Documentation ¶
Index ¶
- Constants
- Variables
- func CurrentTime(value interface{}, op FieldOperation) (interface{}, error)
- func CurrentTimeIfUnset(value interface{}, op FieldOperation) (interface{}, error)
- func GenerateUUID(value interface{}, _ FieldOperation) (interface{}, error)
- func GetIdentityFieldName(instance interface{}, fallbackIdentityFieldName string) (string, error)
- func IsCollectionNotFoundErr(err error) bool
- func IsExistError(err error) bool
- func IsFieldNotFoundErr(err error) bool
- func IsNotExistError(err error) bool
- func TrimSpace(value interface{}, _ FieldOperation) (interface{}, error)
- func ValidateNonZero(value interface{}) error
- func ValidateNotEmpty(value interface{}) error
- func ValidatePositiveInteger(value interface{}) error
- func ValidatePositiveOrZeroInteger(value interface{}) error
- type Collection
- func (self *Collection) AddFields(fields ...Field) *Collection
- func (self *Collection) ApplyDefinition(definition *Collection) error
- func (self *Collection) ConvertValue(name string, value interface{}) interface{}
- func (self *Collection) Diff(actual *Collection) []SchemaDelta
- func (self *Collection) FillDefaults(record *Record)
- func (self *Collection) GetAggregatorName() string
- func (self *Collection) GetField(name string) (Field, bool)
- func (self *Collection) GetFirstNonIdentityKeyField() (Field, bool)
- func (self *Collection) GetIdentityFieldName() string
- func (self *Collection) GetIndexName() string
- func (self *Collection) HasRecordType() bool
- func (self *Collection) IsExpired(record *Record) bool
- func (self *Collection) IsIdentityField(name string) bool
- func (self *Collection) IsKeyField(name string) bool
- func (self *Collection) KeyCount() int
- func (self *Collection) MakeRecord(in interface{}, ops ...FieldOperation) (*Record, error)
- func (self *Collection) MapFromRecord(record *Record, fields ...string) (map[string]interface{}, error)
- func (self *Collection) NewInstance(initializers ...InitializerFunc) interface{}
- func (self *Collection) SetIdentity(name string, idtype Type, formatter FieldFormatterFunc, ...) *Collection
- func (self *Collection) SetRecordType(in interface{}) *Collection
- func (self *Collection) TTL(record *Record) time.Duration
- func (self *Collection) ValidateRecord(record *Record, op FieldOperation) error
- func (self *Collection) ValueForField(name string, value interface{}, op FieldOperation) (interface{}, error)
- type CollectionAction
- type CollectionValidatorFunc
- type ConnectionString
- func (self *ConnectionString) Backend() string
- func (self *ConnectionString) ClearOpt(key string)
- func (self *ConnectionString) Credentials() (string, string, bool)
- func (self *ConnectionString) Dataset() string
- func (self *ConnectionString) HasOpt(key string) bool
- func (self *ConnectionString) Host(defaults ...string) string
- func (self *ConnectionString) LoadCredentialsFromNetrc(filename string) error
- func (self *ConnectionString) OptBool(key string, fallback bool) bool
- func (self *ConnectionString) OptDuration(key string, fallback time.Duration) time.Duration
- func (self *ConnectionString) OptFloat(key string, fallback float64) float64
- func (self *ConnectionString) OptInt(key string, fallback int64) int64
- func (self *ConnectionString) OptString(key string, fallback string) string
- func (self *ConnectionString) OptTime(key string, fallback time.Time) time.Time
- func (self *ConnectionString) Protocol(defaults ...string) string
- func (self *ConnectionString) Scheme() (string, string)
- func (self *ConnectionString) SetCredentials(username string, password string)
- func (self *ConnectionString) String() string
- type DeltaIssue
- type DeltaType
- type EncoderFunc
- type Field
- func (self *Field) ConvertValue(in interface{}) (interface{}, error)
- func (self *Field) Diff(other *Field) []SchemaDelta
- func (self *Field) Format(value interface{}, op FieldOperation) (interface{}, error)
- func (self *Field) GetDefaultValue() interface{}
- func (self *Field) GetTypeInstance() interface{}
- func (self *Field) MarshalJSON() ([]byte, error)
- func (self *Field) UnmarshalJSON(b []byte) error
- func (self *Field) Validate(value interface{}) error
- type FieldFormatterFunc
- func ChangeCase(cases ...string) FieldFormatterFunc
- func DeriveFromFields(format string, fields ...string) FieldFormatterFunc
- func FormatAll(formatters ...FieldFormatterFunc) FieldFormatterFunc
- func FormatterFromMap(in map[string]interface{}) (FieldFormatterFunc, error)
- func GenerateEncodedUUID(encoder EncoderFunc) FieldFormatterFunc
- func GetFormatter(name string, args interface{}) (FieldFormatterFunc, error)
- func NowPlusDuration(duration time.Duration) FieldFormatterFunc
- func Replace(pairs []interface{}) FieldFormatterFunc
- type FieldOperation
- type FieldValidatorFunc
- type InitializerFunc
- type Instantiator
- type Model
- type Record
- func (self *Record) Append(key string, value ...interface{}) *Record
- func (self *Record) AppendNested(key string, value ...interface{}) *Record
- func (self *Record) Copy(other *Record)
- func (self *Record) Get(key string, fallback ...interface{}) interface{}
- func (self *Record) GetNested(key string, fallback ...interface{}) interface{}
- func (self *Record) GetString(key string, fallback ...string) string
- func (self *Record) Keys(collection *Collection) []interface{}
- func (self *Record) Populate(into interface{}, collection *Collection) error
- func (self *Record) Set(key string, value interface{}) *Record
- func (self *Record) SetData(data []byte) *Record
- func (self *Record) SetFields(values map[string]interface{}) *Record
- func (self *Record) SetKeys(collection *Collection, op FieldOperation, keys ...interface{}) error
- func (self *Record) SetNested(key string, value interface{}) *Record
- func (self *Record) String() string
- type RecordSet
- func (self *RecordSet) Append(other *RecordSet) *RecordSet
- func (self *RecordSet) GetRecord(index int) (*Record, bool)
- func (self *RecordSet) IsEmpty() bool
- func (self *RecordSet) Pluck(field string, fallback ...interface{}) []interface{}
- func (self *RecordSet) PopulateFromRecords(into interface{}, schema *Collection) error
- func (self *RecordSet) Push(record *Record) *RecordSet
- type Relationship
- type SchemaDelta
- type Type
Constants ¶
const ( StringType Type = `str` AutoType = `auto` BooleanType = `bool` IntType = `int` FloatType = `float` TimeType = `time` ObjectType = `object` RawType = `raw` )
Variables ¶
var Base32Encoder = func(src []byte) (string, error) { return strings.TrimSuffix(base32.StdEncoding.EncodeToString(src), `=`), nil }
var Base58Encoder = func(src []byte) (string, error) { return base58.Encode(src), nil }
var Base64Encoder = func(src []byte) (string, error) { return strings.TrimSuffix(base64.StdEncoding.EncodeToString(src), `=`), nil }
var CollectionNotFound = errors.New(`Collection not found`)
var DefaultIdentityField = `id`
var DefaultStructIdentityFieldName = `ID`
var FieldNestingSeparator string = `.`
var FieldNotFound = errors.New(`Field not found`)
var HexEncoder = func(src []byte) (string, error) { return hex.EncodeToString(src), nil }
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 IsCollectionNotFoundErr ¶
func IsExistError ¶
func IsFieldNotFoundErr ¶ added in v3.0.11
func IsNotExistError ¶
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) 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 ConnectionString ¶
func MakeConnectionString ¶
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 (*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) 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 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 (*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 (*Field) UnmarshalJSON ¶
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 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 NewRecordErr ¶
func (*Record) AppendNested ¶
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) SetKeys ¶ added in v3.0.11
func (self *Record) SetKeys(collection *Collection, op FieldOperation, keys ...interface{}) error
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 (*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.
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