3
0
corteza/pkg/dal/attribute_codec.go
Tomaž Jerman 81dda274eb DAL service refactor & RDBMS interface tweak
* Remove Compose service related bits out of the DAL service
* Minor DB connectivity tweaks and include capabilities
* Add values column to the compose_record table
* Compose types tweaks
2022-05-20 15:37:33 +02:00

59 lines
1.6 KiB
Go

package dal
type (
AttributeCodecType string
// Codec defines how values for a specific model attribute
// are retrieved or stored
//
// If attribute does not have store strategy set
// store driver should use attribute name to determinate
// source/destination of the value (table column, json document property)
Codec interface {
Type() AttributeCodecType
}
CodecPlain struct{}
// CodecRecordValueSetJSON defines that values are encoded/decoded into
// a JSON simple document { [_: string]: Array<unknown> }
//
// This only solves
// Attribute{Ident: "foo", Store: StoreCodecRecordValueJSON{ Ident: "bar" }
// => "bar"->'foo'->0
CodecRecordValueSetJSON struct {
Ident string
}
// handling complex JSON documents
//StoreCodecJSON struct {
// Ident string
// Path []any
//}
//
// { "@value": ... "@type": .... }
// StoreCodecJSONLD struct { Ident string; Path []any }
// StoreCodecXML
//StoreCodecXML struct {}
// CodecAlias defines case when value is not stored
// under the same column (in case of an SQL table)
//
// Value of CodecAlias.Ident is used as base
// and value of Attribute.Ident holding CodecAlias is used
// as an alias!
//
// Attribute{Ident: "foo", Store: CodecAlias{ Ident: "bar" }
// => "bar" as "foo"
CodecAlias struct {
Ident string
}
)
func (*CodecPlain) Type() AttributeCodecType { return "corteza::dal:attribute-codec:plain" }
func (*CodecRecordValueSetJSON) Type() AttributeCodecType {
return "corteza::dal:attribute-codec:record-value-set-json"
}
func (*CodecAlias) Type() AttributeCodecType { return "corteza::dal:attribute-codec:alias" }