mapper

package
v0.0.0-...-f0bc3ce Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrColumnNotFound

type ErrColumnNotFound struct {
	// contains filtered or unexported fields
}

ErrColumnNotFound is an error that can occur when the column does not exist for a table

func NewErrColumnNotFound

func NewErrColumnNotFound(column, table string) *ErrColumnNotFound

func (*ErrColumnNotFound) Error

func (e *ErrColumnNotFound) Error() string

Error implements the error interface

type ErrMapper

type ErrMapper struct {
	// contains filtered or unexported fields
}

ErrMapper describes an error in an Mapper type

func (*ErrMapper) Error

func (e *ErrMapper) Error() string

type Info

type Info struct {
	// FieldName indexed by column
	Obj      interface{}
	Metadata Metadata
}

Info is a struct that wraps an object with its metadata

func NewInfo

func NewInfo(tableName string, table *ovsdb.TableSchema, obj interface{}) (*Info, error)

NewInfo creates a MapperInfo structure around an object based on a given table schema

func (*Info) ColumnByPtr

func (i *Info) ColumnByPtr(fieldPtr interface{}) (string, error)

ColumnByPtr returns the column name that corresponds to the field by the field's pointer

func (*Info) FieldByColumn

func (i *Info) FieldByColumn(column string) (interface{}, error)

FieldByColumn returns the field value that corresponds to a column

func (*Info) SetField

func (i *Info) SetField(column string, value interface{}) error

SetField sets the field in the column to the specified value

type Mapper

type Mapper struct {
	Schema ovsdb.DatabaseSchema
}

Mapper offers functions to interact with libovsdb through user-provided native structs. The way to specify what field of the struct goes to what column in the database id through field a field tag. The tag used is "ovsdb" and has the following structure 'ovsdb:"${COLUMN_NAME}"'

where COLUMN_NAME is the name of the column and must match the schema

Example:

type MyObj struct {
	Name string `ovsdb:"name"`
}

func NewMapper

func NewMapper(schema ovsdb.DatabaseSchema) Mapper

NewMapper returns a new mapper

func (Mapper) EqualFields

func (m Mapper) EqualFields(one, other *Info, fields ...interface{}) (bool, error)

EqualFields compares two mapped objects. The indexes to use for comparison are, the _uuid, the table indexes and the columns that correspond to the mapped fields pointed to by 'fields'. They must be pointers to fields on the first mapped element (i.e: one)

func (Mapper) GetRowData

func (m Mapper) GetRowData(row *ovsdb.Row, result *Info) error

GetRowData transforms a Row to a struct based on its tags The result object must be given as pointer to an object with the right tags

func (Mapper) NewCondition

func (m Mapper) NewCondition(data *Info, field interface{}, function ovsdb.ConditionFunction, value interface{}) (*ovsdb.Condition, error)

NewCondition returns a ovsdb.Condition based on the model

func (Mapper) NewEqualityCondition

func (m Mapper) NewEqualityCondition(data *Info, fields ...interface{}) ([]ovsdb.Condition, error)

NewEqualityCondition returns a list of equality conditions that match a given object A list of valid columns that shall be used as a index can be provided. If none are provided, we will try to use object's field that matches the '_uuid' ovsdb tag If it does not exist or is null (""), then we will traverse all of the table indexes and use the first index (list of simultaneously unique columns) for which the provided mapper object has valid data. The order in which they are traversed matches the order defined in the schema. By `valid data` we mean non-default data.

func (Mapper) NewMutation

func (m Mapper) NewMutation(data *Info, column string, mutator ovsdb.Mutator, value interface{}) (*ovsdb.Mutation, error)

NewMutation creates a RFC7047 mutation object based on an ORM object and the mutation fields (in native format) It takes care of field validation against the column type

func (Mapper) NewRow

func (m Mapper) NewRow(data *Info, fields ...interface{}) (ovsdb.Row, error)

NewRow transforms an orm struct to a map[string] interface{} that can be used as libovsdb.Row By default, default or null values are skipped. This behavior can be modified by specifying a list of fields (pointers to fields in the struct) to be added to the row

type Metadata

type Metadata struct {
	Fields      map[string]string  // Map of ColumnName -> FieldName
	TableSchema *ovsdb.TableSchema // TableSchema associated
	TableName   string             // Table name
}

Metadata represents the information needed to know how to map OVSDB columns into an objetss fields

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL