dal

package
v3.0.26 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2018 License: LGPL-2.1 Imports: 22 Imported by: 9

Documentation

Index

Constants

View Source
const (
	StringType  Type = `str`
	AutoType         = `auto`
	BooleanType      = `bool`
	IntType          = `int`
	FloatType        = `float`
	TimeType         = `time`
	ObjectType       = `object`
	RawType          = `raw`
)

Variables

View Source
var Base32Encoder = func(src []byte) (string, error) {
	return strings.TrimSuffix(base32.StdEncoding.EncodeToString(src), `=`), nil
}
View Source
var Base58Encoder = func(src []byte) (string, error) {
	return base58.Encode(src), nil
}
View Source
var Base64Encoder = func(src []byte) (string, error) {
	return strings.TrimSuffix(base64.StdEncoding.EncodeToString(src), `=`), nil
}
View Source
var CollectionNotFound = errors.New(`Collection not found`)
View Source
var DefaultIdentityField = `id`
View Source
var DefaultStructIdentityFieldName = `ID`
View Source
var FieldNestingSeparator string = `.`
View Source
var FieldNotFound = errors.New(`Field not found`)
View Source
var HexEncoder = func(src []byte) (string, error) {
	return hex.EncodeToString(src), nil
}
View Source
var RecordStructTag = `pivot`

Functions

func CurrentTime

func CurrentTime(value interface{}, op FieldOperation) (interface{}, error)

func CurrentTimeIfUnset

func CurrentTimeIfUnset(value interface{}, op FieldOperation) (interface{}, error)

func GenerateUUID

func GenerateUUID(value interface{}, _ FieldOperation) (interface{}, error)

func GetIdentityFieldName

func GetIdentityFieldName(instance interface{}, fallbackIdentityFieldName string) (string, error)

func IsCollectionNotFoundErr

func IsCollectionNotFoundErr(err error) bool

func IsExistError

func IsExistError(err error) bool

func IsFieldNotFoundErr added in v3.0.11

func IsFieldNotFoundErr(err error) bool

func IsNotExistError

func IsNotExistError(err error) bool

func TrimSpace

func TrimSpace(value interface{}, _ FieldOperation) (interface{}, error)

func ValidateNonZero

func ValidateNonZero(value interface{}) error

func ValidateNotEmpty

func ValidateNotEmpty(value interface{}) error

func ValidatePositiveInteger

func ValidatePositiveInteger(value interface{}) error

func ValidatePositiveOrZeroInteger

func ValidatePositiveOrZeroInteger(value interface{}) error

Types

type Collection

type Collection struct {
	Name                        string                  `json:"name"`
	IndexName                   string                  `json:"index_name,omitempty"`
	IndexCompoundFields         []string                `json:"index_compound_fields,omitempty"`
	IndexCompoundFieldJoiner    string                  `json:"index_compound_field_joiner,omitempty"`
	SkipIndexPersistence        bool                    `json:"skip_index_persistence,omitempty"`
	Fields                      []Field                 `json:"fields"`
	IdentityField               string                  `json:"identity_field,omitempty"`
	IdentityFieldType           Type                    `json:"identity_field_type,omitempty"`
	EmbeddedCollections         []Relationship          `json:"embed,omitempty"`
	ExportedFields              []string                `json:"export,omitempty"`
	AllowMissingEmbeddedRecords bool                    `json:"allow_missing_embedded_records"`
	TotalRecords                int64                   `json:"total_records,omitempty"`
	TotalRecordsExact           bool                    `json:"total_records_exact,omitempty"`
	TimeToLiveField             string                  `json:"time_to_live_field"`
	IdentityFieldFormatter      FieldFormatterFunc      `json:"-"`
	IdentityFieldValidator      FieldValidatorFunc      `json:"-"`
	PreSaveValidator            CollectionValidatorFunc `json:"-"`
	// contains filtered or unexported fields
}

func NewCollection

func NewCollection(name string) *Collection

func (*Collection) AddFields

func (self *Collection) AddFields(fields ...Field) *Collection

func (*Collection) ApplyDefinition

func (self *Collection) ApplyDefinition(definition *Collection) error

Copies certain collection and field properties from the definition object into this collection instance. This is useful for collections that are created by parsing the schema as it exists on the remote datastore, which will have some but not all of the information we need to work with the data. Definition collections are the authoritative source for things like what the default value should be, and which validators and formatters apply to a given field.

This function converts this instance into a Collection definition by copying the relevant values from given definition.

func (*Collection) ConvertValue

func (self *Collection) ConvertValue(name string, value interface{}) interface{}

func (*Collection) Diff

func (self *Collection) Diff(actual *Collection) []SchemaDelta

func (*Collection) FillDefaults

func (self *Collection) FillDefaults(record *Record)

func (*Collection) GetAggregatorName

func (self *Collection) GetAggregatorName() string

func (*Collection) GetField

func (self *Collection) GetField(name string) (Field, bool)

func (*Collection) GetFirstNonIdentityKeyField

func (self *Collection) GetFirstNonIdentityKeyField() (Field, bool)

func (*Collection) GetIdentityFieldName

func (self *Collection) GetIdentityFieldName() string

func (*Collection) GetIndexName

func (self *Collection) GetIndexName() string

func (*Collection) HasRecordType

func (self *Collection) HasRecordType() bool

func (*Collection) IsExpired added in v3.0.8

func (self *Collection) IsExpired(record *Record) bool

Expired records are those whose TTL duration is non-zero and negative.

func (*Collection) IsIdentityField

func (self *Collection) IsIdentityField(name string) bool

func (*Collection) IsKeyField

func (self *Collection) IsKeyField(name string) bool

func (*Collection) KeyCount added in v3.0.9

func (self *Collection) KeyCount() int

func (*Collection) MakeRecord

func (self *Collection) MakeRecord(in interface{}, ops ...FieldOperation) (*Record, error)

Generates a Record instance from the given value based on this collection's schema.

func (*Collection) MapFromRecord

func (self *Collection) MapFromRecord(record *Record, fields ...string) (map[string]interface{}, error)

func (*Collection) NewInstance

func (self *Collection) NewInstance(initializers ...InitializerFunc) interface{}

func (*Collection) SetIdentity

func (self *Collection) SetIdentity(name string, idtype Type, formatter FieldFormatterFunc, validator FieldValidatorFunc) *Collection

func (*Collection) SetRecordType

func (self *Collection) SetRecordType(in interface{}) *Collection

func (*Collection) TTL added in v3.0.8

func (self *Collection) TTL(record *Record) time.Duration

Return the duration until the TimeToLiveField in given record expires within the current collection. Collections with an empty TimeToLiveField, or records with a missing or zero-valued TimeToLiveField will return 0. If the record has already expired, the returned duration will be a negative number.

func (*Collection) ValidateRecord

func (self *Collection) ValidateRecord(record *Record, op FieldOperation) error

func (*Collection) ValueForField added in v3.0.11

func (self *Collection) ValueForField(name string, value interface{}, op FieldOperation) (interface{}, error)

type CollectionAction

type CollectionAction int
const (
	SchemaVerify CollectionAction = iota
	SchemaCreate
	SchemaExpand
	SchemaRemove
	SchemaEnforce
)

type CollectionValidatorFunc

type CollectionValidatorFunc func(*Record) error

type ConnectionString

type ConnectionString struct {
	URI     *url.URL
	Options map[string]interface{}
}

func MakeConnectionString

func MakeConnectionString(scheme string, host string, dataset string, options map[string]interface{}) (ConnectionString, error)

func ParseConnectionString

func ParseConnectionString(conn string) (ConnectionString, error)

func (*ConnectionString) Backend

func (self *ConnectionString) Backend() string

Returns the backend component of the string.

func (*ConnectionString) ClearOpt added in v3.0.15

func (self *ConnectionString) ClearOpt(key string)

func (*ConnectionString) Credentials

func (self *ConnectionString) Credentials() (string, string, bool)

Return the credentials (if any) associated with this string, and whether they were present or not.

func (*ConnectionString) Dataset

func (self *ConnectionString) Dataset() string

Returns the dataset component of the string.

func (*ConnectionString) HasOpt

func (self *ConnectionString) HasOpt(key string) bool

func (*ConnectionString) Host

func (self *ConnectionString) Host(defaults ...string) string

Returns the host component of the string.

func (*ConnectionString) LoadCredentialsFromNetrc

func (self *ConnectionString) LoadCredentialsFromNetrc(filename string) error

Reads a .netrc-style file and loads the appropriate credentials. The host component of this connection string is matched with the netrc "machine" field.

func (*ConnectionString) OptBool

func (self *ConnectionString) OptBool(key string, fallback bool) bool

func (*ConnectionString) OptDuration

func (self *ConnectionString) OptDuration(key string, fallback time.Duration) time.Duration

func (*ConnectionString) OptFloat

func (self *ConnectionString) OptFloat(key string, fallback float64) float64

func (*ConnectionString) OptInt

func (self *ConnectionString) OptInt(key string, fallback int64) int64

func (*ConnectionString) OptString

func (self *ConnectionString) OptString(key string, fallback string) string

func (*ConnectionString) OptTime

func (self *ConnectionString) OptTime(key string, fallback time.Time) time.Time

func (*ConnectionString) Protocol

func (self *ConnectionString) Protocol(defaults ...string) string

Returns the protocol component of the string.

func (*ConnectionString) Scheme

func (self *ConnectionString) Scheme() (string, string)

Returns the backend and protocol components of the string.

func (*ConnectionString) SetCredentials

func (self *ConnectionString) SetCredentials(username string, password string)

Explicitly set username and password on this connection string

func (*ConnectionString) String

func (self *ConnectionString) String() string

type DeltaIssue

type DeltaIssue int
const (
	UnknownIssue DeltaIssue = iota
	CollectionNameIssue
	CollectionKeyNameIssue
	CollectionKeyTypeIssue
	FieldMissingIssue
	FieldNameIssue
	FieldLengthIssue
	FieldTypeIssue
	FieldPropertyIssue
)

type DeltaType

type DeltaType string
const (
	CollectionDelta DeltaType = `collection`
	FieldDelta                = `field`
)

type EncoderFunc

type EncoderFunc func([]byte) (string, error) //{}

type Field

type Field struct {
	Name               string                 `json:"name"`
	Description        string                 `json:"description,omitempty"`
	Type               Type                   `json:"type"`
	KeyType            Type                   `json:"keytype,omitempty"`
	Subtype            Type                   `json:"subtype,omitempty"`
	Length             int                    `json:"length,omitempty"`
	Precision          int                    `json:"precision,omitempty"`
	Identity           bool                   `json:"identity,omitempty"`
	Key                bool                   `json:"key,omitempty"`
	Required           bool                   `json:"required,omitempty"`
	Unique             bool                   `json:"unique,omitempty"`
	DefaultValue       interface{}            `json:"default,omitempty"`
	NativeType         string                 `json:"native_type,omitempty"`
	NotUserEditable    bool                   `json:"not_user_editable"`
	ValidateOnPopulate bool                   `json:"validate_on_populate,omitempty"`
	Validator          FieldValidatorFunc     `json:"-"`
	Formatter          FieldFormatterFunc     `json:"-"`
	FormatterConfig    map[string]interface{} `json:"formatters,omitempty"`
	ValidatorConfig    map[string]interface{} `json:"validators,omitempty"`
}

func (*Field) ConvertValue

func (self *Field) ConvertValue(in interface{}) (interface{}, error)

func (*Field) Diff

func (self *Field) Diff(other *Field) []SchemaDelta

func (*Field) Format

func (self *Field) Format(value interface{}, op FieldOperation) (interface{}, error)

func (*Field) GetDefaultValue

func (self *Field) GetDefaultValue() interface{}

func (*Field) GetTypeInstance

func (self *Field) GetTypeInstance() interface{}

func (*Field) MarshalJSON

func (self *Field) MarshalJSON() ([]byte, error)

func (*Field) UnmarshalJSON

func (self *Field) UnmarshalJSON(b []byte) error

func (*Field) Validate

func (self *Field) Validate(value interface{}) error

type FieldFormatterFunc

type FieldFormatterFunc func(interface{}, FieldOperation) (interface{}, error)

func ChangeCase

func ChangeCase(cases ...string) FieldFormatterFunc

func DeriveFromFields

func DeriveFromFields(format string, fields ...string) FieldFormatterFunc

func FormatAll

func FormatAll(formatters ...FieldFormatterFunc) FieldFormatterFunc

func FormatterFromMap

func FormatterFromMap(in map[string]interface{}) (FieldFormatterFunc, error)

func GenerateEncodedUUID

func GenerateEncodedUUID(encoder EncoderFunc) FieldFormatterFunc

func GetFormatter

func GetFormatter(name string, args interface{}) (FieldFormatterFunc, error)

func NowPlusDuration added in v3.0.8

func NowPlusDuration(duration time.Duration) FieldFormatterFunc

func Replace

func Replace(pairs []interface{}) FieldFormatterFunc

type FieldOperation

type FieldOperation int
const (
	PersistOperation FieldOperation = iota
	RetrieveOperation
)

type FieldValidatorFunc

type FieldValidatorFunc func(interface{}) error

func GetValidator

func GetValidator(name string, args interface{}) (FieldValidatorFunc, error)

func ValidateAll

func ValidateAll(validators ...FieldValidatorFunc) FieldValidatorFunc

func ValidateIsOneOf

func ValidateIsOneOf(choices ...interface{}) FieldValidatorFunc

func ValidatorFromMap

func ValidatorFromMap(in map[string]interface{}) (FieldValidatorFunc, error)

type InitializerFunc

type InitializerFunc func(interface{}) interface{} // {}

Used by consumers Collection.NewInstance that wish to modify the instance before returning it

type Instantiator

type Instantiator interface {
	Constructor() interface{}
}

type Model

type Model interface{}

type Record

type Record struct {
	ID     interface{}            `json:"id"`
	Fields map[string]interface{} `json:"fields,omitempty"`
	Data   []byte                 `json:"data,omitempty"`
	Error  error                  `json:"error,omitempty"`
}

func NewRecord

func NewRecord(id interface{}) *Record

func NewRecordErr

func NewRecordErr(id interface{}, err error) *Record

func (*Record) Append

func (self *Record) Append(key string, value ...interface{}) *Record

func (*Record) AppendNested

func (self *Record) AppendNested(key string, value ...interface{}) *Record

func (*Record) Copy

func (self *Record) Copy(other *Record)

func (*Record) Get

func (self *Record) Get(key string, fallback ...interface{}) interface{}

func (*Record) GetNested

func (self *Record) GetNested(key string, fallback ...interface{}) interface{}

func (*Record) GetString

func (self *Record) GetString(key string, fallback ...string) string

func (*Record) Keys added in v3.0.11

func (self *Record) Keys(collection *Collection) []interface{}

func (*Record) Populate

func (self *Record) Populate(into interface{}, collection *Collection) error

Populates a given struct with with the values in this record.

func (*Record) Set

func (self *Record) Set(key string, value interface{}) *Record

func (*Record) SetData

func (self *Record) SetData(data []byte) *Record

func (*Record) SetFields

func (self *Record) SetFields(values map[string]interface{}) *Record

func (*Record) SetKeys added in v3.0.11

func (self *Record) SetKeys(collection *Collection, op FieldOperation, keys ...interface{}) error

func (*Record) SetNested

func (self *Record) SetNested(key string, value interface{}) *Record

func (*Record) String

func (self *Record) String() string

type RecordSet

type RecordSet struct {
	ResultCount    int64                  `json:"result_count"`
	Page           int                    `json:"page,omitempty"`
	TotalPages     int                    `json:"total_pages,omitempty"`
	RecordsPerPage int                    `json:"records_per_page,omitempty"`
	Records        []*Record              `json:"records"`
	Options        map[string]interface{} `json:"options"`
	KnownSize      bool                   `json:"known_size"`
}

func NewRecordSet

func NewRecordSet(records ...*Record) *RecordSet

func (*RecordSet) Append

func (self *RecordSet) Append(other *RecordSet) *RecordSet

func (*RecordSet) GetRecord

func (self *RecordSet) GetRecord(index int) (*Record, bool)

func (*RecordSet) IsEmpty

func (self *RecordSet) IsEmpty() bool

func (*RecordSet) Pluck

func (self *RecordSet) Pluck(field string, fallback ...interface{}) []interface{}

func (*RecordSet) PopulateFromRecords

func (self *RecordSet) PopulateFromRecords(into interface{}, schema *Collection) error

Takes a slice of structs or maps and fills it with instances populated by the records in this RecordSet in accordance with the types specified in the given collection definition, as well as which fields are available in the given struct.

func (*RecordSet) Push

func (self *RecordSet) Push(record *Record) *RecordSet

type Relationship

type Relationship struct {
	Keys           interface{} `json:"key"`
	Collection     *Collection `json:"-"`
	CollectionName string      `json:"collection,omitempty"`
	Fields         []string    `json:"fields,omitempty"`
}

type SchemaDelta

type SchemaDelta struct {
	Type       DeltaType
	Issue      DeltaIssue
	Message    string
	Collection string
	Name       string
	Parameter  string
	Desired    interface{}
	Actual     interface{}
}

func (SchemaDelta) String

func (self SchemaDelta) String() string

type Type

type Type string
var DefaultIdentityFieldType Type = IntType

func ParseFieldType

func ParseFieldType(in string) Type

func (Type) String

func (self Type) String() string

Jump to

Keyboard shortcuts

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