Documentation ¶
Overview ¶
Package dcon - universal data container for any values and tables
Index ¶
- Constants
- func CDsVal[T any](c *DataContainer, id int, row int, column int) T
- func CDsValue[T any](c *DataContainer, id int, row int, column int) (T, error)
- func CVal[T any](c *DataContainer, id int) T
- func CValue[T any](c *DataContainer, id int) (T, error)
- func DsVal[T any](table *Table, row int, column int) T
- func DsValue[T any](table *Table, row int, column int) (T, error)
- type ColumnConfig
- type ContainerReadWriter
- type ContainerReader
- type ContainerWriter
- type DataContainer
- func (d *DataContainer) AppendRow(id int) error
- func (d *DataContainer) Clear(id int) error
- func (d *DataContainer) Clone() *DataContainer
- func (d *DataContainer) Contains(id int) bool
- func (d *DataContainer) Debug() string
- func (d *DataContainer) FromJSON(data []byte) error
- func (d *DataContainer) GetFloat32(id int) float32
- func (d *DataContainer) GetFloat64(id int) float64
- func (d *DataContainer) GetInt(id int) int
- func (d *DataContainer) GetInt64(id int) int64
- func (d *DataContainer) GetString(id int) string
- func (d *DataContainer) GetTableFloat32(id int, row int, column int) float32
- func (d *DataContainer) GetTableFloat64(id int, row int, column int) float64
- func (d *DataContainer) GetTableInt(id int, row int, column int) int
- func (d *DataContainer) GetTableInt64(id int, row int, column int) int64
- func (d *DataContainer) GetTableString(id int, row int, column int) string
- func (d *DataContainer) GetTableTime(id int, row int, column int) time.Time
- func (d *DataContainer) GetTableVal(id int, row int, column int) interface{}
- func (d *DataContainer) GetTableValue(id int, row int, column int) (interface{}, error)
- func (d *DataContainer) GetTime(id int) time.Time
- func (d *DataContainer) GetVal(id int) interface{}
- func (d *DataContainer) GetValue(id int) (interface{}, error)
- func (d *DataContainer) InitTable(id int, rowCount int, columnCount int) (*Table, error)
- func (d *DataContainer) InsertRow(id int, pos int) error
- func (d *DataContainer) IsTable(id int) bool
- func (d *DataContainer) IsValue(id int) bool
- func (d *DataContainer) MarshalJSON() ([]byte, error)
- func (d *DataContainer) Properties() (values []int, tables []int)
- func (d *DataContainer) Reset()
- func (d *DataContainer) SetTableValue(id int, row int, column int, value interface{}) error
- func (d *DataContainer) SetTimeFormat(f string)
- func (d *DataContainer) SetValue(id int, value interface{}) error
- func (d *DataContainer) Table(id int) (*Table, error)
- func (d *DataContainer) ToFile(fname string, perm os.FileMode) error
- func (d *DataContainer) ToJSON() []byte
- func (d *DataContainer) Trim(id int) error
- func (d *DataContainer) UnmarshalJSON(data []byte) error
- func (d *DataContainer) Validate(names map[int]string, rules map[int][]validation.Rule) error
- type DataType
- type DatasetConfig
- type Entity
- type EntityID
- type FieldConfig
- type Property
- type PropertyID
- type PropertyType
- type StrictContainer
- func (sc *StrictContainer) AppendRow(datasetID PropertyID) error
- func (sc *StrictContainer) Clear(id PropertyID) error
- func (sc *StrictContainer) ClearCell(row int, columnID PropertyID) error
- func (sc *StrictContainer) ColumnCount(datasetID PropertyID) int
- func (sc *StrictContainer) ColumnFromPos(datasetID PropertyID, pos int) (PropertyID, error)
- func (sc *StrictContainer) ContainsProperty(id PropertyID) bool
- func (sc *StrictContainer) DatasetByColumn(columnID PropertyID) (PropertyID, error)
- func (sc *StrictContainer) DatasetColumns(datasetID PropertyID) ([]PropertyID, error)
- func (sc *StrictContainer) DatasetColumnsProperty(datasetID PropertyID) ([]Property, error)
- func (sc *StrictContainer) GetAny(id PropertyID) interface{}
- func (sc *StrictContainer) GetByteArray(id PropertyID) []byte
- func (sc *StrictContainer) GetCellAny(row int, columnID PropertyID) interface{}
- func (sc *StrictContainer) GetCellByteArray(row int, columnID PropertyID) []byte
- func (sc *StrictContainer) GetCellFloat(row int, columnID PropertyID) float64
- func (sc *StrictContainer) GetCellInt(row int, columnID PropertyID) int64
- func (sc *StrictContainer) GetCellString(row int, columnID PropertyID) string
- func (sc *StrictContainer) GetFloat(id PropertyID) float64
- func (sc *StrictContainer) GetInt(id PropertyID) int64
- func (sc *StrictContainer) GetString(id PropertyID) string
- func (sc *StrictContainer) InsertRow(datasetID PropertyID, pos int) error
- func (sc *StrictContainer) IsCellEmpty(row int, columnID PropertyID) bool
- func (sc *StrictContainer) IsEmpty(id PropertyID) bool
- func (sc *StrictContainer) MarshalJSON() ([]byte, error)
- func (sc *StrictContainer) Properties() []Property
- func (sc *StrictContainer) Property(id PropertyID) (Property, bool)
- func (sc *StrictContainer) RawData() *DataContainer
- func (sc *StrictContainer) RowCount(datasetID PropertyID) int
- func (sc *StrictContainer) SetCellValue(row int, columnID PropertyID, v interface{}) error
- func (sc *StrictContainer) SetValue(id PropertyID, v interface{}) error
- func (sc *StrictContainer) StructID() StructureID
- func (sc *StrictContainer) StructName() string
- func (sc *StrictContainer) Structure() *Structure
- func (sc *StrictContainer) ToFile(fname string, perm os.FileMode) error
- func (sc *StrictContainer) ToJSON() []byte
- func (sc *StrictContainer) Trim(id PropertyID) error
- func (sc *StrictContainer) TrimCell(row int, columnID PropertyID) error
- func (sc *StrictContainer) Validate(rules map[PropertyID][]validation.Rule) error
- type Structure
- func (sc *Structure) Contains(id PropertyID) bool
- func (sc *Structure) DatasetByColumn(columnID PropertyID) (PropertyID, error)
- func (sc *Structure) DatasetColumns(datasetID PropertyID) ([]PropertyID, error)
- func (sc *Structure) DatasetColumnsProperty(datasetID PropertyID) ([]Property, error)
- func (sc *Structure) ID() StructureID
- func (sc *Structure) Name() string
- func (sc *Structure) Properties() []Property
- func (sc *Structure) Property(id PropertyID) (Property, bool)
- type StructureConfig
- type StructureFactory
- type StructureID
- type StructureInformer
- type Table
- func (d *Table) AppendRow()
- func (d *Table) Clear()
- func (d *Table) Clone() *Table
- func (d *Table) ColumnCount() int
- func (d *Table) Debug() string
- func (d *Table) FromJSON(data []byte) error
- func (d *Table) GetVal(row int, column int) interface{}
- func (d *Table) GetValue(row int, column int) (interface{}, error)
- func (d *Table) InsertRow(pos int) error
- func (d *Table) MarshalJSON() ([]byte, error)
- func (d *Table) RowCount() int
- func (d *Table) SetColumnCount(n int) error
- func (d *Table) SetDim(rowCount int, columnCount int) error
- func (d *Table) SetRowCount(n int) error
- func (d *Table) SetValue(row int, column int, value interface{}) error
- func (d *Table) ToJSON() []byte
- func (d *Table) UnmarshalJSON(data []byte) error
Constants ¶
const PropertyIDUnefined = PropertyID(0)
PropertyIDUnefined ...
Variables ¶
This section is empty.
Functions ¶
func CDsVal ¶
func CDsVal[T any](c *DataContainer, id int, row int, column int) T
CDsVal - generic helper for read table value from DataContainer. Errors ignored
func CVal ¶
func CVal[T any](c *DataContainer, id int) T
CVal - generic helper for read value from DataContainer. Errors ignored
func CValue ¶
func CValue[T any](c *DataContainer, id int) (T, error)
CValue - generic helper for read value from DataContainer
Types ¶
type ColumnConfig ¶
type ColumnConfig struct { ID PropertyID DataType DataType Name string }
type ContainerReadWriter ¶
type ContainerReadWriter interface { ContainerReader ContainerWriter }
ContainerReadWriter - read and write interface for container
type ContainerReader ¶
type ContainerReader interface { StructureInformer GetInt(id PropertyID) int64 GetFloat(id PropertyID) float64 GetString(id PropertyID) string GetByteArray(id PropertyID) []byte GetAny(id PropertyID) interface{} IsEmpty(id PropertyID) bool GetCellInt(row int, columnID PropertyID) int64 GetCellFloat(row int, columnID PropertyID) float64 GetCellString(row int, columnID PropertyID) string GetCellByteArray(row int, columnID PropertyID) []byte GetCellAny(row int, columnID PropertyID) interface{} IsCellEmpty(row int, columnID PropertyID) bool RowCount(datasetID PropertyID) int ColumnCount(datasetID PropertyID) int ColumnFromPos(datasetID PropertyID, pos int) (PropertyID, error) }
ContainerReader - interface for reading from container
type ContainerWriter ¶
type ContainerWriter interface { StructureInformer SetValue(id PropertyID, v interface{}) error Trim(id PropertyID) error Clear(id PropertyID) error SetCellValue(row int, columnID PropertyID, v interface{}) error TrimCell(row int, columnID PropertyID) error ClearCell(row int, columnID PropertyID) error AppendRow(datasetID PropertyID) error InsertRow(datasetID PropertyID, pos int) error }
ContainerWriter - interface for writing to container
type DataContainer ¶
type DataContainer struct {
// contains filtered or unexported fields
}
DataContainer - container of any data. Access by field ID
func NewDataContainer ¶
func NewDataContainer(valueIDs []int, tableIDs []int) (*DataContainer, error)
NewDataContainer - create DataContainer
valueIDs: ID of general fields, tableIDs: ID of tables
func NewDataContainerJSON ¶
func NewDataContainerJSON(data []byte) (*DataContainer, error)
NewDataContainerJSON - create DataContainer from JSON
func (*DataContainer) AppendRow ¶
func (d *DataContainer) AppendRow(id int) error
AppendRow - append row to the end of table
func (*DataContainer) Clone ¶
func (d *DataContainer) Clone() *DataContainer
Clone - clone DataContainer
func (*DataContainer) Contains ¶
func (d *DataContainer) Contains(id int) bool
Contains - contains id property
func (*DataContainer) FromJSON ¶
func (d *DataContainer) FromJSON(data []byte) error
ToJSON - export to JSON
func (*DataContainer) GetFloat32 ¶
func (d *DataContainer) GetFloat32(id int) float32
GetInt - get object value by ID. Convert to int if it possible
func (*DataContainer) GetFloat64 ¶
func (d *DataContainer) GetFloat64(id int) float64
GetInt64 - get object value by ID. Convert to int64 if it possible
func (*DataContainer) GetInt ¶
func (d *DataContainer) GetInt(id int) int
GetInt - get object value by ID. Convert to int if it possible
func (*DataContainer) GetInt64 ¶
func (d *DataContainer) GetInt64(id int) int64
GetInt64 - get object value by ID. Convert to int64 if it possible
func (*DataContainer) GetString ¶
func (d *DataContainer) GetString(id int) string
GetString - get object value by ID. Convert to string if it possible
func (*DataContainer) GetTableFloat32 ¶
func (d *DataContainer) GetTableFloat32(id int, row int, column int) float32
GetTableInt - get table value by ID. Convert to int if it possible
func (*DataContainer) GetTableFloat64 ¶
func (d *DataContainer) GetTableFloat64(id int, row int, column int) float64
GetTableInt64 - get table value by ID. Convert to int64 if it possible
func (*DataContainer) GetTableInt ¶
func (d *DataContainer) GetTableInt(id int, row int, column int) int
GetTableInt - get table value by ID. Convert to int if it possible
func (*DataContainer) GetTableInt64 ¶
func (d *DataContainer) GetTableInt64(id int, row int, column int) int64
GetTableInt64 - get table value by ID. Convert to int64 if it possible
func (*DataContainer) GetTableString ¶
func (d *DataContainer) GetTableString(id int, row int, column int) string
GetTableString - get table value by ID. Convert to string if it possible
func (*DataContainer) GetTableTime ¶
GetTableTime - get table value by ID. Convert to time if it possible
func (*DataContainer) GetTableVal ¶
func (d *DataContainer) GetTableVal(id int, row int, column int) interface{}
GetTableVal - get table value by ID. Errors ignored
func (*DataContainer) GetTableValue ¶
func (d *DataContainer) GetTableValue(id int, row int, column int) (interface{}, error)
GetTableValue - get table value by ID
func (*DataContainer) GetTime ¶
func (d *DataContainer) GetTime(id int) time.Time
GetTime - get object value by ID. Convert to time if it possible
func (*DataContainer) GetVal ¶
func (d *DataContainer) GetVal(id int) interface{}
GetVal - get object value by ID. Errors ignored
func (*DataContainer) GetValue ¶
func (d *DataContainer) GetValue(id int) (interface{}, error)
GetValue - get object value by ID
func (*DataContainer) InsertRow ¶
func (d *DataContainer) InsertRow(id int, pos int) error
InsertRow - insert row to position. pos == 0 => insert to first row, pos == RowCount => insert to the end
func (*DataContainer) IsTable ¶
func (d *DataContainer) IsTable(id int) bool
IsTable - check is property is table (not value)
func (*DataContainer) IsValue ¶
func (d *DataContainer) IsValue(id int) bool
IsValue - check is property is value (not table)
func (*DataContainer) MarshalJSON ¶
func (d *DataContainer) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface
func (*DataContainer) Properties ¶
func (d *DataContainer) Properties() (values []int, tables []int)
Properties - return all properties ID
func (*DataContainer) SetTableValue ¶
func (d *DataContainer) SetTableValue(id int, row int, column int, value interface{}) error
SetTableValue - write table value by ID
func (*DataContainer) SetTimeFormat ¶
func (d *DataContainer) SetTimeFormat(f string)
SetTimeFormat - set format string fo GetString function
func (*DataContainer) SetValue ¶
func (d *DataContainer) SetValue(id int, value interface{}) error
SetValue - write object value by ID
func (*DataContainer) Table ¶
func (d *DataContainer) Table(id int) (*Table, error)
Table - get Table object by ID
func (*DataContainer) ToFile ¶
func (d *DataContainer) ToFile(fname string, perm os.FileMode) error
ToFile - export to file
func (*DataContainer) Trim ¶
func (d *DataContainer) Trim(id int) error
func (*DataContainer) UnmarshalJSON ¶
func (d *DataContainer) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface
func (*DataContainer) Validate ¶
func (d *DataContainer) Validate(names map[int]string, rules map[int][]validation.Rule) error
Validate - data validation
type DatasetConfig ¶
type DatasetConfig struct { ID PropertyID Name string Columns []ColumnConfig }
type Entity ¶
type Entity[T EntityID] struct { // contains filtered or unexported fields }
Entity - an object with a specified data structure and a unique identifier
func MakeEntity ¶
func MakeEntity[T EntityID](data *StrictContainer, id T) *Entity[T]
func NewEntity ¶
func NewEntity[T EntityID](factory *StructureFactory, structureID StructureID, id T) (*Entity[T], error)
NewEntity - create new Entity
type FieldConfig ¶
type FieldConfig struct { ID PropertyID DataType DataType Name string }
type Property ¶
type Property struct {
// contains filtered or unexported fields
}
Property ...
func NewDatasetProperty ¶
func NewDatasetProperty( id PropertyID, name string, columns []Property) (Property, error)
func NewFieldProperty ¶
func NewFieldProperty( id PropertyID, dataType DataType, name string) (Property, error)
func (*Property) ID ¶
func (p *Property) ID() PropertyID
func (*Property) PropertyType ¶
func (p *Property) PropertyType() PropertyType
type PropertyType ¶
type PropertyType uint8
PropertyType ...
const ( Field PropertyType = 1 Dataset PropertyType = 2 )
type StrictContainer ¶
type StrictContainer struct {
// contains filtered or unexported fields
}
StrictContainer ...
func NewStrictContainer ¶
func NewStrictContainer(structure *Structure) *StrictContainer
NewStrictContainer ...
func (*StrictContainer) AppendRow ¶
func (sc *StrictContainer) AppendRow(datasetID PropertyID) error
func (*StrictContainer) Clear ¶
func (sc *StrictContainer) Clear(id PropertyID) error
func (*StrictContainer) ClearCell ¶
func (sc *StrictContainer) ClearCell(row int, columnID PropertyID) error
func (*StrictContainer) ColumnCount ¶
func (sc *StrictContainer) ColumnCount(datasetID PropertyID) int
func (*StrictContainer) ColumnFromPos ¶
func (sc *StrictContainer) ColumnFromPos(datasetID PropertyID, pos int) (PropertyID, error)
ColumnFromPos - convert column position to PropertyID
func (*StrictContainer) ContainsProperty ¶
func (sc *StrictContainer) ContainsProperty(id PropertyID) bool
func (*StrictContainer) DatasetByColumn ¶
func (sc *StrictContainer) DatasetByColumn(columnID PropertyID) (PropertyID, error)
func (*StrictContainer) DatasetColumns ¶
func (sc *StrictContainer) DatasetColumns(datasetID PropertyID) ([]PropertyID, error)
func (*StrictContainer) DatasetColumnsProperty ¶
func (sc *StrictContainer) DatasetColumnsProperty(datasetID PropertyID) ([]Property, error)
func (*StrictContainer) GetAny ¶
func (sc *StrictContainer) GetAny(id PropertyID) interface{}
func (*StrictContainer) GetByteArray ¶
func (sc *StrictContainer) GetByteArray(id PropertyID) []byte
func (*StrictContainer) GetCellAny ¶
func (sc *StrictContainer) GetCellAny(row int, columnID PropertyID) interface{}
func (*StrictContainer) GetCellByteArray ¶
func (sc *StrictContainer) GetCellByteArray(row int, columnID PropertyID) []byte
func (*StrictContainer) GetCellFloat ¶
func (sc *StrictContainer) GetCellFloat(row int, columnID PropertyID) float64
func (*StrictContainer) GetCellInt ¶
func (sc *StrictContainer) GetCellInt(row int, columnID PropertyID) int64
func (*StrictContainer) GetCellString ¶
func (sc *StrictContainer) GetCellString(row int, columnID PropertyID) string
func (*StrictContainer) GetFloat ¶
func (sc *StrictContainer) GetFloat(id PropertyID) float64
func (*StrictContainer) GetInt ¶
func (sc *StrictContainer) GetInt(id PropertyID) int64
func (*StrictContainer) GetString ¶
func (sc *StrictContainer) GetString(id PropertyID) string
func (*StrictContainer) InsertRow ¶
func (sc *StrictContainer) InsertRow(datasetID PropertyID, pos int) error
func (*StrictContainer) IsCellEmpty ¶
func (sc *StrictContainer) IsCellEmpty(row int, columnID PropertyID) bool
func (*StrictContainer) IsEmpty ¶
func (sc *StrictContainer) IsEmpty(id PropertyID) bool
func (*StrictContainer) MarshalJSON ¶
func (sc *StrictContainer) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface
func (*StrictContainer) Properties ¶
func (sc *StrictContainer) Properties() []Property
func (*StrictContainer) Property ¶
func (sc *StrictContainer) Property(id PropertyID) (Property, bool)
func (*StrictContainer) RawData ¶
func (sc *StrictContainer) RawData() *DataContainer
func (*StrictContainer) RowCount ¶
func (sc *StrictContainer) RowCount(datasetID PropertyID) int
func (*StrictContainer) SetCellValue ¶
func (sc *StrictContainer) SetCellValue(row int, columnID PropertyID, v interface{}) error
func (*StrictContainer) SetValue ¶
func (sc *StrictContainer) SetValue(id PropertyID, v interface{}) error
func (*StrictContainer) StructID ¶
func (sc *StrictContainer) StructID() StructureID
func (*StrictContainer) StructName ¶
func (sc *StrictContainer) StructName() string
func (*StrictContainer) Structure ¶
func (sc *StrictContainer) Structure() *Structure
func (*StrictContainer) ToFile ¶
func (sc *StrictContainer) ToFile(fname string, perm os.FileMode) error
ToFile - export to file
func (*StrictContainer) Trim ¶
func (sc *StrictContainer) Trim(id PropertyID) error
func (*StrictContainer) TrimCell ¶
func (sc *StrictContainer) TrimCell(row int, columnID PropertyID) error
func (*StrictContainer) Validate ¶
func (sc *StrictContainer) Validate(rules map[PropertyID][]validation.Rule) error
Validate - data validation
type Structure ¶
type Structure struct {
// contains filtered or unexported fields
}
Structure ...
func NewStructure ¶
func NewStructure(factory *StructureFactory, id StructureID, name string, properties []Property) (*Structure, error)
func NewStructureConf ¶
func NewStructureConf(factory *StructureFactory, conf StructureConfig) (*Structure, error)
func (*Structure) Contains ¶
func (sc *Structure) Contains(id PropertyID) bool
func (*Structure) DatasetByColumn ¶
func (sc *Structure) DatasetByColumn(columnID PropertyID) (PropertyID, error)
func (*Structure) DatasetColumns ¶
func (sc *Structure) DatasetColumns(datasetID PropertyID) ([]PropertyID, error)
func (*Structure) DatasetColumnsProperty ¶
func (sc *Structure) DatasetColumnsProperty(datasetID PropertyID) ([]Property, error)
func (*Structure) ID ¶
func (sc *Structure) ID() StructureID
func (*Structure) Properties ¶
type StructureConfig ¶
type StructureConfig struct { ID StructureID Name string Version uint16 Fields []FieldConfig Datasets []DatasetConfig }
type StructureFactory ¶
type StructureFactory struct {
// contains filtered or unexported fields
}
func NewStructureFactory ¶
func NewStructureFactory() *StructureFactory
func (*StructureFactory) Get ¶
func (sf *StructureFactory) Get(id StructureID) *Structure
type StructureID ¶
type StructureID uint16
type StructureInformer ¶
type StructureInformer interface { StructID() StructureID StructName() string Properties() []Property Property(id PropertyID) (Property, bool) ContainsProperty(id PropertyID) bool DatasetColumns(datasetID PropertyID) ([]PropertyID, error) DatasetColumnsProperty(datasetID PropertyID) ([]Property, error) DatasetByColumn(columnID PropertyID) (PropertyID, error) }
StructureInformer - information about data structure
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table - table with any data
func NewTableJSON ¶
NewTableJSON - create Table object from JSON
func (*Table) InsertRow ¶
InsertRow - insert row to position. pos == 0 => insert to first row, pos == RowCount => insert to the end
func (*Table) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface
func (*Table) SetColumnCount ¶
SetColumnCount - set column count
func (*Table) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface