Skip to content
Tauri

Store

This plugin provides a persistent key-value store. This is one of many options to handle state in your application. See the state management overview for more information on additional options.

This store will allow you to persist state to a file which can be saved and loaded on demand including between app restarts. Note that this process is asynchronous which will require handling it within your code. It can be used both in the webview or within Rust.

Supported Platforms

  • Windows
  • Linux
  • macOS
  • Android
  • iOS

Setup

Install the store plugin to get started.

Use your project’s package manager to add the dependency:

npm run tauri add store

Usage

import { Store } from '@tauri-apps/plugin-store';
// when using `"withGlobalTauri": true`, you may use
// const { Store } = window.__TAURI_PLUGIN_STORE__;
// Store will be loaded automatically when used in JavaScript binding.
const store = new Store('store.bin');
// Set a value.
await store.set('some-key', { value: 5 });
// Get a value.
const val = await store.get('some-key');
console.log(val); // { value: 5 }
// You can manually save the store after making changes.
// Otherwise, it will save upon graceful exit as described above.
await store.save();

Permissions

By default, all plugin commands are blocked and cannot be accessed. You must define a list of permissions in your capabilities configuration.

See Permissions Overview for more information.

src-tauri/capabilities/main.json
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "main-capability",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"store:allow-get",
"store:allow-set",
"store:allow-save",
"store:allow-load"
]
}
PermissionDescription
store:allow-clearEnables the clear command without any pre-configured scope.
store:deny-clearDenies the clear command without any pre-configured scope.
store:allow-deleteEnables the delete command without any pre-configured scope.
store:deny-deleteDenies the delete command without any pre-configured scope.
store:allow-entriesEnables the entries command without any pre-configured scope.
store:deny-entriesDenies the entries command without any pre-configured scope.
store:allow-getEnables the get command without any pre-configured scope.
store:deny-getDenies the get command without any pre-configured scope.
store:allow-hasEnables the has command without any pre-configured scope.
store:deny-hasDenies the has command without any pre-configured scope.
store:allow-keysEnables the keys command without any pre-configured scope.
store:deny-keysDenies the keys command without any pre-configured scope.
store:allow-lengthEnables the length command without any pre-configured scope.
store:deny-lengthDenies the length command without any pre-configured scope.
store:allow-loadEnables the load command without any pre-configured scope.
store:deny-loadDenies the load command without any pre-configured scope.
store:allow-resetEnables the reset command without any pre-configured scope.
store:deny-resetDenies the reset command without any pre-configured scope.
store:allow-saveEnables the save command without any pre-configured scope.
store:deny-saveDenies the save command without any pre-configured scope.
store:allow-setEnables the set command without any pre-configured scope.
store:deny-setDenies the set command without any pre-configured scope.
store:allow-valuesEnables the values command without any pre-configured scope.
store:deny-valuesDenies the values command without any pre-configured scope.

© 2024 Tauri Contributors. CC-BY / MIT