models

package
v0.0.0-...-1746241 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 16 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	RequestAuthGuest  = "guest"
	RequestAuthRecord = "authRecord"
)
View Source
const (
	RequestInfoContextDefault       = "default"
	RequestInfoContextRealtime      = "realtime"
	RequestInfoContextProtectedFile = "protectedFile"
	RequestInfoContextOAuth2        = "oauth2"
)
View Source
const DefaultIdLength = basemodels.DefaultIdLength

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseModel

type BaseModel = basemodels.BaseModel

type ColumnValueMapper

type ColumnValueMapper = basemodels.ColumnValueMapper

type FilesManager

type FilesManager = basemodels.FilesManager

type Model

type Model = basemodels.Model

type Record

type Record struct {
	BaseModel
	// contains filtered or unexported fields
}

func NewRecord

func NewRecord(collection *collectionmodels.Collection) *Record

NewRecord initializes a new empty Record model.

func NewRecordFromNullStringMap

func NewRecordFromNullStringMap(collection *collectionmodels.Collection, data dbx.NullStringMap) *Record

NewRecordFromNullStringMap initializes a single new Record model with data loaded from the provided NullStringMap.

Note that this method is intended to load and Scan data from a database result and calls PostScan() which marks the record as "not new".

func NewRecordsFromNullStringMaps

func NewRecordsFromNullStringMaps(collection *collectionmodels.Collection, rows []dbx.NullStringMap) []*Record

NewRecordsFromNullStringMaps initializes a new Record model for each row in the provided NullStringMap slice.

Note that this method is intended to load and Scan data from a database result and calls PostScan() for each record marking them as "not new".

func (*Record) BaseFilesPath

func (m *Record) BaseFilesPath() string

BaseFilesPath returns the storage dir path used by the record.

func (*Record) CleanCopy

func (m *Record) CleanCopy() *Record

CleanCopy returns a copy of the current record model populated only with its LATEST data state and everything else reset to the defaults.

func (*Record) Collection

func (m *Record) Collection() *collectionmodels.Collection

Collection returns the Collection model associated to the current Record model.

func (*Record) ColumnValueMap

func (m *Record) ColumnValueMap() map[string]any

ColumnValueMap implements ColumnValueMapper interface.

func (*Record) Email

func (m *Record) Email() string

Email returns the "email" users record data value.

func (*Record) EmailVisibility

func (m *Record) EmailVisibility() bool

EmailVisibility returns the "emailVisibility" users record data value.

func (*Record) Expand

func (m *Record) Expand() map[string]any

Expand returns a shallow copy of the current Record model expand data.

func (*Record) ExpandedAll

func (m *Record) ExpandedAll(relField string) []*Record

ExpandedAll retrieves a slice of relation Records from the already loaded expand data of the current model.

If the requested expand relation is single, this method normalizes the return result and will wrap the single model as a slice.

Returns nil slice if there is no such expand relation loaded.

func (*Record) ExpandedOne

func (m *Record) ExpandedOne(relField string) *Record

ExpandedOne retrieves a single relation Record from the already loaded expand data of the current model.

If the requested expand relation is multiple, this method returns only first available Record from the expanded relation.

Returns nil if there is no such expand relation loaded.

func (*Record) FindFileFieldByFile

func (m *Record) FindFileFieldByFile(filename string) *collectionmodels.SchemaField

FindFileFieldByFile returns the first file type field for which any of the record's data contains the provided filename.

func (*Record) Get

func (m *Record) Get(key string) any

Get returns a normalized single record model data value for "key".

func (*Record) GetBool

func (m *Record) GetBool(key string) bool

GetBool returns the data value for "key" as a bool.

func (*Record) GetDateTime

func (m *Record) GetDateTime(key string) types.DateTime

GetDateTime returns the data value for "key" as a DateTime instance.

func (*Record) GetFloat

func (m *Record) GetFloat(key string) float64

GetFloat returns the data value for "key" as a float64.

func (*Record) GetInt

func (m *Record) GetInt(key string) int

GetInt returns the data value for "key" as an int.

func (*Record) GetString

func (m *Record) GetString(key string) string

GetString returns the data value for "key" as a string.

func (*Record) GetStringSlice

func (m *Record) GetStringSlice(key string) []string

GetStringSlice returns the data value for "key" as a slice of unique strings.

func (*Record) GetTime

func (m *Record) GetTime(key string) time.Time

GetTime returns the data value for "key" as a time.Time instance.

func (*Record) IgnoreEmailVisibility

func (m *Record) IgnoreEmailVisibility(state bool)

IgnoreEmailVisibility toggles the flag to ignore the users record email visibility check.

func (*Record) LastLoginAlertSentAt

func (m *Record) LastLoginAlertSentAt() types.DateTime

LastLoginAlertSentAt returns the "lastLoginAlertSentAt" users record data value.

func (*Record) LastResetSentAt

func (m *Record) LastResetSentAt() types.DateTime

LastResetSentAt returns the "lastResentSentAt" users record data value.

func (*Record) LastVerificationSentAt

func (m *Record) LastVerificationSentAt() types.DateTime

LastVerificationSentAt returns the "lastVerificationSentAt" users record data value.

func (*Record) Load

func (m *Record) Load(data map[string]any)

Load bulk loads the provided data into the current Record model.

func (Record) MarshalJSON

func (m Record) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

Only the data exported by `PublicExport()` will be serialized.

func (*Record) MergeExpand

func (m *Record) MergeExpand(expand map[string]any)

MergeExpand merges recursively the provided expand data into the current model's expand (if any).

Note that if an expanded prop with the same key is a slice (old or new expand) then both old and new records will be merged into a new slice (aka. a :merge: [b,c] => [a,b,c]). Otherwise the "old" expanded record will be replace with the "new" one (aka. a :merge: aNew => aNew).

func (*Record) OriginalCopy

func (m *Record) OriginalCopy() *Record

OriginalCopy returns a copy of the current record model populated with its ORIGINAL data state (aka. the initially loaded) and everything else reset to the defaults.

func (*Record) PasswordHash

func (m *Record) PasswordHash() string

PasswordHash returns the "passwordHash" users record data value.

func (*Record) PublicExport

func (m *Record) PublicExport() map[string]any

PublicExport exports only the record fields that are safe to be public.

For users records, to force the export of the email field you need to set `m.IgnoreEmailVisibility(true)`.

func (*Record) RefreshTokenKey

func (m *Record) RefreshTokenKey() error

RefreshTokenKey generates and sets new random users record "tokenKey".

Returns an error if the record is not from a users collection.

func (*Record) ReplaceModifers

func (m *Record) ReplaceModifers(data map[string]any) map[string]any

ReplaceModifers returns a new map with applied modifier values based on the current record and the specified data.

The resolved modifier keys will be removed.

Multiple modifiers will be applied one after another, while reusing the previous base key value result (eg. 1; -5; +2 => -2).

Example usage:

 newData := record.ReplaceModifers(data)
	// record:  {"field": 10}
	// data:    {"field+": 5}
	// newData: {"field": 15}

func (*Record) SchemaData

func (m *Record) SchemaData() map[string]any

SchemaData returns a shallow copy ONLY of the defined record schema fields data.

func (*Record) Set

func (m *Record) Set(key string, value any)

Set sets the provided key-value data pair for the current Record model.

If the record collection has field with name matching the provided "key", the value will be further normalized according to the field rules.

func (*Record) SetEmail

func (m *Record) SetEmail(email string) error

SetEmail sets the "email" users record data value.

This method doesn't check whether the provided value is a valid email.

Returns an error if the record is not from a users collection.

func (*Record) SetEmailVisibility

func (m *Record) SetEmailVisibility(visible bool) error

SetEmailVisibility sets the "emailVisibility" users record data value.

Returns an error if the record is not from a users collection.

func (*Record) SetExpand

func (m *Record) SetExpand(expand map[string]any)

SetExpand shallow copies the provided data to the current Record model's expand.

func (*Record) SetLastLoginAlertSentAt

func (m *Record) SetLastLoginAlertSentAt(dateTime types.DateTime) error

SetLastLoginAlertSentAt sets a "lastLoginAlertSentAt" users record data value.

Returns an error if the record is not from a users collection.

func (*Record) SetLastResetSentAt

func (m *Record) SetLastResetSentAt(dateTime types.DateTime) error

SetLastResetSentAt sets the "lastResentSentAt" users record data value.

Returns an error if the record is not from a users collection.

func (*Record) SetLastVerificationSentAt

func (m *Record) SetLastVerificationSentAt(dateTime types.DateTime) error

SetLastVerificationSentAt sets a "lastVerificationSentAt" users record data value.

Returns an error if the record is not from a users collection.

func (*Record) SetPassword

func (m *Record) SetPassword(password string) error

SetPassword sets cryptographically secure string to the users record "password" field. This method also resets the "lastResetSentAt" and the "tokenKey" fields.

Returns an error if the record is not from a users collection or an empty password is provided.

func (*Record) SetTokenKey

func (m *Record) SetTokenKey(key string) error

SetTokenKey sets the "tokenKey" users record data value.

Returns an error if the record is not from a users collection.

func (*Record) SetUsername

func (m *Record) SetUsername(username string) error

SetUsername sets the "username" users record data value.

This method doesn't check whether the provided value is a valid username.

Returns an error if the record is not from a users collection.

func (*Record) SetVerified

func (m *Record) SetVerified(verified bool) error

SetVerified sets the "verified" users record data value.

Returns an error if the record is not from a users collection.

func (*Record) TableName

func (m *Record) TableName() string

TableName returns the table name associated to the current Record model.

func (*Record) TokenKey

func (m *Record) TokenKey() string

TokenKey returns the "tokenKey" users record data value.

func (*Record) UnknownData

func (m *Record) UnknownData() map[string]any

UnknownData returns a shallow copy ONLY of the unknown record fields data, aka. fields that are neither one of the base and special system ones, nor defined by the collection

func (*Record) UnmarshalJSON

func (m *Record) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Record) UnmarshalJSONField

func (m *Record) UnmarshalJSONField(key string, result any) error

Retrieves the "key" json field value and unmarshals it into "result".

Example

result := struct {
    FirstName string `json:"first_name"`
}{}
err := m.UnmarshalJSONField("my_field_name", &result)

func (*Record) Username

func (m *Record) Username() string

Username returns the "username" users record data value.

func (*Record) ValidatePassword

func (m *Record) ValidatePassword(password string) bool

ValidatePassword validates a plain password against the users record password.

Returns false if the password is incorrect or record is not from a users collection.

func (*Record) Verified

func (m *Record) Verified() bool

Verified returns the "verified" users record data value.

func (*Record) WithUnknownData

func (m *Record) WithUnknownData(state bool)

WithUnknownData toggles the export/serialization of unknown data fields (false by default).

type RequestInfo

type RequestInfo struct {
	Context         string         `json:"context"`
	Query           map[string]any `json:"query"`
	Data            map[string]any `json:"data"`
	Headers         map[string]any `json:"headers"`
	AuthRecord      *Record        `json:"authRecord"`
	AdminTeamAccess bool           `json:"adminTeamAccess"`
	Method          string         `json:"method"`
}

RequestInfo defines a HTTP request data struct, usually used as part of the `@request.*` filter resolver.

func (*RequestInfo) HasModifierDataKeys

func (r *RequestInfo) HasModifierDataKeys() bool

HasModifierDataKeys loosely checks if the current struct has any modifier Data keys.

Jump to

Keyboard shortcuts

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