Documentation ¶
Overview ¶
Package schema implements custom Schema and SchemaField datatypes for handling the Collection schema definitions.
Index ¶
- Constants
- func ArraybleFieldTypes() []string
- func AuthFieldNames() []string
- func BaseModelFieldNames() []string
- func FieldTypes() []string
- func SystemFieldNames() []string
- type BoolOptions
- type DateOptions
- type EmailOptions
- type FieldOptions
- type FileOptions
- type JsonOptions
- type NumberOptions
- type RelationOptions
- type Schema
- func (s *Schema) AddField(newField *SchemaField)
- func (s *Schema) AsMap() map[string]*SchemaField
- func (s *Schema) Clone() (*Schema, error)
- func (s *Schema) Fields() []*SchemaField
- func (s *Schema) GetFieldById(id string) *SchemaField
- func (s *Schema) GetFieldByName(name string) *SchemaField
- func (s *Schema) InitFieldsOptions() error
- func (s Schema) MarshalJSON() ([]byte, error)
- func (s *Schema) RemoveField(id string)
- func (s *Schema) Scan(value any) error
- func (s *Schema) UnmarshalJSON(data []byte) error
- func (s Schema) Validate() error
- func (s Schema) Value() (driver.Value, error)
- type SchemaField
- func (f *SchemaField) ColDefinition() string
- func (f *SchemaField) InitOptions() error
- func (f SchemaField) MarshalJSON() ([]byte, error)
- func (f *SchemaField) PrepareValue(value any) any
- func (f SchemaField) String() string
- func (f *SchemaField) UnmarshalJSON(data []byte) error
- func (f SchemaField) Validate() error
- type SelectOptions
- type TextOptions
- type UrlOptions
- type UserOptionsdeprecated
- func (o UserOptions) Validate() errordeprecated
Constants ¶
const ( FieldNameId = "id" FieldNameCreated = "created" FieldNameUpdated = "updated" FieldNameCollectionId = "collectionId" FieldNameCollectionName = "collectionName" FieldNameExpand = "expand" FieldNameUsername = "username" FieldNameEmail = "email" FieldNameEmailVisibility = "emailVisibility" FieldNameVerified = "verified" FieldNameTokenKey = "tokenKey" FieldNamePasswordHash = "passwordHash" FieldNameLastResetSentAt = "lastResetSentAt" FieldNameLastVerificationSentAt = "lastVerificationSentAt" )
commonly used field names
const ( FieldTypeText string = "text" FieldTypeNumber string = "number" FieldTypeBool string = "bool" FieldTypeEmail string = "email" FieldTypeUrl string = "url" FieldTypeDate string = "date" FieldTypeSelect string = "select" FieldTypeJson string = "json" FieldTypeFile string = "file" FieldTypeRelation string = "relation" // Deprecated: Will be removed in v0.9! FieldTypeUser string = "user" )
All valid field types
Variables ¶
This section is empty.
Functions ¶
func ArraybleFieldTypes ¶
func ArraybleFieldTypes() []string
ArraybleFieldTypes returns slice with all array value supported field types.
func AuthFieldNames ¶ added in v0.8.0
func AuthFieldNames() []string
AuthFieldNames returns the reserved "auth" collection auth field names.
func BaseModelFieldNames ¶ added in v0.8.0
func BaseModelFieldNames() []string
BaseModelFieldNames returns the field names that all models have (id, created, updated).
func FieldTypes ¶
func FieldTypes() []string
FieldTypes returns slice with all supported field types.
func SystemFieldNames ¶ added in v0.8.0
func SystemFieldNames() []string
SystemFields returns special internal field names that are usually readonly.
Types ¶
type BoolOptions ¶
type BoolOptions struct { }
func (BoolOptions) Validate ¶
func (o BoolOptions) Validate() error
type DateOptions ¶
type DateOptions struct { Min types.DateTime `form:"min" json:"min"` Max types.DateTime `form:"max" json:"max"` }
func (DateOptions) Validate ¶
func (o DateOptions) Validate() error
type EmailOptions ¶
type EmailOptions struct { ExceptDomains []string `form:"exceptDomains" json:"exceptDomains"` OnlyDomains []string `form:"onlyDomains" json:"onlyDomains"` }
func (EmailOptions) Validate ¶
func (o EmailOptions) Validate() error
type FieldOptions ¶
type FieldOptions interface {
Validate() error
}
FieldOptions interfaces that defines common methods that every field options struct has.
type FileOptions ¶
type FileOptions struct { MaxSelect int `form:"maxSelect" json:"maxSelect"` MaxSize int `form:"maxSize" json:"maxSize"` // in bytes MimeTypes []string `form:"mimeTypes" json:"mimeTypes"` Thumbs []string `form:"thumbs" json:"thumbs"` }
func (FileOptions) Validate ¶
func (o FileOptions) Validate() error
type JsonOptions ¶
type JsonOptions struct { }
func (JsonOptions) Validate ¶
func (o JsonOptions) Validate() error
type NumberOptions ¶
type NumberOptions struct { Min *float64 `form:"min" json:"min"` Max *float64 `form:"max" json:"max"` }
func (NumberOptions) Validate ¶
func (o NumberOptions) Validate() error
type RelationOptions ¶
type RelationOptions struct { MaxSelect *int `form:"maxSelect" json:"maxSelect"` CollectionId string `form:"collectionId" json:"collectionId"` CascadeDelete bool `form:"cascadeDelete" json:"cascadeDelete"` }
func (RelationOptions) Validate ¶
func (o RelationOptions) Validate() error
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema defines a dynamic db schema as a slice of `SchemaField`s.
func NewSchema ¶
func NewSchema(fields ...*SchemaField) Schema
NewSchema creates a new Schema instance with the provided fields.
func (*Schema) AddField ¶
func (s *Schema) AddField(newField *SchemaField)
AddField registers the provided newField to the current schema.
If field with `newField.Id` already exist, the existing field is replaced with the new one.
Otherwise the new field is appended to the other schema fields.
func (*Schema) AsMap ¶
func (s *Schema) AsMap() map[string]*SchemaField
AsMap returns a map with all registered schema field. The returned map is indexed with each field name.
func (*Schema) Fields ¶
func (s *Schema) Fields() []*SchemaField
Fields returns the registered schema fields.
func (*Schema) GetFieldById ¶
func (s *Schema) GetFieldById(id string) *SchemaField
GetFieldById returns a single field by its id.
func (*Schema) GetFieldByName ¶
func (s *Schema) GetFieldByName(name string) *SchemaField
GetFieldByName returns a single field by its name.
func (*Schema) InitFieldsOptions ¶
InitFieldsOptions calls `InitOptions()` for all schema fields.
func (Schema) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Schema) RemoveField ¶
RemoveField removes a single schema field by its id.
This method does nothing if field with `id` doesn't exist.
func (*Schema) Scan ¶
Scan implements [sql.Scanner] interface to scan the provided value into the current Schema instance.
func (*Schema) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
On success, all schema field options are auto initialized.
func (Schema) Validate ¶
Validate makes Schema validatable by implementing validation.Validatable interface.
Internally calls each individual field's validator and additionally checks for invalid renamed fields and field name duplications.
type SchemaField ¶
type SchemaField struct { System bool `form:"system" json:"system"` Id string `form:"id" json:"id"` Name string `form:"name" json:"name"` Type string `form:"type" json:"type"` Required bool `form:"required" json:"required"` Unique bool `form:"unique" json:"unique"` Options any `form:"options" json:"options"` }
SchemaField defines a single schema field structure.
func (*SchemaField) ColDefinition ¶
func (f *SchemaField) ColDefinition() string
ColDefinition returns the field db column type definition as string.
func (*SchemaField) InitOptions ¶
func (f *SchemaField) InitOptions() error
InitOptions initializes the current field options based on its type.
Returns error on unknown field type.
func (SchemaField) MarshalJSON ¶
func (f SchemaField) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*SchemaField) PrepareValue ¶
func (f *SchemaField) PrepareValue(value any) any
PrepareValue returns normalized and properly formatted field value.
func (SchemaField) String ¶
func (f SchemaField) String() string
String serializes and returns the current field as string.
func (*SchemaField) UnmarshalJSON ¶
func (f *SchemaField) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
The schema field options are auto initialized on success.
func (SchemaField) Validate ¶
func (f SchemaField) Validate() error
Validate makes `SchemaField` validatable by implementing validation.Validatable interface.
type SelectOptions ¶
type SelectOptions struct { MaxSelect int `form:"maxSelect" json:"maxSelect"` Values []string `form:"values" json:"values"` }
func (SelectOptions) Validate ¶
func (o SelectOptions) Validate() error
type TextOptions ¶
type TextOptions struct { Min *int `form:"min" json:"min"` Max *int `form:"max" json:"max"` Pattern string `form:"pattern" json:"pattern"` }
func (TextOptions) Validate ¶
func (o TextOptions) Validate() error
type UrlOptions ¶
type UrlOptions struct { ExceptDomains []string `form:"exceptDomains" json:"exceptDomains"` OnlyDomains []string `form:"onlyDomains" json:"onlyDomains"` }
func (UrlOptions) Validate ¶
func (o UrlOptions) Validate() error
type UserOptions
deprecated
type UserOptions struct { MaxSelect int `form:"maxSelect" json:"maxSelect"` CascadeDelete bool `form:"cascadeDelete" json:"cascadeDelete"` }
Deprecated: Will be removed in v0.9!
func (UserOptions) Validate
deprecated
func (o UserOptions) Validate() error
Deprecated: Will be removed in v0.9!