dal

package
v4.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: LGPL-2.1 Imports: 22 Imported by: 0

Documentation

Index

Constants

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

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 DefaultFieldCodec = `json`
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 IntIsProbablyUnixEpochSeconds int64 = 4294967296
View Source
var RecordStructTag = util.RecordStructTag

Functions

func AddConnectionSchemeAlias

func AddConnectionSchemeAlias(from string, to string)

func CurrentTime

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

Returns the current time every time the field is persisted.

func CurrentTimeIfUnset

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

Returns the current time when the field is persisted if the current value is empty.

func GenerateUUID

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

Generates a V4 UUID value if the existing value is empty.

func IsCollectionNotFoundErr

func IsCollectionNotFoundErr(err error) bool

func IsExistError

func IsExistError(err error) bool

func IsFieldNotFoundErr

func IsFieldNotFoundErr(err error) bool

func IsNotExistError

func IsNotExistError(err error) bool

func ShouldCreateCollection

func ShouldCreateCollection(collection *Collection, errs ...error) bool

Takes a collection definition and any errors encountered while retrieving it, and determines whether a CreateCollection() call should be made.

func TrimSpace

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

func ValidateIsURL

func ValidateIsURL(value interface{}) error

Validate that the value is a URL with a non-empty scheme and host component.

func ValidateNonZero

func ValidateNonZero(value interface{}) error

Validate that the given value is not a zero value (false, 0, 0.0, "", null).

func ValidateNotEmpty

func ValidateNotEmpty(value interface{}) error

Validate that the given value is not a zero value, and if it's a string, that the string does not contain only whitespace.

func ValidatePositiveInteger

func ValidatePositiveInteger(value interface{}) error

Validate that the given value is an integer > 0.

func ValidatePositiveOrZeroInteger

func ValidatePositiveOrZeroInteger(value interface{}) error

Validate that the given value is an integer >= 0.

Types

type Backend

type Backend interface {
	GetCollection(collection string) (*Collection, error)
}

type Collection

type Collection struct {
	// The name of the collection
	Name string `json:"name"`

	// The name of the associated external inverted index used to query this collection.
	IndexName string `json:"index_name,omitempty"`

	// Lists the field names that make up a composite key on this Collection that should be joined
	// together when determining index record IDs.  Often it is the case that external indices do
	// not support composite keys the way databases do, so this allows Collections with composite
	// keys to be indexed in those systems by joining several values together to form a unique key.
	IndexCompoundFields []string `json:"index_compound_fields,omitempty"`

	// The string used to join and split ID values that go into / come out of external indices.
	IndexCompoundFieldJoiner string `json:"index_compound_field_joiner,omitempty"`

	// Disable automatically dual-writing modified records into the external index.
	SkipIndexPersistence bool `json:"skip_index_persistence,omitempty"`

	// The fields that belong to this collection (all except the primary key/identity field/first
	// field in a composite key)
	Fields []Field `json:"fields"`

	// The name of the identity field for this Collection.  Defaults to "id".
	IdentityField string `json:"identity_field,omitempty"`

	// The datatype of the identity field.  Defaults to integer.
	IdentityFieldType Type `json:"identity_field_type,omitempty"`

	// Used to store the location of the identity field in the source database.
	IdentityFieldIndex int `json:"identity_field_index"`

	// Specifies how fields in this Collection relate to records from other collections.  This is
	// a partial implementation of a relational model, specifically capturing one-to-one or
	// one-to-many relationships.  The definitions here will retrieve the associated records from
	// another, and those values will replace the value that is actually in this Collection's field.
	EmbeddedCollections []Relationship `json:"embed,omitempty"`

	// Allows for constraints to be applied to a collection.  In addition to informing Pivot about the
	// relationships between collections, this data is also used to enforce referential integrity for
	// backends that support such guarantees (e.g.: ACID-compliant RDBMS').
	Constraints []Constraint `json:"constraints,omitempty"`

	// Specifies which fields can be seen when records are from relationships defined on other
	// Collections.  This can be used to restrict the exposure) of sensitive data in this Collection
	// be being an embedded field in another Collection.
	ExportedFields []string `json:"export,omitempty"`

	// Specify whether missing related fields generate an error when retrieving a record.
	AllowMissingEmbeddedRecords bool `json:"allow_missing_embedded_records"`

	// A read-only count of the number of records in this Collection
	TotalRecords int64 `json:"total_records,omitempty"`

	// Whether the value of TotalRecords represents an exact (authoritative) count or an
	// approximate count.
	TotalRecordsExact bool `json:"total_records_exact,omitempty"`

	// The name of a field containing an absolute datetime after which expired records should be
	// deleted from this Collection.
	TimeToLiveField string `json:"time_to_live_field"`

	// A function that modifies the identity key value before any operation.  Operates the same as
	// a Field Formatter function.
	IdentityFieldFormatter FieldFormatterFunc `json:"-"`

	// Specifies that IDs should be automatically generated using a formatter function
	AutoIdentity string `json:"autoidentity"`

	// A function that validates the value of an identity key before create and update operations.
	// Operates the same as a Field Validator function.
	IdentityFieldValidator FieldValidatorFunc `json:"-"`

	// Allow backends to store internal information about the backing datasource for this collection.
	SourceURI string `json:"-"`

	// If specified, this function receives a copy of the populated record before create and update
	// operations, allowing for a last-chance validation of the record as a whole.  Use a pre-save
	// validator when validation requires checking multiple fields at once.
	PreSaveValidator CollectionValidatorFunc `json:"-"`

	// Specifies that this collection is a read-only view on data that is queried by the underlying database engine.
	View bool `json:"view,omitempty"`

	// Specify additional keywords in the view creation to modify how it is created.
	ViewKeywords string `json:"view_keywords,omitempty"`

	// A query object that is passed to the underlying database engine.
	ViewQuery interface{} `json:"view_query,omitempty"`

	// Specifies that creating this collection on the backend should always be attempted.
	AlwaysCreate bool `json:"create,omitempty"`
	// contains filtered or unexported fields
}

func NewCollection

func NewCollection(name string, fields ...Field) *Collection

Create a new colllection definition with no fields.

func (*Collection) AddFields

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

Append a field definition to this 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) Check

func (self *Collection) Check() error

Verifies that the schema passes some basic sanity checks.

func (*Collection) ConvertValue

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

Convert a given value according to the data type of a specific named field.

func (*Collection) Diff

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

Determine the differences (if any) between this Collection definition and another.

func (*Collection) EmptyRecord

func (self *Collection) EmptyRecord() *Record

func (*Collection) FillDefaults

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

Populate a given Record with the default values (if any) of all fields in the Collection.

func (*Collection) GetAggregatorName

func (self *Collection) GetAggregatorName() string

Get the canonical name of the dataset in an external aggregator service.

func (*Collection) GetAllConstraints

func (self *Collection) GetAllConstraints() (constraints []Constraint)

Retrieve the set of all Constraints on this collection, both explicitly provided via the Constraints field, as well as constraints specified using the "BelongsTo" shorthand on Fields.

func (*Collection) GetField

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

Retrieve a single field by name. The second return value will be false if the field does not exist.

func (*Collection) GetFieldByIndex

func (self *Collection) GetFieldByIndex(index int) (Field, bool)

Retrieve a single field by its index value. The second return value will be false if a field at that index does not exist.

func (*Collection) GetFirstNonIdentityKeyField

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

Retrieve the first non-indentity key field, sometimes referred to as the "range", "sort", or "cluster" key.

func (*Collection) GetIdentityFieldName

func (self *Collection) GetIdentityFieldName() string

Get the canonical name of the primary identity field.

func (*Collection) GetIndexName

func (self *Collection) GetIndexName() string

Get the canonical name of the external index name.

func (*Collection) GetRelatedCollection

func (self *Collection) GetRelatedCollection(name string) (*Collection, error)

Retrieves a Collection by name from the backend this Collection is registered to.

func (*Collection) HasRecordType

func (self *Collection) HasRecordType() bool

func (*Collection) IsExpired

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

TODO: what is this?

func (*Collection) IsKeyField

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

Return whether a given field name is a key on this Collection.

func (*Collection) KeyCount

func (self *Collection) KeyCount() int

Return the number of keys on that uniquely identify a single record in this Collection.

func (*Collection) KeyFieldNames

func (self *Collection) KeyFieldNames() (names []string)

Same as KeyFields, but returns only the field names

func (*Collection) KeyFields

func (self *Collection) KeyFields() []Field

Retrieve all of the fields that comprise the primary key for this Collection. This will always include the identity field at a minimum.

func (*Collection) MakeRecord deprecated

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

Deprecated: use StructToRecord instead

func (*Collection) MapFromRecord

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

Convert the given record into a map.

func (*Collection) SetBackend

func (self *Collection) SetBackend(backend Backend)

Set the backend for this collection. The Backend interface in this package is a limited subset of the backends.Backend interface that avoids a circular dependency between the two packages. The intent is to allow Collections to retrieve details about other collections registered on the same backend.

func (*Collection) SetIdentity

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

Configure the identity field of a collection in a single function call.

func (*Collection) SetRecordType deprecated

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

Deprecated: this functionality has been removed.

func (*Collection) StructToRecord

func (self *Collection) StructToRecord(in interface{}) (*Record, error)

Generates a Record suitable for persistence in a backend from the given struct.

func (*Collection) TTL

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

Validate the given record against all Field and Collection validators.

func (*Collection) ValueForField

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

Convert a given value into one that that can go into the backend database (for create/update operations), or that should be returned to the user (for retrieval operations) in accordance with the named field's data type and formatters. Invalid values (determined by Validators and the Required option in the Field) will return an 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 MustParseConnectionString

func MustParseConnectionString(conn string) ConnectionString

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

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) Opt

func (self *ConnectionString) Opt(key string) typeutil.Variant

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 Constraint

type Constraint struct {
	// Represents the name (or array of names) of the local field the constraint is being applied to.
	On interface{} `json:"on"`

	// The remote collection the constraint applies to.
	Collection string `json:"collection"`

	// The remote field (or fields) in the remote collection the constraint applies to.
	Field interface{} `json:"field"`

	// Provides backend-specific additional options for the constraint.
	Options string `json:"options,omitempty"`

	// Specifies the local field that related records will be put into.  Defaults to the field specified in On.
	Into string `json:"into,omitempty"`

	// Whether to omit this constraint when determining embedded collections.
	NoEmbed bool `json:"noembed,omitempty"`
}

func (Constraint) Equal

func (self Constraint) Equal(other *Constraint) bool

func (Constraint) Validate

func (self Constraint) Validate() error

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 {
	// The name of the field
	Name string `json:"name"`

	// A description of the field used in help text
	Description string `json:"description,omitempty"`

	// The data type of the field
	Type Type `json:"type"`

	// For complex field types (tuples, objects); the data type of the key portion
	KeyType Type `json:"keytype,omitempty"`

	// For complex field types (arrays, sets, lists); the data type of the contained values
	Subtype Type `json:"subtype,omitempty"`

	// The length constraint for values in the field (where supported)
	Length int `json:"length,omitempty"`

	// The precision of stored values in the field (where supported)
	Precision int `json:"precision,omitempty"`

	// Whether the field is an identity field (don't use this, configure the identity on the
	// Collection instead)
	Identity bool `json:"identity,omitempty"`

	// Whether the field is a key field in a composite key Collection
	Key bool `json:"key,omitempty"`

	// Whether the field can store a null/empty value
	Required bool `json:"required,omitempty"`

	// Enforces that the field value must be unique across the entire Collection (where supported)
	Unique bool `json:"unique,omitempty"`

	// The name of a group of unique fields that, taken together, must be unique across the entire
	// Collection (where supported)
	UniqueGroup string `json:"unique_group,omitempty"`

	// The default value of the field is one is not explicitly specified.  Can be any type or a
	// function that takes zero arguments and returns a single value.
	DefaultValue interface{} `json:"default,omitempty"`

	// Represents the native datatype of the underlying Backend object (read only)
	NativeType string `json:"native_type,omitempty"`

	// Specify that the field should not be modified.  This is not enforced in Pivot, but rather
	// serves as a note to applications implementing interactions with the Pivot API.
	NotUserEditable bool `json:"not_user_editable"`

	// Whether this field's validator(s) should be used to validate data being retrieved from the
	// backend.  Invalid data (possibly created outside of Pivot) will cause Retrieve() calls to
	// return a validation error.
	ValidateOnPopulate bool `json:"validate_on_populate,omitempty"`

	// A function that is used to validate the field's value before performing any create, update,
	// and (optionally) retrieval operations.
	Validator FieldValidatorFunc `json:"-"`

	// A function that can modify values before any create or update operations.  Formatters run
	// before Validators, giving users the opportunity to ensure a valid value is in the data
	// structure before validation runs.
	Formatter FieldFormatterFunc `json:"-"`

	// A declarative form of the Validator configuration that uses pre-defined validators. Primarily
	// used when storing schema declarations in external JSON files.
	ValidatorConfig map[string]interface{} `json:"validators,omitempty"`

	// A declarative form of the Formatter configuration that uses pre-defined validators. Primarily
	// used when storing schema declarations in external JSON files.
	FormatterConfig map[string]interface{} `json:"formatters,omitempty"`

	// Used to store the order this field appears in the source database.
	Index int `json:"index,omitempty"`

	// Specify a relationship between this field and another collection.
	//
	// If given a string, it will be interpreted as a collection name and a
	// constaint against that collection's identity field will be created.
	//
	// If given a *Collection, the same behavior as above will occur, but using
	// the Collection.Name from the given struct.
	//
	// If given a Constraint, the constraint will be added to this field's
	// parent collection with the "On" field set to this field's name.
	BelongsTo interface{} `json:"belongs_to,omitempty"`

	// Specifies that the field may not be updated, only read.  Attempts to update the field will be silently discarded.
	ReadOnly bool `json:"readonly,omitempty"`
}

func (*Field) BelongsToConstraint

func (self *Field) BelongsToConstraint() *Constraint

Parses the value of BelongsTo into a valid Constraint

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

Extracts values from the given Record and generates a deterministic output based on those values.

func FormatAll

func FormatAll(formatters ...FieldFormatterFunc) FieldFormatterFunc

func FormatterFromMap

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

func GenerateEncodedUUID

func GenerateEncodedUUID(encoder EncoderFunc) FieldFormatterFunc

Same as GenerateUUID, but allows for a custom representation of the underlying bytes.

func GetFormatter

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

func IfUnset

func IfUnset(onlyIf FieldFormatterFunc) FieldFormatterFunc

Only evaluates the given formatter if the current value of the field is empty.

func NowPlusDuration

func NowPlusDuration(duration time.Duration) FieldFormatterFunc

Returns the current time with an added offset when the field is persisted.

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)

Retrieve a validator by name. Used by the ValidatorConfig configuration on Field.

func ValidateAll

func ValidateAll(validators ...FieldValidatorFunc) FieldValidatorFunc

Validate that all of the given validator functions pass.

func ValidateIsOneOf

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

Validate that the given value is among the given choices.

func ValidateMatchAll

func ValidateMatchAll(patterns ...string) FieldValidatorFunc

Validate that the given value matches all of the given regular expressions.

func ValidateMatchAny

func ValidateMatchAny(patterns ...string) FieldValidatorFunc

Validate that the given value matches at least one of the given regular expressions.

func ValidatorFromMap

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

Retrieve a validator by name. Used by the ValidatorConfig configuration on Field.

type Migratable

type Migratable interface {
	Migrate() error
}

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"`
	CollectionName string                 `json:"collection,omitempty"`
	Operation      string                 `json:"operation,omitempty"`
	Optional       bool                   `json:"optional,omitempty"` // Specifies that the record is "optional", which is namely used in fixtures to indicate that a missing collection should not be considered fatal.
}

func NewRecord

func NewRecord(id interface{}, data ...map[string]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, schema ...*Collection) error

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

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

func (*Record) Map

func (self *Record) Map(fields ...string) map[string]interface{}

func (*Record) OnlyFields

func (self *Record) OnlyFields(fields []string) *Record

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

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) GetRecordByID

func (self *RecordSet) GetRecordByID(id interface{}) (*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"`
	Force          bool        `json:"force,omitempty"`
}

func (*Relationship) RelatedCollectionName

func (self *Relationship) RelatedCollectionName() string

type SchemaDelta

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

func (SchemaDelta) DesiredField

func (self SchemaDelta) DesiredField(from Field) *Field

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