Documentation
¶
Overview ¶
Package submodelelements provides handlers for different types of submodel elements in the BaSyx framework. This package contains PostgreSQL-based persistence implementations for various submodel element types including annotated relationship elements.
Package submodelelements provides persistence handlers for various submodel element types.
Package submodelelements provides handlers for different types of submodel elements in the BaSyx framework. This package contains PostgreSQL-based persistence implementations for various submodel element types including basic event elements.
Package submodelelements provides handlers for different types of submodel elements in the BaSyx framework. This package contains PostgreSQL-based persistence implementations for various submodel element types including blob elements for binary data storage.
Package submodelelements provides handlers for different types of submodel elements in the BaSyx framework. This package contains PostgreSQL-based persistence implementations for various submodel element types including capability elements for representing functional capabilities.
Package submodelelements provides handlers for different types of submodel elements in the BaSyx framework. This package contains PostgreSQL-based persistence implementations for various submodel element types including submodel element collections for organizing related elements.
Package submodelelements provides persistence handlers for various submodel element types.
Package submodelelements provides persistence handlers for various submodel element types in the Eclipse BaSyx submodel repository. It implements CRUD operations for different submodel element types such as Range, Property, Collection, and others, with PostgreSQL as the underlying database.
Author: Jannik Fried ( Fraunhofer IESE )
Package submodelelements provides persistence handlers for various submodel element types in the Eclipse BaSyx submodel repository. It implements CRUD operations for different submodel element types such as Range, Property, Collection, and others, with PostgreSQL as the underlying database.
Author: Jannik Fried ( Fraunhofer IESE )
Package submodelelements provides persistence handlers for various submodel element types in the Eclipse BaSyx submodel repository. It implements CRUD operations for different submodel element types such as Range, Property, Collection, and others, with PostgreSQL as the underlying database.
Author: Jannik Fried ( Fraunhofer IESE )
Package submodelelements provides persistence handlers for various submodel element types in the Eclipse BaSyx submodel repository. It implements CRUD operations for different submodel element types such as Range, Property, Collection, and others, with PostgreSQL as the underlying database.
Package submodelelements provides persistence handlers for Asset Administration Shell (AAS) submodel elements in Eclipse BaSyx. This package implements the repository pattern for storing and retrieving various types of submodel elements in a PostgreSQL database, including their hierarchical relationships, metadata, and type-specific attributes.
The package supports all AAS submodel element types defined in the specification, such as Properties, Collections, Lists, RelationshipElements, ReferenceElements, and more. Each handler uses a decorator pattern to add type-specific functionality on top of the base CRUD operations provided by PostgreSQLSMECrudHandler.
Package submodelelements provides handlers for different types of submodel elements in the BaSyx framework.
This package contains PostgreSQL-based persistence implementations for various submodel element types including relationship elements that define directed relationships between other elements.
Package submodelelements provides handlers for CRUD operations on Submodel Elements in a PostgreSQL database.
This package implements the base CRUD handler that manages common submodel element operations including creation, path management, and position tracking within hierarchical structures.
Package submodelelements provides interfaces and implementations for CRUD operations on Submodel Elements in a PostgreSQL database.
Package submodelelements provides persistence layer functionality for managing submodel elements in the Eclipse BaSyx submodel repository. It implements CRUD operations for all types of submodel elements defined in the AAS specification, including properties, collections, relationships, events, and more.
The package uses a factory pattern to create type-specific handlers and provides efficient database queries with hierarchical data retrieval for nested element structures.
Index ¶
- func CreateContextReferenceByOwnerID(tx *sql.Tx, ownerID int64, tableBaseName string, reference types.IReference) (sql.NullInt64, error)
- func DeleteAllChildren(db *sql.DB, submodelId string, idShortPath string, tx *sql.Tx) error
- func DeleteSubmodelElementByPath(tx *sql.Tx, submodelID string, idShortOrPath string) error
- func GetModelTypeByIdShortPathAndSubmodelID(db *sql.DB, submodelID string, idShortOrPath string) (*types.ModelType, error)
- func GetModelTypeByIdShortPathAndSubmodelIDTx(tx *sql.Tx, submodelID string, idShortOrPath string) (*types.ModelType, error)
- func GetRangeColumnNames(valueType types.DataTypeDefXSD) (minCol, maxCol string)
- func GetSubmodelElementByIDShortOrPath(ctx context.Context, db *sql.DB, submodelID string, idShortOrPath string, ...) (types.ISubmodelElement, error)
- func GetSubmodelElementByIDShortOrPathTx(ctx context.Context, tx *sql.Tx, submodelID string, idShortOrPath string, ...) (types.ISubmodelElement, error)
- func GetSubmodelElementPathsByPath(ctx context.Context, db *sql.DB, submodelID string, idShortPath string, ...) ([]string, error)
- func GetSubmodelElementPathsBySubmodelID(ctx context.Context, db *sql.DB, submodelID string, level string) ([]string, error)
- func GetSubmodelElementPathsPageBySubmodelID(ctx context.Context, db *sql.DB, submodelID string, limit *int, cursor string, ...) ([]string, string, error)
- func GetSubmodelElementReferencesBySubmodelID(ctx context.Context, db *sql.DB, submodelID string, limit *int, cursor string) ([]types.IReference, string, error)
- func GetSubmodelElementsBySubmodelID(ctx context.Context, db *sql.DB, submodelID string, limit *int, cursor string, ...) ([]types.ISubmodelElement, string, error)
- func GetSubmodelElementsBySubmodelIDTx(ctx context.Context, tx *sql.Tx, submodelID string, limit *int, cursor string, ...) ([]types.ISubmodelElement, string, error)
- func GetSupportedModelTypes() []types.ModelType
- func InsertSubmodelElements(db *sql.DB, submodelID string, elements []types.ISubmodelElement, tx *sql.Tx, ...) ([]int, error)
- func IsDateTimeType(valueType types.DataTypeDefXSD) bool
- func IsNumericType(valueType types.DataTypeDefXSD) bool
- func IsTextType(valueType types.DataTypeDefXSD) bool
- func RegisterHandler(modelType types.ModelType, factory HandlerFactory)
- func ResolveUpdatedPath(idShortOrPath string, submodelElement types.ISubmodelElement, isPut bool) string
- func UpdateNestedElements(db *sql.DB, elems []SubmodelElementToProcess, idShortOrPath string, ...) error
- func UpdateNestedElementsValueOnly(db *sql.DB, elems []ValueOnlyElementsToProcess, idShortOrPath string, ...) error
- type BaseHandler
- type BatchInsertContext
- type HandlerFactory
- type InsertQueryPart
- type PostgreSQLAnnotatedRelationshipElementHandler
- func (p PostgreSQLAnnotatedRelationshipElementHandler) Delete(idShortOrPath string) error
- func (p PostgreSQLAnnotatedRelationshipElementHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
- func (p PostgreSQLAnnotatedRelationshipElementHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p PostgreSQLAnnotatedRelationshipElementHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, ...) error
- type PostgreSQLBasicEventElementHandler
- func (p PostgreSQLBasicEventElementHandler) Delete(idShortOrPath string) error
- func (p PostgreSQLBasicEventElementHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
- func (p PostgreSQLBasicEventElementHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p PostgreSQLBasicEventElementHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, ...) error
- type PostgreSQLBlobHandler
- func (p PostgreSQLBlobHandler) Delete(idShortOrPath string) error
- func (p PostgreSQLBlobHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
- func (p PostgreSQLBlobHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p PostgreSQLBlobHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, ...) error
- type PostgreSQLCapabilityHandler
- func (p PostgreSQLCapabilityHandler) Delete(idShortOrPath string) error
- func (p PostgreSQLCapabilityHandler) GetInsertQueryPart(_ *sql.Tx, _ int, element types.ISubmodelElement) (*InsertQueryPart, error)
- func (p PostgreSQLCapabilityHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p PostgreSQLCapabilityHandler) UpdateValueOnly(_ string, _ string, _ gen.SubmodelElementValue, _ *sql.Tx) error
- type PostgreSQLEntityHandler
- func (p PostgreSQLEntityHandler) Delete(idShortOrPath string) error
- func (p PostgreSQLEntityHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
- func (p PostgreSQLEntityHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p PostgreSQLEntityHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, ...) error
- type PostgreSQLFileHandler
- func (p PostgreSQLFileHandler) Delete(idShortOrPath string) error
- func (p PostgreSQLFileHandler) DeleteFileAttachment(submodelID string, idShortPath string) error
- func (p PostgreSQLFileHandler) DeleteFileAttachmentTx(tx *sql.Tx, submodelID string, idShortPath string) error
- func (p PostgreSQLFileHandler) DownloadFileAttachment(submodelID string, idShortPath string) ([]byte, string, string, error)
- func (p PostgreSQLFileHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
- func (p PostgreSQLFileHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p PostgreSQLFileHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, ...) error
- func (p PostgreSQLFileHandler) UploadFileAttachment(submodelID string, idShortPath string, file *os.File, fileName string) error
- func (p PostgreSQLFileHandler) UploadFileAttachmentTx(tx *sql.Tx, submodelID string, idShortPath string, file *os.File, ...) error
- type PostgreSQLMultiLanguagePropertyHandler
- func (p PostgreSQLMultiLanguagePropertyHandler) Delete(idShortOrPath string) error
- func (p PostgreSQLMultiLanguagePropertyHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
- func (p PostgreSQLMultiLanguagePropertyHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p PostgreSQLMultiLanguagePropertyHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, ...) error
- type PostgreSQLOperationHandler
- func (p PostgreSQLOperationHandler) Delete(idShortOrPath string) error
- func (p PostgreSQLOperationHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
- func (p PostgreSQLOperationHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p PostgreSQLOperationHandler) UpdateValueOnly(_ string, _ string, _ gen.SubmodelElementValue, _ *sql.Tx) error
- type PostgreSQLPropertyHandler
- func (p PostgreSQLPropertyHandler) Delete(idShortOrPath string) error
- func (p PostgreSQLPropertyHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
- func (p PostgreSQLPropertyHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p PostgreSQLPropertyHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, ...) error
- type PostgreSQLRangeHandler
- func (p PostgreSQLRangeHandler) Delete(idShortOrPath string) error
- func (p PostgreSQLRangeHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
- func (p PostgreSQLRangeHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p PostgreSQLRangeHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, ...) error
- type PostgreSQLReferenceElementHandler
- func (p PostgreSQLReferenceElementHandler) Delete(idShortOrPath string) error
- func (p PostgreSQLReferenceElementHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
- func (p PostgreSQLReferenceElementHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p PostgreSQLReferenceElementHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, ...) error
- type PostgreSQLRelationshipElementHandler
- func (p PostgreSQLRelationshipElementHandler) Delete(idShortOrPath string) error
- func (p PostgreSQLRelationshipElementHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
- func (p PostgreSQLRelationshipElementHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p PostgreSQLRelationshipElementHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, ...) error
- type PostgreSQLSMECrudHandler
- func (p *PostgreSQLSMECrudHandler) Delete(idShortOrPath string) error
- func (p *PostgreSQLSMECrudHandler) GetDatabaseID(submodelID int, idShortPath string) (int, error)
- func (p *PostgreSQLSMECrudHandler) GetDatabaseIDWithTx(tx *sql.Tx, submodelID int, idShortPath string) (int, error)
- func (p *PostgreSQLSMECrudHandler) GetNextPosition(parentID int) (int, error)
- func (p *PostgreSQLSMECrudHandler) GetRootSmeIDByElementID(elementID int) (int, error)
- func (p *PostgreSQLSMECrudHandler) GetSubmodelElementType(idShortPath string) (*types.ModelType, error)
- func (p *PostgreSQLSMECrudHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p *PostgreSQLSMECrudHandler) UpdateIdShortPaths(tx *sql.Tx, submodelID string, oldPath string, newIDShort string) (string, error)
- type PostgreSQLSMECrudInterface
- func GetHandlerFromRegistry(modelType types.ModelType, db *sql.DB) (PostgreSQLSMECrudInterface, error)
- func GetSMEHandler(submodelElement types.ISubmodelElement, db *sql.DB) (PostgreSQLSMECrudInterface, error)
- func GetSMEHandlerByModelType(modelType types.ModelType, db *sql.DB) (PostgreSQLSMECrudInterface, error)
- type PostgreSQLSubmodelElementCollectionHandler
- func (p PostgreSQLSubmodelElementCollectionHandler) Delete(idShortOrPath string) error
- func (p PostgreSQLSubmodelElementCollectionHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
- func (p PostgreSQLSubmodelElementCollectionHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p PostgreSQLSubmodelElementCollectionHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, ...) error
- type PostgreSQLSubmodelElementListHandler
- func (p PostgreSQLSubmodelElementListHandler) Delete(idShortOrPath string) error
- func (p PostgreSQLSubmodelElementListHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
- func (p PostgreSQLSubmodelElementListHandler) Update(submodelID string, idShortOrPath string, ...) error
- func (p PostgreSQLSubmodelElementListHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, ...) error
- type SubmodelElementToProcess
- type TypedRangeValue
- type TypedValue
- type ValueOnlyElementsToProcess
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateContextReferenceByOwnerID ¶
func CreateContextReferenceByOwnerID(tx *sql.Tx, ownerID int64, tableBaseName string, reference types.IReference) (sql.NullInt64, error)
CreateContextReferenceByOwnerID upserts a context reference for a given owner ID.
Description: This function writes a complete reference triplet (reference base row, payload row, and key rows) for a specific owner into the dynamic reference tables derived from tableBaseName. Existing payload and keys for the owner are replaced atomically inside the provided transaction.
Parameters:
- tx: Active SQL transaction used for all operations. Must not be nil.
- ownerID: The owner identifier used as primary key in
_reference. - tableBaseName: Base name used to resolve target tables:
_reference _reference_payload _reference_key - reference: Reference object to persist. If nil, no row is written and an invalid sql.NullInt64 is returned without error.
Returns:
- sql.NullInt64: Reference ID (equal to ownerID) when a reference is persisted.
- error: Internal server error if query build or execution fails.
Usage:
refID, err := CreateContextReferenceByOwnerID(tx, int64(submodelElementID), "submodel_element_semantic_id", element.SemanticID())
if err != nil {
return err
}
if !refID.Valid {
// semantic reference was nil
}
func DeleteAllChildren ¶
DeleteAllChildren removes all associated children
Parameters: - db: The database connection - submodelId: The Identifier of the Submodel the SubmodelElement belongs to - idShortPath: The parents idShortPath to delete the children from - tx: transaction context (will be set if nil)
func DeleteSubmodelElementByPath ¶
DeleteSubmodelElementByPath removes a submodel element by its idShort or path including all nested elements.
This function performs cascading deletion of a submodel element and its entire subtree. If the deleted element is part of a SubmodelElementList, it automatically adjusts the position indices of remaining elements to maintain consistency.
The function handles:
- Direct deletion of the element and its subtree (using path pattern matching)
- Index recalculation for SubmodelElementList elements after deletion
- Path updates for remaining list elements to reflect new indices
Parameters:
- tx: Transaction context for atomic deletion operations
- submodelID: ID of the parent submodel
- idShortOrPath: Path to the element to delete (e.g., "prop1" or "collection.list[2]")
Returns:
- error: An error if the element is not found or database operations fail
Example:
// Delete a simple property err := DeleteSubmodelElementByPath(tx, "submodel123", "temperature") // Delete an element in a list (adjusts indices of elements after it) err := DeleteSubmodelElementByPath(tx, "submodel123", "sensors[1]") // Delete a nested collection and all its children err := DeleteSubmodelElementByPath(tx, "submodel123", "properties.metadata")
func GetModelTypeByIdShortPathAndSubmodelID ¶
func GetModelTypeByIdShortPathAndSubmodelID(db *sql.DB, submodelID string, idShortOrPath string) (*types.ModelType, error)
GetModelTypeByIdShortPathAndSubmodelID retrieves the model type of a submodel element
Parameters: - db: Database connection - submodelID: ID of the parent submodel
- idShortOrPath: idShort or hierarchical path of the submodel element Returns: - string: Model type of the submodel element - error: Error if retrieval fails or element is not found
func GetModelTypeByIdShortPathAndSubmodelIDTx ¶
func GetModelTypeByIdShortPathAndSubmodelIDTx(tx *sql.Tx, submodelID string, idShortOrPath string) (*types.ModelType, error)
GetModelTypeByIdShortPathAndSubmodelIDTx retrieves the model type within an existing transaction.
func GetRangeColumnNames ¶
func GetRangeColumnNames(valueType types.DataTypeDefXSD) (minCol, maxCol string)
GetRangeColumnNames returns the appropriate column names for min and max values based on the XML Schema datatype of the Range element.
Parameters:
- valueType: The XS datatype string
Returns:
- minCol: The column name for the minimum value
- maxCol: The column name for the maximum value
func GetSubmodelElementByIDShortOrPath ¶
func GetSubmodelElementByIDShortOrPath(ctx context.Context, db *sql.DB, submodelID string, idShortOrPath string, level string) (types.ISubmodelElement, error)
GetSubmodelElementByIDShortOrPath loads a submodel element by path and applies optional ABAC formula filters from ctx.
func GetSubmodelElementByIDShortOrPathTx ¶
func GetSubmodelElementByIDShortOrPathTx(ctx context.Context, tx *sql.Tx, submodelID string, idShortOrPath string, level string) (types.ISubmodelElement, error)
GetSubmodelElementByIDShortOrPathTx loads a submodel element by path from an existing transaction.
func GetSubmodelElementPathsByPath ¶
func GetSubmodelElementPathsByPath(ctx context.Context, db *sql.DB, submodelID string, idShortPath string, level string) ([]string, error)
GetSubmodelElementPathsByPath returns persisted idshort_path values for a submodel element path and, for deep level, its descendants.
func GetSubmodelElementPathsBySubmodelID ¶
func GetSubmodelElementPathsBySubmodelID(ctx context.Context, db *sql.DB, submodelID string, level string) ([]string, error)
GetSubmodelElementPathsBySubmodelID returns submodel element paths directly from persisted idshort_path values.
func GetSubmodelElementPathsPageBySubmodelID ¶
func GetSubmodelElementPathsPageBySubmodelID(ctx context.Context, db *sql.DB, submodelID string, limit *int, cursor string, level string) ([]string, string, error)
GetSubmodelElementPathsPageBySubmodelID returns paged submodel element paths directly from persisted idshort_path values.
func GetSubmodelElementReferencesBySubmodelID ¶
func GetSubmodelElementReferencesBySubmodelID(ctx context.Context, db *sql.DB, submodelID string, limit *int, cursor string) ([]types.IReference, string, error)
GetSubmodelElementReferencesBySubmodelID retrieves references for top-level submodel elements of a submodel with optional pagination.
func GetSubmodelElementsBySubmodelID ¶
func GetSubmodelElementsBySubmodelID(ctx context.Context, db *sql.DB, submodelID string, limit *int, cursor string, level string) ([]types.ISubmodelElement, string, error)
GetSubmodelElementsBySubmodelID loads top-level submodel elements and reconstructs each complete subtree in original hierarchy.
func GetSubmodelElementsBySubmodelIDTx ¶
func GetSubmodelElementsBySubmodelIDTx(ctx context.Context, tx *sql.Tx, submodelID string, limit *int, cursor string, level string) ([]types.ISubmodelElement, string, error)
GetSubmodelElementsBySubmodelIDTx loads top-level submodel elements from an existing transaction.
func GetSupportedModelTypes ¶
GetSupportedModelTypes returns a list of all model types supported by the registry.
func InsertSubmodelElements ¶
func InsertSubmodelElements(db *sql.DB, submodelID string, elements []types.ISubmodelElement, tx *sql.Tx, ctx *BatchInsertContext) ([]int, error)
InsertSubmodelElements inserts submodel elements with maximum throughput while preserving data-equivalent persistence semantics of BatchInsert.
It flattens the full element tree, inserts base records depth-wise in large batches, then performs bulk inserts for payloads and type-specific records.
func IsDateTimeType ¶
func IsDateTimeType(valueType types.DataTypeDefXSD) bool
IsDateTimeType checks if the given XS datatype should be stored in TIMESTAMPTZ columns.
Parameters:
- valueType: The XS datatype string to check
Returns:
- bool: true if the type is xs:dateTime (stored in TIMESTAMPTZ), false otherwise
func IsNumericType ¶
func IsNumericType(valueType types.DataTypeDefXSD) bool
IsNumericType checks if the given XS datatype is a numeric type.
Parameters:
- valueType: The XS datatype string to check
Returns:
- bool: true if the type is a numeric type, false otherwise
func IsTextType ¶
func IsTextType(valueType types.DataTypeDefXSD) bool
IsTextType checks if the given XS datatype is a text/string type.
Parameters:
- valueType: The XS datatype string to check
Returns:
- bool: true if the type is a text type, false otherwise
func RegisterHandler ¶
func RegisterHandler(modelType types.ModelType, factory HandlerFactory)
RegisterHandler registers a custom handler factory for a model type. This allows for extending the registry with custom element types.
Parameters:
- modelType: The model type name to register
- factory: The factory function that creates handlers for this type
func ResolveUpdatedPath ¶
func ResolveUpdatedPath(idShortOrPath string, submodelElement types.ISubmodelElement, isPut bool) string
ResolveUpdatedPath returns the persisted path after a submodel-element update.
func UpdateNestedElements ¶
func UpdateNestedElements(db *sql.DB, elems []SubmodelElementToProcess, idShortOrPath string, submodelID string, tx *sql.Tx, isPut bool) error
UpdateNestedElements updates nested submodel elements based on value-only patches.
Parameters:
- db: Database connection
- elems: List of elements to process
- idShortOrPath: idShort or hierarchical path of the root element
- submodelID: ID of the parent submodel
Returns:
- error: Error if update fails
func UpdateNestedElementsValueOnly ¶
func UpdateNestedElementsValueOnly(db *sql.DB, elems []ValueOnlyElementsToProcess, idShortOrPath string, submodelID string, tx *sql.Tx) error
UpdateNestedElementsValueOnly updates nested submodel elements based on value-only patches.
Parameters:
- db: Database connection
- elems: List of elements to process
- idShortOrPath: idShort or hierarchical path of the root element
- submodelID: ID of the parent submodel
Returns:
- error: Error if update fails
Types ¶
type BaseHandler ¶
type BaseHandler struct {
DB *sql.DB
Decorated *PostgreSQLSMECrudHandler
}
BaseHandler provides common functionality shared by all submodel element handlers. It uses the decorator pattern where type-specific handlers embed this base and extend it with specialized functionality.
This eliminates code duplication across all handler types by centralizing the database connection and decorated handler initialization.
func NewBaseHandler ¶
func NewBaseHandler(db *sql.DB) (*BaseHandler, error)
NewBaseHandler creates a new BaseHandler instance with the provided database connection. It initializes the decorated PostgreSQLSMECrudHandler for base submodel element operations.
Parameters:
- db: A PostgreSQL database connection
Returns:
- *BaseHandler: A new handler instance
- error: An error if the decorated handler initialization fails
type BatchInsertContext ¶
type BatchInsertContext struct {
ParentID int // Database ID of the parent element (0 for top-level elements)
ParentPath string // Path of the parent element (empty for top-level elements)
RootSmeID int // Database ID of the root submodel element (0 for top-level elements, will be set to own ID)
IsFromList bool // Whether elements are being inserted into a SubmodelElementList
StartPosition int // Starting position for elements (used when adding to existing containers)
}
BatchInsertContext provides context for batch inserting submodel elements. It specifies where in the hierarchy the elements should be inserted.
type HandlerFactory ¶
type HandlerFactory func(*sql.DB) (PostgreSQLSMECrudInterface, error)
HandlerFactory is a function type that creates a PostgreSQLSMECrudInterface for a given database connection.
type InsertQueryPart ¶
type InsertQueryPart struct {
TableName string // The name of the type-specific table (e.g., "property_element", "blob_element")
Record goqu.Record // The record containing column-value pairs for the insert
}
InsertQueryPart represents the type-specific insert data for a submodel element. It contains the target table name and the record to insert.
type PostgreSQLAnnotatedRelationshipElementHandler ¶
type PostgreSQLAnnotatedRelationshipElementHandler struct {
// contains filtered or unexported fields
}
PostgreSQLAnnotatedRelationshipElementHandler provides PostgreSQL-based persistence operations for AnnotatedRelationshipElement submodel elements. It implements CRUD operations and handles the complex relationships and annotations associated with annotated relationship elements.
func NewPostgreSQLAnnotatedRelationshipElementHandler ¶
func NewPostgreSQLAnnotatedRelationshipElementHandler(db *sql.DB) (*PostgreSQLAnnotatedRelationshipElementHandler, error)
NewPostgreSQLAnnotatedRelationshipElementHandler creates a new handler for AnnotatedRelationshipElement persistence. It initializes the handler with a database connection and sets up the decorated CRUD handler for common submodel element operations.
Parameters:
- db: PostgreSQL database connection
Returns:
- *PostgreSQLAnnotatedRelationshipElementHandler: Configured handler instance
- error: Error if handler initialization fails
func (PostgreSQLAnnotatedRelationshipElementHandler) Delete ¶
func (p PostgreSQLAnnotatedRelationshipElementHandler) Delete(idShortOrPath string) error
Delete removes an AnnotatedRelationshipElement identified by its idShort or path from the database. This method delegates the deletion operation to the decorated CRUD handler which handles the cascading deletion of all related data and child elements.
Parameters:
- idShortOrPath: idShort or hierarchical path to the element to delete
Returns:
- error: Error if deletion fails
func (PostgreSQLAnnotatedRelationshipElementHandler) GetInsertQueryPart ¶
func (p PostgreSQLAnnotatedRelationshipElementHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
GetInsertQueryPart returns the type-specific insert query part for batch insertion of AnnotatedRelationshipElement elements. It returns the table name and record for inserting into the annotated_relationship_element table.
Parameters:
- tx: Active database transaction (not used for AnnotatedRelationshipElement)
- id: The database ID of the base submodel_element record
- element: The AnnotatedRelationshipElement element to insert
Returns:
- *InsertQueryPart: The table name and record for annotated_relationship_element insert
- error: An error if the element is not of type AnnotatedRelationshipElement
func (PostgreSQLAnnotatedRelationshipElementHandler) Update ¶
func (p PostgreSQLAnnotatedRelationshipElementHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update modifies an existing AnnotatedRelationshipElement identified by its idShort or path. This method handles both the common submodel element properties and the specific annotated relationship data such as the 'first' and 'second' references and annotations.
Parameters:
- idShortOrPath: idShort or hierarchical path to the element to update
- submodelElement: Updated element data
- isPut: true: Replaces the Submodel Element with the Body Data (Deletes non-specified fields); false: Updates only passed request body data, unspecified is ignored
Returns:
- error: Error if update fails
func (PostgreSQLAnnotatedRelationshipElementHandler) UpdateValueOnly ¶
func (p PostgreSQLAnnotatedRelationshipElementHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, tx *sql.Tx) error
UpdateValueOnly updates only the value of an existing AnnotatedRelationshipElement submodel element identified by its idShort or path. It updates the 'first' and 'second' references based on the provided value.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- valueOnly: The new value to set (must be of type gen.AnnotatedRelationshipElementValue)
Returns:
- error: An error if the update operation fails
type PostgreSQLBasicEventElementHandler ¶
type PostgreSQLBasicEventElementHandler struct {
// contains filtered or unexported fields
}
PostgreSQLBasicEventElementHandler provides PostgreSQL-based persistence operations for BasicEventElement submodel elements. It implements CRUD operations and handles the event-specific properties such as observed references, message brokers, and timing intervals.
func NewPostgreSQLBasicEventElementHandler ¶
func NewPostgreSQLBasicEventElementHandler(db *sql.DB) (*PostgreSQLBasicEventElementHandler, error)
NewPostgreSQLBasicEventElementHandler creates a new handler for BasicEventElement persistence. It initializes the handler with a database connection and sets up the decorated CRUD handler for common submodel element operations.
Parameters:
- db: PostgreSQL database connection
Returns:
- *PostgreSQLBasicEventElementHandler: Configured handler instance
- error: Error if handler initialization fails
func (PostgreSQLBasicEventElementHandler) Delete ¶
func (p PostgreSQLBasicEventElementHandler) Delete(idShortOrPath string) error
Delete removes a BasicEventElement identified by its idShort or path from the database. This method delegates the deletion operation to the decorated CRUD handler which handles the cascading deletion of all related data and child elements.
Parameters:
- idShortOrPath: idShort or hierarchical path to the element to delete
Returns:
- error: Error if deletion fails
func (PostgreSQLBasicEventElementHandler) GetInsertQueryPart ¶
func (p PostgreSQLBasicEventElementHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
GetInsertQueryPart returns the type-specific insert query part for batch insertion of BasicEventElement elements. It returns the table name and record for inserting into the basic_event_element table.
Parameters:
- tx: Active database transaction (not used for BasicEventElement)
- id: The database ID of the base submodel_element record
- element: The BasicEventElement element to insert
Returns:
- *InsertQueryPart: The table name and record for basic_event_element insert
- error: An error if the element is not of type BasicEventElement
func (PostgreSQLBasicEventElementHandler) Update ¶
func (p PostgreSQLBasicEventElementHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update modifies an existing BasicEventElement identified by its idShort or path. This method handles both the common submodel element properties and the specific event properties such as observed references, message brokers, and timing intervals.
Parameters:
- submodelID: ID of the parent submodel
- idShortOrPath: idShort or hierarchical path to the element to update
- submodelElement: Updated element data
- tx: Active database transaction (can be nil, will create one if needed)
- isPut: true: Replaces the Submodel Element with the Body Data (Deletes non-specified fields); false: Updates only passed request body data, unspecified is ignored
Returns:
- error: Error if update fails
func (PostgreSQLBasicEventElementHandler) UpdateValueOnly ¶
func (p PostgreSQLBasicEventElementHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, tx *sql.Tx) error
UpdateValueOnly updates only the value of an existing BasicEventElement submodel element identified by its idShort or path. It updates the observed reference in the database.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- valueOnly: The new value to set (must be of type gen.BasicEventElementValue)
Returns:
- error: An error if the update operation fails or if the valueOnly type is incorrect
type PostgreSQLBlobHandler ¶
type PostgreSQLBlobHandler struct {
// contains filtered or unexported fields
}
PostgreSQLBlobHandler provides PostgreSQL-based persistence operations for Blob submodel elements. It implements CRUD operations and handles binary data storage with content type information. Blob elements are used to store binary data such as images, documents, or other files within submodels.
func NewPostgreSQLBlobHandler ¶
func NewPostgreSQLBlobHandler(db *sql.DB) (*PostgreSQLBlobHandler, error)
NewPostgreSQLBlobHandler creates a new handler for Blob element persistence. It initializes the handler with a database connection and sets up the decorated CRUD handler for common submodel element operations.
Parameters:
- db: PostgreSQL database connection
Returns:
- *PostgreSQLBlobHandler: Configured handler instance
- error: Error if handler initialization fails
func (PostgreSQLBlobHandler) Delete ¶
func (p PostgreSQLBlobHandler) Delete(idShortOrPath string) error
Delete removes a Blob element identified by its idShort or path from the database. This method delegates the deletion operation to the decorated CRUD handler which handles the cascading deletion of all related data and child elements.
Parameters:
- idShortOrPath: idShort or hierarchical path to the element to delete
Returns:
- error: Error if deletion fails
func (PostgreSQLBlobHandler) GetInsertQueryPart ¶
func (p PostgreSQLBlobHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
GetInsertQueryPart returns the type-specific insert query part for batch insertion of Blob elements. It returns the table name and record for inserting into the blob_element table.
Parameters:
- tx: Active database transaction (not used for Blob)
- id: The database ID of the base submodel_element record
- element: The Blob element to insert
Returns:
- *InsertQueryPart: The table name and record for blob_element insert
- error: An error if the element is not of type Blob
func (PostgreSQLBlobHandler) Update ¶
func (p PostgreSQLBlobHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update modifies an existing Blob element identified by its idShort or path. This method handles both the common submodel element properties and the specific blob data including content type and binary value storage.
Parameters:
- submodelID: ID of the parent submodel
- idShortOrPath: idShort or hierarchical path to the element to update
- submodelElement: Updated element data
- tx: Active database transaction (can be nil, will create one if needed)
- isPut: true: Replaces the Submodel Element with the Body Data (Deletes non-specified fields); false: Updates only passed request body data, unspecified is ignored
Returns:
- error: Error if update fails
func (PostgreSQLBlobHandler) UpdateValueOnly ¶
func (p PostgreSQLBlobHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, tx *sql.Tx) error
UpdateValueOnly updates only the value of an existing Blob submodel element identified by its idShort or path. It updates the content type and binary value in the database.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- valueOnly: The new value to set (must be of type gen.BlobValue)
Returns:
- error: An error if the update operation fails or if the valueOnly type is incorrect
type PostgreSQLCapabilityHandler ¶
type PostgreSQLCapabilityHandler struct {
// contains filtered or unexported fields
}
PostgreSQLCapabilityHandler provides PostgreSQL-based persistence operations for Capability submodel elements. It implements CRUD operations for capability elements which represent functional capabilities or services that can be provided by an asset or component within the Industrial Digital Twin context.
func NewPostgreSQLCapabilityHandler ¶
func NewPostgreSQLCapabilityHandler(db *sql.DB) (*PostgreSQLCapabilityHandler, error)
NewPostgreSQLCapabilityHandler creates a new handler for Capability element persistence. It initializes the handler with a database connection and sets up the decorated CRUD handler for common submodel element operations.
Parameters:
- db: PostgreSQL database connection
Returns:
- *PostgreSQLCapabilityHandler: Configured handler instance
- error: Error if handler initialization fails
func (PostgreSQLCapabilityHandler) Delete ¶
func (p PostgreSQLCapabilityHandler) Delete(idShortOrPath string) error
Delete removes a Capability element identified by its idShort or path from the database. This method delegates the deletion operation to the decorated CRUD handler which handles the cascading deletion of all related data and child elements.
Parameters:
- idShortOrPath: idShort or hierarchical path to the element to delete
Returns:
- error: Error if deletion fails
func (PostgreSQLCapabilityHandler) GetInsertQueryPart ¶
func (p PostgreSQLCapabilityHandler) GetInsertQueryPart(_ *sql.Tx, _ int, element types.ISubmodelElement) (*InsertQueryPart, error)
GetInsertQueryPart returns the type-specific insert query part for batch insertion of Capability elements. Capability elements have no type-specific table, so this method returns nil.
Parameters:
- tx: Active database transaction (not used)
- id: The database ID of the base submodel_element record (not used)
- element: The Capability element to insert
Returns:
- *InsertQueryPart: Always nil as Capability has no type-specific table
- error: An error if the element is not of type Capability
func (PostgreSQLCapabilityHandler) Update ¶
func (p PostgreSQLCapabilityHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update modifies an existing Capability element identified by its idShort or path. This method delegates the update operation to the decorated CRUD handler which handles the common submodel element update logic.
Parameters:
- idShortOrPath: idShort or hierarchical path to the element to update
- submodelElement: Updated element data
Returns:
- error: Error if update fails
func (PostgreSQLCapabilityHandler) UpdateValueOnly ¶
func (p PostgreSQLCapabilityHandler) UpdateValueOnly(_ string, _ string, _ gen.SubmodelElementValue, _ *sql.Tx) error
UpdateValueOnly updates only the value of an existing Capability submodel element identified by its idShort or path. Capability has no value only representation, so this method currently performs no operation.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- valueOnly: The new value to set
Returns:
- error: An error if the update operation fails
type PostgreSQLEntityHandler ¶
type PostgreSQLEntityHandler struct {
// contains filtered or unexported fields
}
PostgreSQLEntityHandler handles the persistence operations for Entity submodel elements. It implements the SubmodelElementHandler interface and uses the decorator pattern to extend the base CRUD operations with Entity-specific functionality.
func NewPostgreSQLEntityHandler ¶
func NewPostgreSQLEntityHandler(db *sql.DB) (*PostgreSQLEntityHandler, error)
NewPostgreSQLEntityHandler creates a new PostgreSQLEntityHandler instance. It initializes the handler with a database connection and creates the decorated base CRUD handler for common SubmodelElement operations.
Parameters:
- db: Database connection to PostgreSQL
Returns:
- *PostgreSQLEntityHandler: Configured Entity handler instance
- error: Error if the decorated handler creation fails
func (PostgreSQLEntityHandler) Delete ¶
func (p PostgreSQLEntityHandler) Delete(idShortOrPath string) error
Delete removes an Entity submodel element from the database. Currently delegates to the decorated handler for base SubmodelElement deletion. Entity-specific data is automatically deleted due to foreign key constraints.
Parameters:
- idShortOrPath: The idShort or path identifier of the element to delete
Returns:
- error: Error if the delete operation fails
func (PostgreSQLEntityHandler) GetInsertQueryPart ¶
func (p PostgreSQLEntityHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
GetInsertQueryPart returns the type-specific insert query part for batch insertion of Entity elements. It returns the table name and record for inserting into the entity_element table.
Parameters:
- tx: Active database transaction (not used for Entity)
- id: The database ID of the base submodel_element record
- element: The Entity element to insert
Returns:
- *InsertQueryPart: The table name and record for entity_element insert
- error: An error if the element is not of type Entity
func (PostgreSQLEntityHandler) Update ¶
func (p PostgreSQLEntityHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update modifies an existing Entity element identified by its idShort or path. This method delegates the update operation to the decorated CRUD handler which handles the common submodel element update logic and additionally manages Entity-specific fields.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifier of the element to update
- submodelElement: The updated Entity element data (must be of type *gen.Entity)
- tx: Optional database transaction (created if nil)
- isPut: true for PUT (replace all), false for PATCH (update only provided fields)
Returns:
- error: Error if the update operation fails or element is not of correct type
func (PostgreSQLEntityHandler) UpdateValueOnly ¶
func (p PostgreSQLEntityHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, tx *sql.Tx) error
UpdateValueOnly updates only the value of an existing Entity submodel element identified by its idShort or path. It updates the entity type, global asset ID, and specific asset IDs based on the provided value.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- valueOnly: The new value to set (must be of type gen.EntityValue)
Returns:
- error: An error if the update operation fails
type PostgreSQLFileHandler ¶
type PostgreSQLFileHandler struct {
// contains filtered or unexported fields
}
PostgreSQLFileHandler handles the persistence operations for File submodel elements. It implements the SubmodelElementHandler interface and uses the decorator pattern to extend the base CRUD operations with File-specific functionality.
func NewPostgreSQLFileHandler ¶
func NewPostgreSQLFileHandler(db *sql.DB) (*PostgreSQLFileHandler, error)
NewPostgreSQLFileHandler creates a new PostgreSQLFileHandler instance. It initializes the handler with a database connection and creates the decorated base CRUD handler for common SubmodelElement operations.
Parameters:
- db: Database connection to PostgreSQL
Returns:
- *PostgreSQLFileHandler: Configured File handler instance
- error: Error if the decorated handler creation fails
func (PostgreSQLFileHandler) Delete ¶
func (p PostgreSQLFileHandler) Delete(idShortOrPath string) error
Delete removes a File submodel element from the database. Currently delegates to the decorated handler for base SubmodelElement deletion. File-specific data is automatically deleted due to foreign key constraints.
Parameters:
- idShortOrPath: The idShort or path identifier of the element to delete
Returns:
- error: Error if the delete operation fails
func (PostgreSQLFileHandler) DeleteFileAttachment ¶
func (p PostgreSQLFileHandler) DeleteFileAttachment(submodelID string, idShortPath string) error
DeleteFileAttachment deletes a file from PostgreSQL's Large Object system. This method removes the Large Object and clears the file_data entry, setting the File SME value to empty.
Parameters:
- submodelID: ID of the parent submodel
- idShortPath: Path to the file element within the submodel
Returns:
- error: Error if the deletion operation fails
func (PostgreSQLFileHandler) DeleteFileAttachmentTx ¶
func (p PostgreSQLFileHandler) DeleteFileAttachmentTx(tx *sql.Tx, submodelID string, idShortPath string) error
DeleteFileAttachmentTx deletes attachment content using the provided transaction.
func (PostgreSQLFileHandler) DownloadFileAttachment ¶
func (p PostgreSQLFileHandler) DownloadFileAttachment(submodelID string, idShortPath string) ([]byte, string, string, error)
DownloadFileAttachment retrieves a file from PostgreSQL's Large Object system. This method reads the file content based on the OID stored in file_data.
Parameters:
- submodelID: ID of the parent submodel
- idShortPath: Path to the file element within the submodel
Returns:
- []byte: The file content
- string: The content type
- error: Error if the download operation fails
func (PostgreSQLFileHandler) GetInsertQueryPart ¶
func (p PostgreSQLFileHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
GetInsertQueryPart returns the type-specific insert query part for batch insertion of File elements. It returns the table name and record for inserting into the file_element table.
Parameters:
- tx: Active database transaction (not used for File)
- id: The database ID of the base submodel_element record
- element: The File element to insert
Returns:
- *InsertQueryPart: The table name and record for file_element insert
- error: An error if the element is not of type File
func (PostgreSQLFileHandler) Update ¶
func (p PostgreSQLFileHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update modifies an existing File submodel element in the database. If the file value is changed and an OID exists, the old Large Object is deleted.
Parameters:
- idShortOrPath: The idShort or path identifier of the element to update
- submodelElement: The updated File element data
Returns:
- error: Error if the update operation fails
func (PostgreSQLFileHandler) UpdateValueOnly ¶
func (p PostgreSQLFileHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, tx *sql.Tx) error
UpdateValueOnly updates only the value of an existing File submodel element identified by its idShort or path. It processes the new value and updates nested elements accordingly.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- valueOnly: The new value to set (must be of type gen.FileValue)
Returns:
- error: An error if the update operation fails
func (PostgreSQLFileHandler) UploadFileAttachment ¶
func (p PostgreSQLFileHandler) UploadFileAttachment(submodelID string, idShortPath string, file *os.File, fileName string) error
UploadFileAttachment uploads a file to PostgreSQL's Large Object system and stores the OID reference. This method handles the complete upload process including cleaning up any existing file data.
Parameters:
- submodelID: ID of the parent submodel
- idShortPath: Path to the file element within the submodel
- file: The file to upload
Returns:
- error: Error if the upload operation fails
type PostgreSQLMultiLanguagePropertyHandler ¶
type PostgreSQLMultiLanguagePropertyHandler struct {
// contains filtered or unexported fields
}
PostgreSQLMultiLanguagePropertyHandler handles persistence operations for MultiLanguageProperty submodel elements. It uses the decorator pattern to extend the base PostgreSQLSMECrudHandler with MultiLanguageProperty-specific functionality. MultiLanguageProperty elements represent text values that can be expressed in multiple languages, with each language variant stored as a separate value.
func NewPostgreSQLMultiLanguagePropertyHandler ¶
func NewPostgreSQLMultiLanguagePropertyHandler(db *sql.DB) (*PostgreSQLMultiLanguagePropertyHandler, error)
NewPostgreSQLMultiLanguagePropertyHandler creates a new PostgreSQLMultiLanguagePropertyHandler instance. It initializes the decorated PostgreSQLSMECrudHandler for base submodel element operations.
Parameters:
- db: A PostgreSQL database connection
Returns:
- *PostgreSQLMultiLanguagePropertyHandler: A new handler instance
- error: An error if the decorated handler initialization fails
func (PostgreSQLMultiLanguagePropertyHandler) Delete ¶
func (p PostgreSQLMultiLanguagePropertyHandler) Delete(idShortOrPath string) error
Delete removes a MultiLanguageProperty submodel element from the database. Currently delegates all delete operations to the decorated handler. MultiLanguageProperty-specific data (including all language values) is typically removed via database cascade constraints.
Parameters:
- idShortOrPath: The idShort or path identifying the element to delete
Returns:
- error: An error if the delete operation fails
func (PostgreSQLMultiLanguagePropertyHandler) GetInsertQueryPart ¶
func (p PostgreSQLMultiLanguagePropertyHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
GetInsertQueryPart returns nil because MultiLanguageProperty persistence is handled via batch post-processing for multilanguage_property_value and multilanguage_property_payload.
Parameters:
- tx: Active database transaction (needed for creating value references)
- id: The database ID of the base submodel_element record
- element: The MultiLanguageProperty element to insert
Returns:
- *InsertQueryPart: nil (no type-specific table insert required)
- error: An error if the element is not of type MultiLanguageProperty
func (PostgreSQLMultiLanguagePropertyHandler) Update ¶
func (p PostgreSQLMultiLanguagePropertyHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update modifies an existing MultiLanguageProperty submodel element in the database. This method handles both the common submodel element properties and the specific multi-language property data including language-text pairs and valueId reference.
Parameters:
- submodelID: ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- submodelElement: The updated MultiLanguageProperty element data
- tx: Active database transaction (can be nil, will create one if needed)
- isPut: true: Replaces the element with the body data; false: Updates only passed data
Returns:
- error: An error if the update operation fails
func (PostgreSQLMultiLanguagePropertyHandler) UpdateValueOnly ¶
func (p PostgreSQLMultiLanguagePropertyHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, tx *sql.Tx) error
UpdateValueOnly updates only the value of an existing MultiLanguageProperty submodel element identified by its idShort or path. It deletes existing language-text pairs and inserts the new set of values provided.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- valueOnly: The new value to set (must be of type gen.MultiLanguagePropertyValue)
Returns:
- error: An error if the update operation fails or if the valueOnly type is incorrect
type PostgreSQLOperationHandler ¶
type PostgreSQLOperationHandler struct {
// contains filtered or unexported fields
}
PostgreSQLOperationHandler handles persistence operations for Operation submodel elements. It uses the decorator pattern to extend the base PostgreSQLSMECrudHandler with Operation-specific functionality. Operation elements represent callable functions with input, output, and in-output variables, each containing submodel elements as values.
func NewPostgreSQLOperationHandler ¶
func NewPostgreSQLOperationHandler(db *sql.DB) (*PostgreSQLOperationHandler, error)
NewPostgreSQLOperationHandler creates a new PostgreSQLOperationHandler instance. It initializes the decorated PostgreSQLSMECrudHandler for base submodel element operations.
Parameters:
- db: A PostgreSQL database connection
Returns:
- *PostgreSQLOperationHandler: A new handler instance
- error: An error if the decorated handler initialization fails
func (PostgreSQLOperationHandler) Delete ¶
func (p PostgreSQLOperationHandler) Delete(idShortOrPath string) error
Delete removes an Operation submodel element from the database. Currently delegates all delete operations to the decorated handler. Operation-specific data (including variables and their values) is typically removed via database cascade constraints.
Parameters:
- idShortOrPath: The idShort or path identifying the element to delete
Returns:
- error: An error if the delete operation fails
func (PostgreSQLOperationHandler) GetInsertQueryPart ¶
func (p PostgreSQLOperationHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
GetInsertQueryPart returns the type-specific insert query part for batch insertion of Operation elements. It returns the table name and record for inserting into the operation_element table.
Parameters:
- tx: Active database transaction (not used for Operation)
- id: The database ID of the base submodel_element record
- element: The Operation element to insert
Returns:
- *InsertQueryPart: The table name and record for operation_element insert
- error: An error if the element is not of type Operation
func (PostgreSQLOperationHandler) Update ¶
func (p PostgreSQLOperationHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update modifies an existing Operation submodel element in the database. This method handles both the common submodel element properties and the specific operation data including input, output, and in-output variables.
Parameters:
- submodelID: ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- submodelElement: The updated Operation element data
- tx: Active database transaction (can be nil, will create one if needed)
- isPut: true: Replaces the element with the body data; false: Updates only passed data
Returns:
- error: An error if the update operation fails
func (PostgreSQLOperationHandler) UpdateValueOnly ¶
func (p PostgreSQLOperationHandler) UpdateValueOnly(_ string, _ string, _ gen.SubmodelElementValue, _ *sql.Tx) error
UpdateValueOnly updates only the value of an existing Operation submodel element identified by its idShort or path. Operation has no Value Only representation, so this method currently performs no action and returns nil.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- valueOnly: The new value to set (must be of type types.ISubmodelElementValue)
Returns:
- error: An error if the update operation fails
type PostgreSQLPropertyHandler ¶
type PostgreSQLPropertyHandler struct {
// contains filtered or unexported fields
}
PostgreSQLPropertyHandler handles persistence operations for Property submodel elements. It uses the decorator pattern to extend the base PostgreSQLSMECrudHandler with Property-specific functionality. Property elements represent single data values with a defined value type (string, numeric, boolean, time, or datetime).
func NewPostgreSQLPropertyHandler ¶
func NewPostgreSQLPropertyHandler(db *sql.DB) (*PostgreSQLPropertyHandler, error)
NewPostgreSQLPropertyHandler creates a new PostgreSQLPropertyHandler instance. It initializes the decorated PostgreSQLSMECrudHandler for base submodel element operations.
Parameters:
- db: A PostgreSQL database connection
Returns:
- *PostgreSQLPropertyHandler: A new handler instance
- error: An error if the decorated handler initialization fails
func (PostgreSQLPropertyHandler) Delete ¶
func (p PostgreSQLPropertyHandler) Delete(idShortOrPath string) error
Delete removes a Property submodel element from the database. Currently delegates all delete operations to the decorated handler. Property-specific data is typically removed via database cascade constraints.
Parameters:
- idShortOrPath: The idShort or path identifying the element to delete
Returns:
- error: An error if the delete operation fails
func (PostgreSQLPropertyHandler) GetInsertQueryPart ¶
func (p PostgreSQLPropertyHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
GetInsertQueryPart returns the type-specific insert query part for batch insertion of Property elements.
Parameters:
- tx: Active database transaction (needed for creating value references)
- id: The database ID of the base submodel_element record
- element: The submodel element to insert (must be of type *types.Property)
Returns:
- *InsertQueryPart: The table name and record for property_element table insert
- error: An error if the element is not a Property or value reference creation fails
func (PostgreSQLPropertyHandler) Update ¶
func (p PostgreSQLPropertyHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update modifies an existing Property submodel element in the database. This method handles both the common submodel element properties and the specific property data including value type, value, and value ID reference.
Parameters:
- submodelID: ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- submodelElement: The updated Property element data
- tx: Active database transaction (can be nil, will create one if needed)
- isPut: true: Replaces the element with the body data; false: Updates only passed data
Returns:
- error: An error if the update operation fails
func (PostgreSQLPropertyHandler) UpdateValueOnly ¶
func (p PostgreSQLPropertyHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, tx *sql.Tx) error
UpdateValueOnly updates only the value of an existing Property submodel element identified by its idShort or path. It categorizes the new value based on the property's value type and updates the corresponding database columns.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- valueOnly: The new value to set (must be of type gen.SubmodelElementValue)
Returns:
- error: An error if the update operation fails or if the valueOnly type is incorrect
type PostgreSQLRangeHandler ¶
type PostgreSQLRangeHandler struct {
// contains filtered or unexported fields
}
PostgreSQLRangeHandler handles persistence operations for Range submodel elements. It uses the decorator pattern to extend the base PostgreSQLSMECrudHandler with Range-specific functionality. Range elements represent intervals with min and max values that can be of various data types (string, numeric, time, datetime).
func NewPostgreSQLRangeHandler ¶
func NewPostgreSQLRangeHandler(db *sql.DB) (*PostgreSQLRangeHandler, error)
NewPostgreSQLRangeHandler creates a new PostgreSQLRangeHandler instance. It initializes the decorated PostgreSQLSMECrudHandler for base submodel element operations.
Parameters:
- db: A PostgreSQL database connection
Returns:
- *PostgreSQLRangeHandler: A new handler instance
- error: An error if the decorated handler initialization fails
func (PostgreSQLRangeHandler) Delete ¶
func (p PostgreSQLRangeHandler) Delete(idShortOrPath string) error
Delete removes a Range submodel element from the database. Currently delegates all delete operations to the decorated handler. Range-specific data is typically removed via database cascade constraints.
Parameters:
- idShortOrPath: The idShort or path identifying the element to delete
Returns:
- error: An error if the delete operation fails
func (PostgreSQLRangeHandler) GetInsertQueryPart ¶
func (p PostgreSQLRangeHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
GetInsertQueryPart returns the type-specific insert query part for batch insertion of Range elements. It returns the table name and record for inserting into the range_element table.
Parameters:
- tx: Active database transaction (not used for Range)
- id: The database ID of the base submodel_element record
- element: The Range element to insert
Returns:
- *InsertQueryPart: The table name and record for range_element insert
- error: An error if the element is not of type Range or min/max values are missing
func (PostgreSQLRangeHandler) Update ¶
func (p PostgreSQLRangeHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update modifies an existing Range submodel element identified by its idShort or path. It updates both the common submodel element properties via the decorated handler and the Range-specific fields such as min/max values based on the value type.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- submodelElement: The updated Range element data
- tx: Optional database transaction (created if nil)
- isPut: true for PUT (replace all), false for PATCH (update only provided fields)
Returns:
- error: An error if the update operation fails or if the element is not a Range type
func (PostgreSQLRangeHandler) UpdateValueOnly ¶
func (p PostgreSQLRangeHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, tx *sql.Tx) error
UpdateValueOnly updates only the value-specific fields of an existing Range submodel element. It updates the min and max values based on the value type of the Range element, ensuring that only the relevant columns are modified while others are set to NULL.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- valueOnly: The RangeValue containing the new min and max values
Returns:
- error: An error if the update operation fails or if the valueOnly is not of type RangeValue
type PostgreSQLReferenceElementHandler ¶
type PostgreSQLReferenceElementHandler struct {
// contains filtered or unexported fields
}
PostgreSQLReferenceElementHandler is a persistence handler for ReferenceElement submodel elements. It implements the decorator pattern by wrapping PostgreSQLSMECrudHandler to add ReferenceElement-specific persistence logic for managing references to other AAS elements or external resources.
A ReferenceElement contains a value that is a Reference, which consists of a type and a list of keys that together identify a specific element within an AAS environment or an external resource.
The handler manages:
- Base SubmodelElement attributes (via decorated handler)
- Reference value with type and keys
- Null reference handling for empty values
- Key ordering and position management
Database structure:
- reference_element table: Links submodel element ID to reference ID
- reference table: Stores reference type
- reference_key table: Stores ordered keys with positions
func NewPostgreSQLReferenceElementHandler ¶
func NewPostgreSQLReferenceElementHandler(db *sql.DB) (*PostgreSQLReferenceElementHandler, error)
NewPostgreSQLReferenceElementHandler creates a new ReferenceElementHandler with the specified database connection. It initializes the decorated PostgreSQLSMECrudHandler for base SubmodelElement operations.
Parameters:
- db: Active PostgreSQL database connection
Returns:
- *PostgreSQLReferenceElementHandler: Initialized handler instance
- error: Any error encountered during handler initialization
func (PostgreSQLReferenceElementHandler) Delete ¶
func (p PostgreSQLReferenceElementHandler) Delete(idShortOrPath string) error
Delete removes a ReferenceElement identified by its idShort or full path from the database. Parameters:
- idShortOrPath: The idShort or full path of the ReferenceElement to delete
Returns:
- error: Any error encountered during the deletion operation
Note: Database foreign key constraints ensure cascading deletion of related records.
func (PostgreSQLReferenceElementHandler) GetInsertQueryPart ¶
func (p PostgreSQLReferenceElementHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
GetInsertQueryPart returns the type-specific insert query part for batch insertion of ReferenceElement elements. It returns the table name and record for inserting into the reference_element table.
Parameters:
- tx: Active database transaction (not used for ReferenceElement)
- id: The database ID of the base submodel_element record
- element: The ReferenceElement element to insert
Returns:
- *InsertQueryPart: The table name and record for reference_element insert
- error: An error if the element is not of type ReferenceElement
func (PostgreSQLReferenceElementHandler) Update ¶
func (p PostgreSQLReferenceElementHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update modifies an existing ReferenceElement identified by its idShort or full path. This method handles both the common submodel element properties and the specific reference element data including the reference value.
Parameters:
- submodelID: ID of the parent submodel
- idShortOrPath: The idShort or full path of the ReferenceElement to update
- submodelElement: The updated ReferenceElement with new values
- tx: Active database transaction (can be nil, will create one if needed)
- isPut: true: Replaces the element with the body data; false: Updates only passed data
Returns:
- error: Any error encountered during the update operation
func (PostgreSQLReferenceElementHandler) UpdateValueOnly ¶
func (p PostgreSQLReferenceElementHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, tx *sql.Tx) error
UpdateValueOnly updates only the value of an existing ReferenceElement identified by its idShort or full path. This method specifically updates the reference value (type and keys) without modifying other attributes.
The method performs the following operations:
- Type assertion to ensure the valueOnly is a ReferenceElementValue
- Marshals the reference value to JSON for database storage
- Constructs and executes an update query to modify only the value field
Parameters:
- idShortOrPath: The idShort or full path of the ReferenceElement to update
- valueOnly: The new ReferenceElementValue containing updated reference data
Returns:
- error: Any error encountered during type assertion, marshaling, or database operations
type PostgreSQLRelationshipElementHandler ¶
type PostgreSQLRelationshipElementHandler struct {
// contains filtered or unexported fields
}
PostgreSQLRelationshipElementHandler provides persistence operations for RelationshipElement types.
This handler implements the decorator pattern, wrapping the base PostgreSQLSMECrudHandler to add RelationshipElement-specific functionality. A RelationshipElement represents a directed relationship between two elements in the AAS model, identified by "first" and "second" references.
The handler manages:
- Base submodel element properties (via decorated handler)
- First and second reference persistence
- Reference keys and their positions
- Both root-level and nested relationship elements
func NewPostgreSQLRelationshipElementHandler ¶
func NewPostgreSQLRelationshipElementHandler(db *sql.DB) (*PostgreSQLRelationshipElementHandler, error)
NewPostgreSQLRelationshipElementHandler creates a new handler for RelationshipElement persistence.
This constructor initializes a RelationshipElement handler with a decorated base handler for common submodel element operations. The decorator pattern allows for separation of concerns between generic element handling and type-specific logic.
Parameters:
- db: PostgreSQL database connection
Returns:
- *PostgreSQLRelationshipElementHandler: Initialized handler ready for CRUD operations
- error: An error if the decorated handler creation fails
func (PostgreSQLRelationshipElementHandler) Delete ¶
func (p PostgreSQLRelationshipElementHandler) Delete(idShortOrPath string) error
Delete removes a RelationshipElement identified by its idShort or path.
This method delegates to the decorated handler for delete operations. When implemented, it will handle cascading deletion of relationship-specific data along with base element data.
Parameters:
- idShortOrPath: The idShort or full path of the element to delete
Returns:
- error: An error if the decorated delete operation fails
func (PostgreSQLRelationshipElementHandler) GetInsertQueryPart ¶
func (p PostgreSQLRelationshipElementHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
GetInsertQueryPart returns the type-specific insert query part for batch insertion of RelationshipElement elements. It returns the table name and record for inserting into the relationship_element table.
Parameters:
- tx: Active database transaction (not used for RelationshipElement)
- id: The database ID of the base submodel_element record
- element: The RelationshipElement element to insert
Returns:
- *InsertQueryPart: The table name and record for relationship_element insert
- error: An error if the element is not of type RelationshipElement
func (PostgreSQLRelationshipElementHandler) Update ¶
func (p PostgreSQLRelationshipElementHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update updates an existing RelationshipElement identified by its idShort or path. This method handles both the common submodel element properties and the specific relationship element data including first and second references.
Parameters:
- submodelID: ID of the parent submodel
- idShortOrPath: The idShort or full path of the element to update
- submodelElement: The updated element data
- tx: Active database transaction (can be nil, will create one if needed)
- isPut: true: Replaces the element with the body data; false: Updates only passed data
Returns:
- error: An error if the decorated update operation fails
func (PostgreSQLRelationshipElementHandler) UpdateValueOnly ¶
func (p PostgreSQLRelationshipElementHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, tx *sql.Tx) error
UpdateValueOnly updates only the value fields of an existing RelationshipElement.
This method allows for partial updates of a RelationshipElement, specifically targeting the "first" and "second" references without modifying other base element properties. It constructs an update record dynamically based on which fields are provided in the valueOnly parameter.
Parameters:
- submodelID: ID of the parent submodel
- idShortOrPath: idShort or hierarchical path to the element to update
- valueOnly: The RelationshipElementValue containing fields to update
Returns:
- error: An error if the update operation fails
type PostgreSQLSMECrudHandler ¶
PostgreSQLSMECrudHandler provides base CRUD operations for submodel elements in PostgreSQL.
This handler implements common functionality for all submodel element types, including database ID management, path tracking, position management, and semantic ID handling. Type-specific handlers extend this base functionality for specialized element types.
The handler operates within transaction contexts to ensure atomicity of operations and maintains hierarchical relationships through parent-child linkage and path tracking.
func NewPostgreSQLSMECrudHandler ¶
func NewPostgreSQLSMECrudHandler(db *sql.DB) (*PostgreSQLSMECrudHandler, error)
NewPostgreSQLSMECrudHandler creates a new PostgreSQL submodel element CRUD handler.
This constructor initializes a handler with a database connection that will be used for all database operations. The handler can then perform CRUD operations on submodel elements within transaction contexts.
Parameters:
- db: PostgreSQL database connection
Returns:
- *PostgreSQLSMECrudHandler: Initialized handler ready for CRUD operations
- error: Always nil in current implementation, kept for interface consistency
func (*PostgreSQLSMECrudHandler) Delete ¶
func (p *PostgreSQLSMECrudHandler) Delete(idShortOrPath string) error
Delete removes a SubmodelElement identified by its idShort or path.
This method is currently a placeholder for future implementation of element deletion. When implemented, it should handle cascading deletion of child elements and cleanup of related data such as semantic IDs and type-specific data.
Parameters:
- idShortOrPath: The idShort or full path of the element to delete
Returns:
- error: Currently always returns nil (not yet implemented)
nolint:revive
func (*PostgreSQLSMECrudHandler) GetDatabaseID ¶
func (p *PostgreSQLSMECrudHandler) GetDatabaseID(submodelID int, idShortPath string) (int, error)
GetDatabaseID retrieves the database primary key ID for an element by its path.
This method looks up the internal database ID for a submodel element using its idShort path. The database ID is needed for operations that create child elements or establish relationships between elements.
Parameters:
- idShortPath: The full idShort path of the element (e.g., "collection.property")
Returns:
- int: The database primary key ID of the element
- error: An error if the query fails or element is not found
Example:
dbID, err := handler.GetDatabaseID("sensors.temperature")
func (*PostgreSQLSMECrudHandler) GetDatabaseIDWithTx ¶
func (p *PostgreSQLSMECrudHandler) GetDatabaseIDWithTx(tx *sql.Tx, submodelID int, idShortPath string) (int, error)
GetDatabaseIDWithTx retrieves the database primary key ID for an element by its path, optionally using the provided transaction for consistent reads within a larger operation.
If tx is nil, the handler's default database connection is used.
func (*PostgreSQLSMECrudHandler) GetNextPosition ¶
func (p *PostgreSQLSMECrudHandler) GetNextPosition(parentID int) (int, error)
GetNextPosition determines the next available position index for a child element.
This method calculates the next position value to use when adding a new child element to a parent (SubmodelElementCollection or SubmodelElementList). It finds the maximum current position among existing children and returns the next value.
The position is used for:
- Maintaining order in SubmodelElementList elements
- Providing consistent ordering for SubmodelElementCollection children
- Supporting index-based access (e.g., "list[2]")
Parameters:
- parentID: Database ID of the parent element
Returns:
- int: The next position value (0 if no children exist, max+1 otherwise)
- error: An error if the query fails
Example:
nextPos, err := handler.GetNextPosition(parentDbID) // Use nextPos when creating the next child element
func (*PostgreSQLSMECrudHandler) GetRootSmeIDByElementID ¶
func (p *PostgreSQLSMECrudHandler) GetRootSmeIDByElementID(elementID int) (int, error)
GetRootSmeIDByElementID resolves the top-level root element ID for a submodel element. If root_sme_id is NULL, the element is itself a root and its own ID is returned.
func (*PostgreSQLSMECrudHandler) GetSubmodelElementType ¶
func (p *PostgreSQLSMECrudHandler) GetSubmodelElementType(idShortPath string) (*types.ModelType, error)
GetSubmodelElementType retrieves the model type of an element by its path.
This method looks up the model type (e.g., "Property", "SubmodelElementCollection", "Blob") for a submodel element using its idShort path. The model type is used to determine which type-specific handler to use for operations on the element.
Parameters:
- idShortPath: The full idShort path of the element
Returns:
- string: The model type string (e.g., "Property", "File", "Range")
- error: An error if the query fails or element is not found
Example:
modelType, err := handler.GetSubmodelElementType("sensors.temperature")
// Use modelType to get the appropriate handler via GetSMEHandlerByModelType
func (*PostgreSQLSMECrudHandler) Update ¶
func (p *PostgreSQLSMECrudHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update updates an existing SubmodelElement identified by its idShort or path.
This method updates the mutable properties of an existing submodel element within a transaction context. It preserves the element's identity (idShort, path, parent, position, model type) while allowing updates to metadata fields.
Updated fields include:
- category: Element category classification
- semanticId: Reference to semantic definition
- description: Localized descriptions
- displayName: Localized display names
- qualifiers: Qualifier constraints
- embeddedDataSpecifications: Embedded data specifications
- supplementalSemanticIds: Additional semantic references
- extensions: Custom extensions
Immutable fields (not updated):
- idShort: Element identifier
- idShortPath: Hierarchical path
- parent_sme_id: Parent element reference
- position: Position in parent
- model_type: Element type
- submodel_id: Parent submodel
Parameters:
- submodelID: ID of the parent submodel (used for validation)
- idShortOrPath: The idShort or full path of the element to update
- submodelElement: The updated element data
- tx: Active transaction context for atomic operations
Returns:
- error: An error if the element is not found, validation fails, or update fails
Example:
err := handler.Update(tx, "submodel123", "sensors.temperature", updatedProperty)
func (*PostgreSQLSMECrudHandler) UpdateIdShortPaths ¶
func (p *PostgreSQLSMECrudHandler) UpdateIdShortPaths(tx *sql.Tx, submodelID string, oldPath string, newIDShort string) (string, error)
UpdateIdShortPaths updates the idShort and idShortPath of a submodel element and all its descendants when the element's idShort changes during a PUT operation.
This method computes the new path by replacing the last segment of the old path with the new idShort, then cascades the path change to all child elements. It uses three precise LIKE patterns (exact match, dot-children, bracket-children) to avoid accidentally updating elements whose idShort merely starts with the same prefix.
Parameters:
- tx: Active transaction for atomic operations
- submodelID: ID of the parent submodel
- oldPath: The current full idShortPath of the element being updated
- newIDShort: The new idShort value from the PUT body
Returns:
- string: The new full idShortPath after the update
- error: An error if a conflict is detected or the update fails
type PostgreSQLSMECrudInterface ¶
type PostgreSQLSMECrudInterface interface {
Update(string, string, types.ISubmodelElement, *sql.Tx, bool) error
UpdateValueOnly(string, string, gen.SubmodelElementValue, *sql.Tx) error
Delete(string) error
// GetInsertQueryPart returns the type-specific insert query part for batch insertion.
// Parameters:
// - tx: Active database transaction (needed for creating references)
// - id: The database ID of the base submodel_element record
// - element: The submodel element to insert
// Returns:
// - *InsertQueryPart: The table name and record for type-specific insert (nil if no type-specific table)
// - error: An error if query part creation fails
GetInsertQueryPart(tx *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
}
PostgreSQLSMECrudInterface defines the CRUD operations for Submodel Elements in a PostgreSQL database.
func GetHandlerFromRegistry ¶
func GetHandlerFromRegistry(modelType types.ModelType, db *sql.DB) (PostgreSQLSMECrudInterface, error)
GetHandlerFromRegistry creates the appropriate handler using the handler registry. This provides a cleaner alternative to the large switch statement in GetSMEHandlerByModelType.
Parameters:
- modelType: String representation of the submodel element type
- db: Database connection to be used by the handler
Returns:
- PostgreSQLSMECrudInterface: Type-specific handler implementing CRUD operations
- error: An error if the model type is unsupported or handler creation fails
func GetSMEHandler ¶
func GetSMEHandler(submodelElement types.ISubmodelElement, db *sql.DB) (PostgreSQLSMECrudInterface, error)
GetSMEHandler creates the appropriate CRUD handler for a submodel element.
This function uses the Factory Pattern to instantiate the correct handler based on the model type of the provided submodel element. It provides a clean, type-safe way to obtain handlers without requiring client code to know the concrete handler types.
Parameters:
- submodelElement: The submodel element for which to create a handler
- db: Database connection to be used by the handler
Returns:
- PostgreSQLSMECrudInterface: Type-specific handler implementing CRUD operations
- error: An error if the model type is unsupported or handler creation fails
func GetSMEHandlerByModelType ¶
func GetSMEHandlerByModelType(modelType types.ModelType, db *sql.DB) (PostgreSQLSMECrudInterface, error)
GetSMEHandlerByModelType creates a handler by model type string.
This function implements the Single Responsibility Principle by focusing solely on the logic for determining and instantiating the correct handler based on a model type string. It supports all AAS submodel element types defined in the specification.
Supported model types:
- AnnotatedRelationshipElement: Relationship with annotations
- BasicEventElement: Event element for monitoring and notifications
- Blob: Binary data element
- Capability: Functional capability description
- Entity: Logical or physical entity
- File: File reference element
- MultiLanguageProperty: Property with multi-language support
- Operation: Invocable operation
- Property: Single-valued property
- Range: Value range element
- ReferenceElement: Reference to another element
- RelationshipElement: Relationship between elements
- SubmodelElementCollection: Collection of submodel elements
- SubmodelElementList: Ordered list of submodel elements
Parameters:
- modelType: String representation of the submodel element type
- db: Database connection to be used by the handler
Returns:
- PostgreSQLSMECrudInterface: Type-specific handler implementing CRUD operations
- error: An error if the model type is unsupported or handler creation fails
type PostgreSQLSubmodelElementCollectionHandler ¶
type PostgreSQLSubmodelElementCollectionHandler struct {
// contains filtered or unexported fields
}
PostgreSQLSubmodelElementCollectionHandler provides PostgreSQL-based persistence operations for SubmodelElementCollection elements. It implements CRUD operations for collections that group related submodel elements together in a hierarchical structure with dot-notation addressing.
func NewPostgreSQLSubmodelElementCollectionHandler ¶
func NewPostgreSQLSubmodelElementCollectionHandler(db *sql.DB) (*PostgreSQLSubmodelElementCollectionHandler, error)
NewPostgreSQLSubmodelElementCollectionHandler creates a new handler for SubmodelElementCollection persistence. It initializes the handler with a database connection and sets up the decorated CRUD handler for common submodel element operations.
Parameters:
- db: PostgreSQL database connection
Returns:
- *PostgreSQLSubmodelElementCollectionHandler: Configured handler instance
- error: Error if handler initialization fails
func (PostgreSQLSubmodelElementCollectionHandler) Delete ¶
func (p PostgreSQLSubmodelElementCollectionHandler) Delete(idShortOrPath string) error
Delete removes a SubmodelElementCollection identified by its idShort or path from the database. This method delegates the deletion operation to the decorated CRUD handler which handles the cascading deletion of all related data and child elements within the collection.
Parameters:
- idShortOrPath: idShort or hierarchical path to the collection to delete
Returns:
- error: Error if deletion fails
func (PostgreSQLSubmodelElementCollectionHandler) GetInsertQueryPart ¶
func (p PostgreSQLSubmodelElementCollectionHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
GetInsertQueryPart returns the type-specific insert query part for batch insertion of SubmodelElementCollection elements. It returns the table name and record for inserting into the submodel_element_collection table.
Parameters:
- tx: Active database transaction (not used for Collection)
- id: The database ID of the base submodel_element record
- element: The SubmodelElementCollection element to insert
Returns:
- *InsertQueryPart: The table name and record for submodel_element_collection insert
- error: An error if the element is not of type SubmodelElementCollection
func (PostgreSQLSubmodelElementCollectionHandler) Update ¶
func (p PostgreSQLSubmodelElementCollectionHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update modifies an existing SubmodelElementCollection element identified by its idShort or path. This method delegates the update operation to the decorated CRUD handler which handles the common submodel element update logic.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: idShort or hierarchical path to the collection to update
- submodelElement: Updated collection data (must be of type *gen.SubmodelElementCollection)
- tx: Optional database transaction (created if nil)
- isPut: true for PUT (replace all), false for PATCH (update only provided fields)
Returns:
- error: Error if update fails or element is not of correct type
func (PostgreSQLSubmodelElementCollectionHandler) UpdateValueOnly ¶
func (p PostgreSQLSubmodelElementCollectionHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, tx *sql.Tx) error
UpdateValueOnly updates only the value of an existing SubmodelElementCollection submodel element identified by its idShort or path. It processes the new value and updates nested elements accordingly.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- valueOnly: The new value to set (must be of type gen.SubmodelElementValue)
Returns:
- error: An error if the update operation fails
type PostgreSQLSubmodelElementListHandler ¶
type PostgreSQLSubmodelElementListHandler struct {
// contains filtered or unexported fields
}
PostgreSQLSubmodelElementListHandler handles the persistence operations for SubmodelElementList submodel elements. It implements the SubmodelElementHandler interface and uses the decorator pattern to extend the base CRUD operations with SubmodelElementList-specific functionality.
func NewPostgreSQLSubmodelElementListHandler ¶
func NewPostgreSQLSubmodelElementListHandler(db *sql.DB) (*PostgreSQLSubmodelElementListHandler, error)
NewPostgreSQLSubmodelElementListHandler creates a new PostgreSQLSubmodelElementListHandler instance. It initializes the handler with a database connection and creates the decorated base CRUD handler for common SubmodelElement operations.
Parameters:
- db: Database connection to PostgreSQL
Returns:
- *PostgreSQLSubmodelElementListHandler: Configured SubmodelElementList handler instance
- error: Error if the decorated handler creation fails
func (PostgreSQLSubmodelElementListHandler) Delete ¶
func (p PostgreSQLSubmodelElementListHandler) Delete(idShortOrPath string) error
Delete removes a SubmodelElementList submodel element from the database. Currently delegates to the decorated handler for base SubmodelElement deletion. SubmodelElementList-specific data is automatically deleted due to foreign key constraints.
Parameters:
- idShortOrPath: The idShort or path identifier of the element to delete
Returns:
- error: Error if the delete operation fails
func (PostgreSQLSubmodelElementListHandler) GetInsertQueryPart ¶
func (p PostgreSQLSubmodelElementListHandler) GetInsertQueryPart(_ *sql.Tx, id int, element types.ISubmodelElement) (*InsertQueryPart, error)
GetInsertQueryPart returns the type-specific insert query part for batch insertion of SubmodelElementList elements. It returns the table name and record for inserting into the submodel_element_list table. Note: This method does not handle semantic_id_list_element which requires reference insertion.
Parameters:
- tx: Active database transaction (needed for reference insertion)
- id: The database ID of the base submodel_element record
- element: The SubmodelElementList element to insert
Returns:
- *InsertQueryPart: The table name and record for submodel_element_list insert
- error: An error if the element is not of type SubmodelElementList
func (PostgreSQLSubmodelElementListHandler) Update ¶
func (p PostgreSQLSubmodelElementListHandler) Update(submodelID string, idShortOrPath string, submodelElement types.ISubmodelElement, tx *sql.Tx, isPut bool) error
Update modifies an existing SubmodelElementList element identified by its idShort or path. This method delegates the update operation to the decorated CRUD handler which handles the common submodel element update logic and then updates SubmodelElementList-specific fields.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifier of the element to update
- submodelElement: The updated SubmodelElementList data (must be of type *gen.SubmodelElementList)
- tx: Optional database transaction (created if nil)
- isPut: true for PUT (replace all), false for PATCH (update only provided fields)
Returns:
- error: Error if the update operation fails or element is not of correct type
func (PostgreSQLSubmodelElementListHandler) UpdateValueOnly ¶
func (p PostgreSQLSubmodelElementListHandler) UpdateValueOnly(submodelID string, idShortOrPath string, valueOnly gen.SubmodelElementValue, tx *sql.Tx) error
UpdateValueOnly updates only the value of an existing SubmodelElementList submodel element identified by its idShort or path. It processes the new value and updates nested elements accordingly.
Parameters:
- submodelID: The ID of the parent submodel
- idShortOrPath: The idShort or path identifying the element to update
- valueOnly: The new value to set (must be of type gen.SubmodelElementValue)
Returns:
- error: An error if the update operation fails
type SubmodelElementToProcess ¶
type SubmodelElementToProcess struct {
Element types.ISubmodelElement
IdShortPath string
}
SubmodelElementToProcess represents a SubmodelElement along with its ID short path.
type TypedRangeValue ¶
type TypedRangeValue struct {
MinText sql.NullString
MaxText sql.NullString
MinNumeric sql.NullString
MaxNumeric sql.NullString
MinTime sql.NullString
MaxTime sql.NullString
MinDate sql.NullString
MaxDate sql.NullString
MinDateTime sql.NullString
MaxDateTime sql.NullString
}
TypedRangeValue represents min/max values categorized by XS datatype for database storage. Used for Range submodel elements that have both min and max values.
func MapRangeValueByType ¶
func MapRangeValueByType(valueType types.DataTypeDefXSD, minValue string, maxValue string) TypedRangeValue
MapRangeValueByType categorizes min/max values into the appropriate TypedRangeValue fields based on XS datatype.
Parameters:
- valueType: The XS datatype string (e.g., "xs:string", "xs:int", "xs:time")
- minValue: The minimum value to be stored
- maxValue: The maximum value to be stored
Returns:
- TypedRangeValue: A struct with the values placed in the appropriate fields based on type
type TypedValue ¶
type TypedValue struct {
Text sql.NullString // For string-like types: xs:string, xs:anyURI, xs:base64Binary, xs:hexBinary
Numeric sql.NullString // For numeric types: xs:int, xs:integer, xs:decimal, xs:double, xs:float, etc.
Boolean sql.NullString // For xs:boolean type
Time sql.NullString // For xs:time type
Date sql.NullString // For xs:date type
DateTime sql.NullString // For date/time types: xs:dateTime, xs:duration, xs:gDay, etc.
}
TypedValue represents a value categorized by its XS datatype for database storage. Each field corresponds to a different column type in the database schema, allowing for type-appropriate storage and retrieval of AAS values.
func MapValueByType ¶
func MapValueByType(valueType types.DataTypeDefXSD, value *string) TypedValue
MapValueByType categorizes a value into the appropriate TypedValue field based on its XS datatype. This consolidates the repeated switch statements found throughout the codebase for determining which database column to use for storing AAS values.
Parameters:
- valueType: The XS datatype string (e.g., "xs:string", "xs:int", "xs:boolean")
- value: The actual value to be stored
Returns:
- TypedValue: A struct with the value placed in the appropriate field based on type
type ValueOnlyElementsToProcess ¶
type ValueOnlyElementsToProcess struct {
Element gen.SubmodelElementValue
IdShortPath string
}
ValueOnlyElementsToProcess represents a SubmodelElementValue along with its ID short path.
Source Files
¶
- AnnotatedRelationshipElementHandler.go
- BaseHandler.go
- BasicEventElementHandler.go
- BlobHandler.go
- CapabilityHandler.go
- CollectionHandler.go
- EntityHandler.go
- FileHandler.go
- HandlerRegistry.go
- ListHandler.go
- MultiLanguagePropertyHandler.go
- OperationHandler.go
- PropertyHandler.go
- RangeHandler.go
- ReferenceElementHandler.go
- RelationshipElementHandler.go
- SMECrudHandler.go
- SMECrudInterface.go
- submodel_element_database.go
- submodel_element_database_utils.go
- submodel_element_read.go
- submodel_element_utils.go
- submodel_element_value_expression.go
- value_type_mapper.go