core: Records and collections

Part of core, PocketBase's Go package core as JavaScript sees it. The same types in Go: core: Records and collections.

core.AuthOrigin

Has everything Record has.

Member Type
preValidate() (app: App): void PreValidate implements the PreValidator interface and checks whether the proxy is properly loaded.
proxyRecord() (): (Record) ProxyRecord returns the proxied Record model.
setProxyRecord() (record: Record): void SetProxyRecord loads the specified record model into the current proxy.
collectionRef() (): string CollectionRef returns the "collectionRef" field value.
setCollectionRef() (collectionId: string): void SetCollectionRef updates the "collectionRef" record field value.
recordRef() (): string RecordRef returns the "recordRef" record field value.
setRecordRef() (recordId: string): void SetRecordRef updates the "recordRef" record field value.
fingerprint() (): string Fingerprint returns the "fingerprint" record field value.
setFingerprint() (fingerprint: string): void SetFingerprint updates the "fingerprint" record field value.
created() (): types.DateTime Created returns the "created" record field value.
updated() (): types.DateTime Updated returns the "updated" record field value.

core.Collection

Has everything baseCollection, collectionAuthOptions, collectionViewOptions has.

Member Type
tableName() (): string TableName returns the Collection model SQL table name.
baseFilesPath() (): string BaseFilesPath returns the storage dir path used by the collection.
isBase() (): boolean IsBase checks if the current collection has "base" type.
isAuth() (): boolean IsAuth checks if the current collection has "auth" type.
isView() (): boolean IsView checks if the current collection has "view" type.
integrityChecks() (enable: boolean): void IntegrityChecks toggles the current collection integrity checks (ex. checking references on delete).
postScan() (): void PostScan implements the dbx.postScanner interface to auto unmarshal the raw serialized options into the concrete type specific fields.
unmarshalJSON() (b: string|Array<number>): void UnmarshalJSON implements the json.unmarshaler interface.
marshalJSON() (): string|Array<number> MarshalJSON implements the json.marshaler interface.
string() (): string String returns a string representation of the current collection.
dbExport() (app: App): { [key: string]: any } DBExport prepares and exports the current collection data for db persistence.
getIndex() (name: string): string GetIndex returns s single Collection index expression by its name.
addIndex() (name: string, unique: boolean, columnsExpr: string, optWhereExpr: string): void AddIndex adds a new index into the current collection.
removeIndex() (name: string): void RemoveIndex removes a single index with the specified name from the current collection.

core.Model

Model defines an interface with common methods that all db models should have.

Note: for simplicity composite pk are not supported.

Member Type
tableName() (): string
pk() (): any
lastSavedPK() (): any
isNew() (): boolean
markAsNew() (): void
markAsNotNew() (): void

core.BaseModel

BaseModel defines a base struct that is intended to be embedded into other custom models.

Member Type
id string Id is the primary key of the model. It is usually autogenerated by the parent model implementation.
lastSavedPK() (): any LastSavedPK returns the last saved primary key of the model.
pk() (): any
isNew() (): boolean IsNew indicates what type of db query (insert or update) should be used with the model instance.
markAsNew() (): void MarkAsNew clears the pk field and marks the current model as "new" (aka. forces m.IsNew() to be true).
markAsNotNew() (): void MarkAsNew set the pk field to the Id value and marks the current model as NOT "new" (aka. forces m.IsNew() to be false).
postScan() (): void PostScan implements the dbx.postScanner interface.

core.ExternalAuth

Has everything Record has.

Member Type
preValidate() (app: App): void PreValidate implements the PreValidator interface and checks whether the proxy is properly loaded.
proxyRecord() (): (Record) ProxyRecord returns the proxied Record model.
setProxyRecord() (record: Record): void SetProxyRecord loads the specified record model into the current proxy.
collectionRef() (): string CollectionRef returns the "collectionRef" field value.
setCollectionRef() (collectionId: string): void SetCollectionRef updates the "collectionRef" record field value.
recordRef() (): string RecordRef returns the "recordRef" record field value.
setRecordRef() (recordId: string): void SetRecordRef updates the "recordRef" record field value.
provider() (): string Provider returns the "provider" record field value.
setProvider() (provider: string): void SetProvider updates the "provider" record field value.
providerId() (): string Provider returns the "providerId" record field value.
setProviderId() (providerId: string): void SetProvider updates the "providerId" record field value.
created() (): types.DateTime Created returns the "created" record field value.
updated() (): types.DateTime Updated returns the "updated" record field value.

core.RecordInterceptor

RecordInterceptor defines a field interface for reacting to various Record related operations (create, delete, validate, etc.).

Member Type
intercept() (app: App, record: Record, actionName: string, actionFunc: () => void): void Interceptor is invoked when a specific record action occurs allowing you to perform extra validations and normalization (ex. uploading or deleting files).

core.Log

Has everything BaseModel has.

Member Type
created types.DateTime
data types.JSONMap<any>
message string
level number
tableName() (): string
dbExport() (app: App): { [key: string]: any } DBExport prepares and exports the current log model for db persistence.

core.LogsStatsItem

LogsStatsItem defines the total number of logs for a specific time period.

Member Type
date types.DateTime
total number

core.MFA

Has everything Record has.

Member Type
preValidate() (app: App): void PreValidate implements the PreValidator interface and checks whether the proxy is properly loaded.
proxyRecord() (): (Record) ProxyRecord returns the proxied Record model.
setProxyRecord() (record: Record): void SetProxyRecord loads the specified record model into the current proxy.
collectionRef() (): string CollectionRef returns the "collectionRef" field value.
setCollectionRef() (collectionId: string): void SetCollectionRef updates the "collectionRef" record field value.
recordRef() (): string RecordRef returns the "recordRef" record field value.
setRecordRef() (recordId: string): void SetRecordRef updates the "recordRef" record field value.
method() (): string Method returns the "method" record field value.
setMethod() (method: string): void SetMethod updates the "method" record field value.
created() (): types.DateTime Created returns the "created" record field value.
updated() (): types.DateTime Updated returns the "updated" record field value.
hasExpired() (maxElapsed: time.Duration): boolean HasExpired checks if the mfa is expired, aka. whether it has been more than maxElapsed time since its creation.

core.OTP

Has everything Record has.

Member Type
preValidate() (app: App): void PreValidate implements the PreValidator interface and checks whether the proxy is properly loaded.
proxyRecord() (): (Record) ProxyRecord returns the proxied Record model.
setProxyRecord() (record: Record): void SetProxyRecord loads the specified record model into the current proxy.
collectionRef() (): string CollectionRef returns the "collectionRef" field value.
setCollectionRef() (collectionId: string): void SetCollectionRef updates the "collectionRef" record field value.
recordRef() (): string RecordRef returns the "recordRef" record field value.
setRecordRef() (recordId: string): void SetRecordRef updates the "recordRef" record field value.
sentTo() (): string SentTo returns the "sentTo" record field value.
setSentTo() (val: string): void SetSentTo updates the "sentTo" record field value.
created() (): types.DateTime Created returns the "created" record field value.
updated() (): types.DateTime Updated returns the "updated" record field value.
hasExpired() (maxElapsed: time.Duration): boolean HasExpired checks if the otp is expired, aka. whether it has been more than maxElapsed time since its creation.

core.RecordFieldResolver

RecordFieldResolver defines a custom search resolver struct for managing Record model search fields.

Usually used together with search.Provider. Example:

	resolver := resolvers.NewRecordFieldResolver(
	    app,
	    myCollection,
	    &models.RequestInfo{...},
	    true,
	)
	provider := search.NewProvider(resolver)
	...
Member Type
allowedFields() (): Array<string> AllowedFields returns a copy of the resolver's allowed fields.
setAllowedFields() (newAllowedFields: Array<string>): void SetAllowedFields replaces the resolver's allowed fields with the new ones.
allowHiddenFields() (): boolean AllowHiddenFields returns whether the current resolver allows filtering hidden fields.
setAllowHiddenFields() (allowHiddenFields: boolean): void SetAllowHiddenFields enables or disables hidden fields filtering.
updateQuery() (query: dbx.SelectQuery): void
resolve() (fieldName: string): (search.ResolverResult) Resolve implements search.FieldResolver interface.

core.Record

Has everything BaseModel has.

Member Type
collection() (): (Collection) Collection returns the Collection model associated with the current Record model.
tableName() (): string TableName returns the table name associated with the current Record model.
postScan() (): void PostScan implements the dbx.postScanner interface.
hookTags() (): Array<string> HookTags returns the hook tags associated with the current record.
baseFilesPath() (): string BaseFilesPath returns the storage dir path used by the record.
original() (): (Record) Original returns a shallow copy of the current record model populated with its ORIGINAL db data state (aka. right after PostScan()) and everything else reset to the defaults.
fresh() (): (Record) Fresh returns a shallow copy of the current record model populated with its LATEST data state and everything else reset to the defaults (aka. no expand, no unknown fields and with default visibility flags).
clone() (): (Record) Clone returns a shallow copy of the current record model with all of its collection and unknown fields data, expand and flags copied.
expand() (): { [key: string]: any } Expand returns a shallow copy of the current Record model expand data (if any).
setExpand() (expand: { [key: string]: any }): void SetExpand replaces the current Record's expand with the provided expand arg data (shallow copied).
mergeExpand() (expand: { [key: string]: any }): void MergeExpand merges recursively the provided expand data into the current model's expand (if any).
fieldsData() (): { [key: string]: any } FieldsData returns a shallow copy ONLY of the collection's fields record's data.
customData() (): { [key: string]: any } CustomData returns a shallow copy ONLY of the custom record fields data, aka. fields that are neither defined by the collection, nor special system ones.
withCustomData() (state: boolean): (Record) WithCustomData toggles the export/serialization of custom data fields (false by default).
ignoreEmailVisibility() (state: boolean): (Record) IgnoreEmailVisibility toggles the flag to ignore the auth record email visibility check.
ignoreUnchangedFields() (state: boolean): (Record) IgnoreUnchangedFields toggles the flag to ignore the unchanged fields from the DB export for the UPDATE SQL query.
setRaw() (key: string, value: any): void Set sets the provided key-value data pair into the current Record model directly as it is WITHOUT NORMALIZATIONS.
setIfFieldExists() (key: string, value: any): Field SetIfFieldExists sets the provided key-value data pair into the current Record model ONLY if key is existing Collection field name/modifier.
set() (key: string, value: any): void Set sets the provided key-value data pair into the current Record model.
getRaw() (key: string): any
get() (key: string): any Get returns a normalized single record model data value for "key".
load() (data: { [key: string]: any }): void Load bulk loads the provided data into the current Record model.
getBool() (key: string): boolean GetBool returns the data value for "key" as a bool.
getString() (key: string): string GetString returns the data value for "key" as a string.
getInt() (key: string): number GetInt returns the data value for "key" as an int.
getInt64() (key: string): number GetInt64 returns the data value for "key" as an int64.
getFloat() (key: string): number GetFloat returns the data value for "key" as a float64.
getDateTime() (key: string): types.DateTime GetDateTime returns the data value for "key" as a DateTime instance.
getGeoPoint() (key: string): types.GeoPoint GetGeoPoint returns the data value for "key" as a GeoPoint instance.
getStringSlice() (key: string): Array<string> GetStringSlice returns the data value for "key" as a slice of non-zero unique strings.
getUnsavedFiles() (key: string): Array<(filesystem.File | undefined)> GetUnsavedFiles returns the uploaded files for the provided "file" field key, (aka. the current [*filesystem.File] values) so that you can apply further validations or modifications (including changing the file name or content before persisting).
getUploadedFiles() (key: string): Array<(filesystem.File | undefined)> Deprecated: replaced with GetUnsavedFiles.
unmarshalJSONField() (key: string, result: any): void Retrieves the "key" json field value and unmarshals it into "result".
expandedOne() (relField: string): (Record) ExpandedOne retrieves a single relation Record from the already loaded expand data of the current model.
expandedAll() (relField: string): Array<(Record | undefined)> ExpandedAll retrieves a slice of relation Records from the already loaded expand data of the current model.
findFileFieldByFile() (filename: string): (FileField) FindFileFieldByFile returns the first file type field for which any of the record's data contains the provided filename.
dbExport() (app: App): { [key: string]: any } DBExport implements the DBExporter interface and returns a key-value map with the data to be persisted when saving the Record in the database.
hide() (...fieldNames: string[]): (Record) Hide hides the specified fields from the public safe serialization of the record.
unhide() (...fieldNames: string[]): (Record) Unhide forces to unhide the specified fields from the public safe serialization of the record (even when the collection field itself is marked as hidden).
publicExport() (): { [key: string]: any } PublicExport exports only the record fields that are safe to be public.
marshalJSON() (): string|Array<number> MarshalJSON implements the json.marshaler interface.
unmarshalJSON() (data: string|Array<number>): void UnmarshalJSON implements the json.unmarshaler interface.
replaceModifiers() (data: { [key: string]: any }): { [key: string]: any } ReplaceModifiers returns a new map with applied modifier values based on the current record and the specified data.
email() (): string Email returns the "email" record field value (usually available with Auth collections).
setEmail() (email: string): void SetEmail sets the "email" record field value (usually available with Auth collections).
emailVisibility() (): boolean Verified returns the "emailVisibility" record field value (usually available with Auth collections).
setEmailVisibility() (visible: boolean): void SetEmailVisibility sets the "emailVisibility" record field value (usually available with Auth collections).
verified() (): boolean Verified returns the "verified" record field value (usually available with Auth collections).
setVerified() (verified: boolean): void SetVerified sets the "verified" record field value (usually available with Auth collections).
tokenKey() (): string TokenKey returns the "tokenKey" record field value (usually available with Auth collections).
setTokenKey() (key: string): void SetTokenKey sets the "tokenKey" record field value (usually available with Auth collections).
refreshTokenKey() (): void RefreshTokenKey generates and sets a new random auth record "tokenKey".
setPassword() (password: string): void SetPassword sets the "password" record field value (usually available with Auth collections).
setRandomPassword() (): string SetRandomPassword sets the "password" auth record field to a random autogenerated value.
validatePassword() (password: string): boolean ValidatePassword validates a plain password against the "password" record field.
isSuperuser() (): boolean IsSuperuser returns whether the current record is a superuser, aka. whether the record is from the _superusers collection.
newStaticAuthToken() (duration: time.Duration): string NewStaticAuthToken generates and returns a new static record authentication token.
newAuthToken() (): string NewAuthToken generates and returns a new record authentication token.
newVerificationToken() (): string NewVerificationToken generates and returns a new record verification token.
newPasswordResetToken() (): string NewPasswordResetToken generates and returns a new auth record password reset request token.
newEmailChangeToken() (newEmail: string): string NewEmailChangeToken generates and returns a new auth record change email request token.
newFileToken() (): string NewFileToken generates and returns a new record private file access token.

core.RecordProxy

RecordProxy defines an interface for a Record proxy/project model, aka. custom model struct that acts on behalve the proxied Record to allow for example typed getter/setters for the Record fields.

To implement the interface it is usually enough to embed the BaseRecordProxy struct.

Member Type
proxyRecord() (): (Record) ProxyRecord returns the proxied Record model.
setProxyRecord() (record: Record): void SetProxyRecord loads the specified record model into the current proxy.

core.BaseRecordProxy

Has everything Record has.

Member Type
proxyRecord() (): (Record) ProxyRecord returns the proxied Record model.
setProxyRecord() (record: Record): void SetProxyRecord loads the specified record model into the current proxy.

core.Param

Has everything BaseModel has.

Member Type
created types.DateTime
updated types.DateTime
value types.JSONRaw
tableName() (): string