Back to Pocketbase

Interface Store<K, T>

static/jsvm/interfaces/store.Store.html

latest4.7 KB
Original Source

Interface Store<K, T>

Store defines a concurrent safe in memory key-value data store.

Type Parameters

K

T

Hierarchy

  • Store

Index

Methods

getgetAllgetOkgetOrSethaslengthmarshalJSONremoveremoveAllresetsetsetFuncsetIfLessThanLimitunmarshalJSONvalues

Methods

get

  • get(key): T

Get returns a single element value from the store.

If key is not set, the zero T value is returned.

Parameters

key: K

Returns T

getAll

GetAll returns a shallow copy of the current store data.

Returns _TygojaDict

getOk

  • getOk(key): [T, boolean]

GetOk is similar to Get but returns also a boolean indicating whether the key exists or not.

Parameters

key: K

Returns [T, boolean]

getOrSet

  • getOrSet(key, setFunc): T

GetOrSet retrieves a single existing value for the provided key or stores a new one if it doesn't exist.

Parameters

key: K
setFunc: (() => T)
- 
  - (): T
  - 

Returns T

Returns T

has

  • has(key): boolean

Has checks if element with the specified key exist or not.

Parameters

key: K

Returns boolean

length

  • length(): number

Length returns the current number of elements in the store.

Returns number

marshalJSON

  • marshalJSON(): string | number[]

MarshalJSON implements [json.Marshaler] and export the current store data into valid JSON.

Returns string | number[]

remove

  • remove(key): void

Remove removes a single entry from the store.

Remove does nothing if key doesn't exist in the store.

Parameters

key: K

Returns void

removeAll

  • removeAll(): void

RemoveAll removes all the existing store entries.

Returns void

reset

  • reset(newData): void

Reset clears the store and replaces the store data with a shallow copy of the provided newData.

Parameters

newData: _TygojaDict

Returns void

set

  • set(key, value): void

Set sets (or overwrite if already exists) a new value for key.

Parameters

key: K
value: T

Returns void

setFunc

  • setFunc(key, fn): void

SetFunc sets (or overwrite if already exists) a new value resolved from the function callback for the provided key.

The function callback receives as argument the old store element value (if exists). If there is no old store element, the argument will be the T zero value.

Example:

s := store.New[string, int](nil) s.SetFunc("count", func(old int) int { return old + 1 })Copy

Parameters

key: K
fn: ((old) => T)
- 
  - (old): T
  - 

Parameters

    - 
old: T

Returns T

Returns void

setIfLessThanLimit

  • setIfLessThanLimit(key, value, maxAllowedElements): boolean

SetIfLessThanLimit sets (or overwrite if already exist) a new value for key.

This method is similar to Set() but it will skip adding new elements to the store if the store length has reached the specified limit. false is returned if maxAllowedElements limit is reached.

Parameters

key: K
value: T
maxAllowedElements: number

Returns boolean

unmarshalJSON

  • unmarshalJSON(data): void

UnmarshalJSON implements [json.Unmarshaler] and imports the provided JSON data into the store.

The store entries that match with the ones from the data will be overwritten with the new value.

Parameters

data: string | number[]

Returns void

values

  • values(): T[]

Values returns a slice with all of the current store values.

Returns T[]

Settings

Member Visibility

  • Inherited

Theme

OSLightDark

On This Page

Generated using TypeDoc