types

Types from PocketBase's Go package types, as JavaScript sees them: you get these objects from $app and the other globals and from hook events, and call their methods by their JS names (Go's FindRecordById is findRecordById). The same package in Go: types.

types.DateTime

DateTime represents a time.time instance in UTC that is wrapped and serialized using the app default date layout.

Member Type
time() (): time.Time Time returns the internal time.time instance.
add() (duration: time.Duration): DateTime Add returns a new DateTime based on the current DateTime + the specified duration.
sub() (u: DateTime): time.Duration Sub returns a time.duration by subtracting the specified DateTime from the current one.
addDate() (years: number, months: number, days: number): DateTime AddDate returns a new DateTime based on the current one + duration.
after() (u: DateTime): boolean After reports whether the current DateTime instance is after u.
before() (u: DateTime): boolean Before reports whether the current DateTime instance is before u.
compare() (u: DateTime): number Compare compares the current DateTime instance with u. If the current instance is before u, it returns -1. If the current instance is after u, it returns +1. If they're the same, it returns 0.
equal() (u: DateTime): boolean Equal reports whether the current DateTime and u represent the same time instant. Two DateTime can be equal even if they are in different locations. For example, 6:00 +0200 and 4:00 UTC are Equal.
unix() (): number Unix returns the current DateTime as a Unix time, aka. the number of seconds elapsed since January 1, 1970 UTC.
isZero() (): boolean IsZero checks whether the current DateTime instance has zero time value.
string() (): string String serializes the current DateTime instance into a formatted UTC date string.
marshalJSON() (): string|Array<number> MarshalJSON implements the json.marshaler interface.
unmarshalJSON() (b: string|Array<number>): void UnmarshalJSON implements the json.unmarshaler interface.
value() (): any Value implements the driver.valuer interface.
scan() (value: any): void Scan implements sql.scanner interface to scan the provided value into the current DateTime instance.

types.GeoPoint

GeoPoint defines a struct for storing geo coordinates as serialized json object (e.g. {lon:0,lat:0}).

Note: using object notation and not a plain array to avoid the confusion as there doesn't seem to be a fixed standard for the coordinates order.

Member Type
lon number
lat number
string() (): string String returns the string representation of the current GeoPoint instance.
asMap() (): { [key: string]: any } AsMap implements [core.mapExtractor] and returns a value suitable to be used in an API rule expression.
value() (): any Value implements the driver.valuer interface.
scan() (value: any): void Scan implements sql.scanner interface to scan the provided value into the current GeoPoint instance.

types.JSONArray

JSONArray defines a slice that is safe for json and db read/write.

Has everything Array<T> has.

Member Type
marshalJSON() (): string|Array<number> MarshalJSON implements the json.marshaler interface.
string() (): string String returns the string representation of the current json array.
value() (): any Value implements the driver.valuer interface.
scan() (value: any): void Scan implements sql.scanner interface to scan the provided value into the current JSONArrayT instance.

types.JSONMap

JSONMap defines a map that is safe for json and db read/write.

Has everything { [key: string]: any } has.

Member Type
get() (key: string): T Get retrieves a single value from the current JSONMapT.
set() (key: string, value: T): void Set sets a single value in the current JSONMapT.
marshalJSON() (): string|Array<number> MarshalJSON implements the json.marshaler interface.
string() (): string String returns the string representation of the current json map.
value() (): any Value implements the driver.valuer interface.
scan() (value: any): void Scan implements sql.scanner interface to scan the provided value into the current JSONMapT instance.

types.JSONRaw

JSONRaw defines a json value type that is safe for db read/write.

Has everything Array<number> has.

Member Type
string() (): string String returns the current JSONRaw instance as a json encoded string.
marshalJSON() (): string|Array<number> MarshalJSON implements the json.marshaler interface.
unmarshalJSON() (b: string|Array<number>): void UnmarshalJSON implements the json.unmarshaler interface.
value() (): any Value implements the driver.valuer interface.
scan() (value: any): void Scan implements sql.scanner interface to scan the provided value into the current JSONRaw instance.