Skip to content
Tauri

@tauri-apps/plugin-store

Classes

Store

A lazy loaded key-value store persisted by the backend layer.

Extends

  • Resource

Constructors

new Store()
new Store(rid, path): Store
Parameters
ParameterType
ridnumber
pathstring
Returns

Store

Overrides

Resource.constructor

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L41

Accessors

rid
get rid(): number
Returns

number

Inherited from

Resource.rid

Source: undefined

Methods

clear()
clear(): Promise<void>

Clears the store, removing all key-value pairs.

Note: To clear the storage and reset it to it’s default value, use reset instead.

Returns

Promise<void>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L108

close()
close(): Promise<void>

Destroys and cleans up this resource from memory. You should not call any method on this object anymore and should drop any reference to it.

Returns

Promise<void>

Inherited from

Resource.close

Source: undefined

delete()
delete(key): Promise<boolean>

Removes a key-value pair from the store.

Parameters
ParameterTypeDescription
keystring
Returns

Promise<boolean>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L95

entries()
entries<T>(): Promise<[string, T][]>

Returns a list of all entries in the store.

Type Parameters
Type Parameter
T
Returns

Promise<[string, T][]>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L145

get()
get<T>(key): Promise<null | T>

Returns the value for the given key or null the key does not exist.

Type Parameters
Type Parameter
T
Parameters
ParameterTypeDescription
keystring
Returns

Promise<null | T>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L69

has()
has(key): Promise<boolean>

Returns true if the given key exists in the store.

Parameters
ParameterTypeDescription
keystring
Returns

Promise<boolean>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L82

keys()
keys(): Promise<string[]>

Returns a list of all key in the store.

Returns

Promise<string[]>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L127

length()
length(): Promise<number>

Returns the number of key-value pairs in the store.

Returns

Promise<number>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L154

load()
load(): Promise<void>

Attempts to load the on-disk state at the stores path into memory.

This method is useful if the on-disk state was edited by the user and you want to synchronize the changes.

Note: This method does not emit change events.

Returns

Promise<void>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L166

onChange()
onChange<T>(cb): Promise<UnlistenFn>

Listen to changes on the store.

Type Parameters
Type Parameter
T
Parameters
ParameterTypeDescription
cb(key, value) => void
Returns

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event.

Since

2.0.0

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L207

onKeyChange()
onKeyChange<T>(key, cb): Promise<UnlistenFn>

Listen to changes on a store key.

Type Parameters
Type Parameter
T
Parameters
ParameterTypeDescription
keystring
cb(value) => void
Returns

Promise<UnlistenFn>

A promise resolving to a function to unlisten to the event.

Since

2.0.0

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L189

reset()
reset(): Promise<void>

Resets the store to it’s default value.

If no default value has been set, this method behaves identical to clear.

Returns

Promise<void>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L118

save()
save(): Promise<void>

Saves the store to disk at the stores path.

As the store is only persisted to disk before the apps exit, changes might be lost in a crash. This method lets you persist the store to disk whenever you deem necessary.

Returns

Promise<void>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L177

set()
set(key, value): Promise<void>

Inserts a key-value pair into the store.

Parameters
ParameterTypeDescription
keystring
valueunknown
Returns

Promise<void>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L55

values()
values<T>(): Promise<T[]>

Returns a list of all values in the store.

Type Parameters
Type Parameter
T
Returns

Promise<T[]>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L136

Type Aliases

StoreOptions

type StoreOptions: object;

Options to create a store

Type declaration

NameTypeDescriptionDefined in
autoSave?booleanAuto save on modification with debounce duration in millisecondsSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L22

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L18

Functions

createStore()

function createStore(path, options?): Promise<Store>

Parameters

ParameterType
pathstring
options?StoreOptions

Returns

Promise<Store>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L29


© 2024 Tauri Contributors. CC-BY / MIT