コンテンツにスキップ
Tauri

Store(キー値保存)

《訳注》

Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。

このプラグインは、「永続的なキー値の保存」を提供します。これは、アプリケーションの状態を管理するための数あるオプションの一つです。これ以外のオプションの詳細については、状態管理の概要 の章をご覧ください。

この「保存 Store」プラグインを使用すると、アプリの状態をファイルに保存・永続化でき、そのファイルはアプリの再起動時などを含め、必要に応じて保存・読み込みできます。このプロセスは非同期であるため、コード内で処理する必要があることに注意してください。WebView でも Rust でも使用できます。

This plugin requires a Rust version of at least 1.77.2

Platform Level Notes
windows
linux
macos
android
ios

はじめに、「Store」プラグインをインストールしてください。

自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:

npm run tauri add store
import { load } from '@tauri-apps/plugin-store';
// `"withGlobalTauri": true`, を使用する場合は、
// const { load } = window.__TAURI__.store; を使用できます
// 新しい「Store」を作成するか、既存の「Store」をロードします。
// 同じパスを持つ `Store` がすでに作成されている場合には、オプション設定が無視されることに注意してください。
const store = await load('store.json', { autoSave: false });
// キー値を設定
await store.set('some-key', { value: 5 });
// キー値を取得
const val = await store.get<{ value: number }>('some-key');
console.log(val); // { value: 5 }
// 変更を行なった後、「Store」を手動で保存できます。
// 手動保存しない場合には、正常終了時に保存されます。
// もし `autoSave`を「数値」に設定するか「空のまま」にしておくと、
// `autoSave` はデバウンス遅延(デフォルトでは 100 ミリ秒)後に変更内容をディスクに保存します。《下記訳注参照》
await store.save();
《訳注》

デバウンス遅延 debounce delay: 特定のイベントが短時間に連続して発生(バウンス)した際に(たとえばキーボード入力時のチャタリング)、意図しない余計な入力信号を無視する(デバウンス)ために。タイマーによる処理遅延時間を設定してそのような入力イベントを無視し、最後の入力だけが一度だけ実行されるようにする手法。

高レベル JavaScript API LazyStore もあり、これは最初のアクセス時にのみ「store」をロードします。

import { LazyStore } from '@tauri-apps/plugin-store';
const store = new LazyStore('settings.json');
import { Store } from '@tauri-apps/plugin-store';
import { LazyStore } from '@tauri-apps/plugin-store';

デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、capabilities 設定でアクセス権限を変更する必要があります。

詳細については「セキュリティ・レベル Capabilities」の章を参照してください。また、プラグインのアクセス権限を設定するには「プライグン・アクセス権の使用」の章のステップ・バイ・ステップ・ガイドを参照してください。

src-tauri/capabilities/default.json
{
"permissions": [
...,
"store:default",
]
}

Default Permission

This permission set configures what kind of operations are available from the store plugin.

Granted Permissions

All operations are enabled by default.

This default permission set includes the following:

  • allow-load
  • allow-get-store
  • allow-set
  • allow-get
  • allow-has
  • allow-delete
  • allow-clear
  • allow-reset
  • allow-keys
  • allow-values
  • allow-entries
  • allow-length
  • allow-reload
  • allow-save

Permission Table

Identifier Description

store:allow-clear

Enables the clear command without any pre-configured scope.

store:deny-clear

Denies the clear command without any pre-configured scope.

store:allow-delete

Enables the delete command without any pre-configured scope.

store:deny-delete

Denies the delete command without any pre-configured scope.

store:allow-entries

Enables the entries command without any pre-configured scope.

store:deny-entries

Denies the entries command without any pre-configured scope.

store:allow-get

Enables the get command without any pre-configured scope.

store:deny-get

Denies the get command without any pre-configured scope.

store:allow-get-store

Enables the get_store command without any pre-configured scope.

store:deny-get-store

Denies the get_store command without any pre-configured scope.

store:allow-has

Enables the has command without any pre-configured scope.

store:deny-has

Denies the has command without any pre-configured scope.

store:allow-keys

Enables the keys command without any pre-configured scope.

store:deny-keys

Denies the keys command without any pre-configured scope.

store:allow-length

Enables the length command without any pre-configured scope.

store:deny-length

Denies the length command without any pre-configured scope.

store:allow-load

Enables the load command without any pre-configured scope.

store:deny-load

Denies the load command without any pre-configured scope.

store:allow-reload

Enables the reload command without any pre-configured scope.

store:deny-reload

Denies the reload command without any pre-configured scope.

store:allow-reset

Enables the reset command without any pre-configured scope.

store:deny-reset

Denies the reset command without any pre-configured scope.

store:allow-save

Enables the save command without any pre-configured scope.

store:deny-save

Denies the save command without any pre-configured scope.

store:allow-set

Enables the set command without any pre-configured scope.

store:deny-set

Denies the set command without any pre-configured scope.

store:allow-values

Enables the values command without any pre-configured scope.

store:deny-values

Denies the values command without any pre-configured scope.

【※ この日本語版は、「Nov 10, 2025 英語版」に基づいています】


© 2025 Tauri Contributors. CC-BY / MIT