@@ -76,15 +76,12 @@ Install the store plugin to get started.
76
76
<TabItem label = " JavaScript" >
77
77
78
78
``` typescript
79
- import { createStore } from ' @tauri-apps/plugin-store' ;
79
+ import { load } from ' @tauri-apps/plugin-store' ;
80
80
// when using `"withGlobalTauri": true`, you may use
81
- // const { createStore } = window.__TAURI__.store;
81
+ // const { load } = window.__TAURI__.store;
82
82
83
83
// create a new store or load the existing one
84
- const store = await createStore (' store.bin' , {
85
- // we can save automatically after each store modification
86
- autoSave: true ,
87
- });
84
+ const store = await load (' store.bin' );
88
85
89
86
// Set a value.
90
87
await store .set (' some-key' , { value: 5 });
@@ -111,7 +108,7 @@ pub fn run() {
111
108
tauri :: Builder :: default ()
112
109
. plugin (tauri_plugin_store :: Builder :: default (). build ())
113
110
. setup (| app | {
114
- let store = app . handle () . store_builder ( " store.bin " ) . build () ;
111
+ let store = app . store ( " store.json " ) ? ;
115
112
116
113
// Note that values must be serde_json::Value instances,
117
114
// otherwise, they will not be compatible with the JavaScript bindings.
@@ -121,11 +118,6 @@ pub fn run() {
121
118
let value = store . get (" some-key" ). expect (" Failed to get value from store" );
122
119
println! (" {}" , value ); // {"value":5}
123
120
124
- // You can manually save the store after making changes.
125
- // Otherwise, it will save upon graceful exit as described above.
126
- store . save ()? ;
127
-
128
-
129
121
Ok (())
130
122
})
131
123
. run (tauri :: generate_context! ())
@@ -136,6 +128,32 @@ pub fn run() {
136
128
</TabItem >
137
129
</Tabs >
138
130
131
+ ## Migrating from v1 and v2 beta/rc
132
+
133
+
134
+ <Tabs >
135
+ <TabItem label = " JavaScript" >
136
+
137
+ ``` diff
138
+ - import { Store } from '@tauri-apps/plugin-store';
139
+ + import { LazyStore } from '@tauri-apps/plugin-store';
140
+ ```
141
+
142
+ </TabItem >
143
+ <TabItem label = " Rust" >
144
+
145
+ ``` diff
146
+ - with_store(app.handle().clone(), stores, path, |store| {
147
+ - store.insert("some-key".to_string(), json!({ "value": 5 }))?;
148
+ - Ok(())
149
+ - });
150
+ + let store = app.store(path)?;
151
+ + store.set("some-key".to_string(), json!({ "value": 5 }));
152
+ ```
153
+
154
+ </TabItem >
155
+ </Tabs >
156
+
139
157
## Permissions
140
158
141
159
By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed. You must modify the permissions in your ` capabilities ` configuration to enable these.
0 commit comments