Aller au contenu

@tauri-apps/plugin-store

Ce contenu n’est pas encore disponible dans votre langue.

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

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

  • IStore

new LazyStore(path, options?): LazyStore;

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

Note that the options are not applied if someone else already created the store

Parameter Type Description
path string Path to save the store in app_data_dir
options? StoreOptions Store configuration options

LazyStore

clear(): Promise<void>;

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

Clears the store, removing all key-value pairs.

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

Promise<void>

IStore.clear

close(): Promise<void>;

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

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

Promise<void>

IStore.close

delete(key): Promise<boolean>;

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

Removes a key-value pair from the store.

Parameter Type Description
key string -

Promise<boolean>

IStore.delete

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

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

Returns a list of all entries in the store.

Type Parameter
T

Promise<[string, T][]>

IStore.entries

get<T>(key): Promise<T | undefined>;

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

Returns the value for the given key or undefined if the key does not exist.

Type Parameter
T
Parameter Type Description
key string -

Promise<T | undefined>

IStore.get

has(key): Promise<boolean>;

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

Returns true if the given key exists in the store.

Parameter Type Description
key string -

Promise<boolean>

IStore.has

init(): Promise<void>;

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

Init/load the store if it’s not loaded already

Promise<void>

keys(): Promise<string[]>;

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

Returns a list of all keys in the store.

Promise<string[]>

IStore.keys

length(): Promise<number>;

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

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

Promise<number>

IStore.length

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

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

Listen to changes on the store.

Type Parameter
T
Parameter Type Description
cb (key, value) => void -

Promise<UnlistenFn>

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

2.0.0

IStore.onChange

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

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

Listen to changes on a store key.

Type Parameter
T
Parameter Type Description
key string -
cb (value) => void -

Promise<UnlistenFn>

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

2.0.0

IStore.onKeyChange

reload(options?): Promise<void>;

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

Attempts to load the on-disk state at the store’s 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 loads the data and merges it with the current store, this behavior will be changed to resetting to default first and then merging with the on-disk state in v3, to fully match the store with the on-disk state, set ignoreDefaults to true
  • This method does not emit change events.
Parameter Type
options? ReloadOptions

Promise<void>

IStore.reload

reset(): Promise<void>;

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

Resets the store to its default value.

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

Promise<void>

IStore.reset

save(): Promise<void>;

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

Saves the store to disk at the store’s path.

Promise<void>

IStore.save

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

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

Inserts a key-value pair into the store.

Parameter Type Description
key string -
value unknown -

Promise<void>

IStore.set

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

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

Returns a list of all values in the store.

Type Parameter
T

Promise<T[]>

IStore.values

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

A key-value store persisted by the backend layer.

  • Resource
  • IStore

get rid(): number;

Source: undefined

number

Resource.rid

clear(): Promise<void>;

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

Clears the store, removing all key-value pairs.

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

Promise<void>

IStore.clear

close(): Promise<void>;

Source: undefined

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.

Promise<void>

IStore.close
Resource.close

delete(key): Promise<boolean>;

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

Removes a key-value pair from the store.

Parameter Type Description
key string -

Promise<boolean>

IStore.delete

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

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

Returns a list of all entries in the store.

Type Parameter
T

Promise<[string, T][]>

IStore.entries

get<T>(key): Promise<T | undefined>;

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

Returns the value for the given key or undefined if the key does not exist.

Type Parameter
T
Parameter Type Description
key string -

Promise<T | undefined>

IStore.get

has(key): Promise<boolean>;

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

Returns true if the given key exists in the store.

Parameter Type Description
key string -

Promise<boolean>

IStore.has

keys(): Promise<string[]>;

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

Returns a list of all keys in the store.

Promise<string[]>

IStore.keys

length(): Promise<number>;

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

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

Promise<number>

IStore.length

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

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

Listen to changes on the store.

Type Parameter
T
Parameter Type Description
cb (key, value) => void -

Promise<UnlistenFn>

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

2.0.0

IStore.onChange

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

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

Listen to changes on a store key.

Type Parameter
T
Parameter Type Description
key string -
cb (value) => void -

Promise<UnlistenFn>

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

2.0.0

IStore.onKeyChange

reload(options?): Promise<void>;

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

Attempts to load the on-disk state at the store’s 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 loads the data and merges it with the current store, this behavior will be changed to resetting to default first and then merging with the on-disk state in v3, to fully match the store with the on-disk state, set ignoreDefaults to true
  • This method does not emit change events.
Parameter Type
options? ReloadOptions

Promise<void>

IStore.reload

reset(): Promise<void>;

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

Resets the store to its default value.

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

Promise<void>

IStore.reset

save(): Promise<void>;

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

Saves the store to disk at the store’s path.

Promise<void>

IStore.save

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

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

Inserts a key-value pair into the store.

Parameter Type Description
key string -
value unknown -

Promise<void>

IStore.set

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

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

Returns a list of all values in the store.

Type Parameter
T

Promise<T[]>

IStore.values

static get(path): Promise<Store | null>;

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

Gets an already loaded store.

If the store is not loaded, returns null. In this case you must load it.

This function is more useful when you already know the store is loaded and just need to access its instance. Prefer Store.load otherwise.

Parameter Type Description
path string Path of the store.

Promise<Store | null>

import { Store } from '@tauri-apps/api/store';
let store = await Store.get('store.json');
if (!store) {
store = await Store.load('store.json');
}

static load(path, options?): Promise<Store>;

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

Create a new Store or load the existing store with the path.

Parameter Type Description
path string Path to save the store in app_data_dir
options? StoreOptions Store configuration options

Promise<Store>

import { Store } from '@tauri-apps/api/store';
const store = await Store.load('store.json');

type ReloadOptions = object;

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

Options to IStore.reload a IStore

Property Type Description Defined in
ignoreDefaults? boolean To fully match the store with the on-disk state, ignoring defaults Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L461

type StoreOptions = object;

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

Options to create a store

Property Type Description Defined in
autoSave? boolean | number Auto save on modification with debounce duration in milliseconds, it’s 100ms by default, pass in false to disable it Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L28
createNew? boolean Force create a new store with default values even if it already exists. Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L40
defaults? object Default value of the store Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L24
deserializeFnName? string Name of a deserialize function registered in the rust side plugin builder Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L36
overrideDefaults? boolean When creating the store, override the store with the on-disk state if it exists, ignoring defaults Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L44
serializeFnName? string Name of a serialize function registered in the rust side plugin builder Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/store/guest-js/index.ts#L32

function getStore(path): Promise<Store | null>;

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

Gets an already loaded store.

If the store is not loaded, returns null. In this case you must load it.

This function is more useful when you already know the store is loaded and just need to access its instance. Prefer Store.load otherwise.

Parameter Type Description
path string Path of the store.

Promise<Store | null>

import { getStore } from '@tauri-apps/api/store';
const store = await getStore('store.json');

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

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

Create a new Store or load the existing store with the path.

Parameter Type Description
path string Path to save the store in app_data_dir
options? StoreOptions Store configuration options

Promise<Store>

import { Store } from '@tauri-apps/api/store';
const store = await Store.load('store.json');

© 2026 Tauri Contributors. CC-BY / MIT