Skip to content
Tauri

@tauri-apps/plugin-store

Classes

Store

A key-value store persisted by the backend layer.

Constructors

new Store()
new Store(path): Store
Parameters
ParameterType
pathstring
Returns

Store

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

Properties

PropertyTypeDefined in
pathstringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L19

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#L84

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#L71

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#L129

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#L45

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#L58

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#L107

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#L140

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#L154

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#L199

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#L181

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#L96

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#L167

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#L31

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#L118


© 2024 Tauri Contributors. CC-BY / MIT