tinybase 6.3.0 → 6.4.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/@types/mergeable-store/index.d.ts +1 -0
  2. package/@types/mergeable-store/with-schemas/index.d.ts +1 -0
  3. package/@types/omni/index.d.ts +1 -0
  4. package/@types/omni/with-schemas/index.d.ts +1 -0
  5. package/@types/persisters/index.d.ts +2 -0
  6. package/@types/persisters/persister-browser/index.d.ts +2 -0
  7. package/@types/persisters/persister-browser/with-schemas/index.d.ts +2 -0
  8. package/@types/persisters/persister-durable-object-sql-storage/index.d.ts +1 -0
  9. package/@types/persisters/persister-durable-object-sql-storage/with-schemas/index.d.ts +1 -0
  10. package/@types/persisters/persister-pglite/index.d.ts +1 -0
  11. package/@types/persisters/persister-pglite/with-schemas/index.d.ts +1 -0
  12. package/@types/persisters/persister-react-native-sqlite/index.d.ts +181 -0
  13. package/@types/persisters/persister-react-native-sqlite/with-schemas/index.d.ts +202 -0
  14. package/@types/persisters/persister-sqlite-wasm/index.d.ts +1 -0
  15. package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.ts +1 -0
  16. package/@types/persisters/with-schemas/index.d.ts +2 -0
  17. package/@types/store/index.d.ts +13 -0
  18. package/@types/store/with-schemas/index.d.ts +13 -0
  19. package/@types/synchronizers/index.d.ts +1 -0
  20. package/@types/synchronizers/synchronizer-ws-client/index.d.ts +1 -0
  21. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.ts +1 -0
  22. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.ts +1 -0
  23. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.ts +1 -0
  24. package/@types/synchronizers/with-schemas/index.d.ts +1 -0
  25. package/@types/ui-react/index.d.ts +5 -0
  26. package/@types/ui-react/with-schemas/index.d.ts +5 -0
  27. package/@types/ui-react-inspector/index.d.ts +1 -0
  28. package/@types/ui-react-inspector/with-schemas/index.d.ts +1 -0
  29. package/min/omni/index.js +1 -1
  30. package/min/omni/index.js.gz +0 -0
  31. package/min/omni/with-schemas/index.js +1 -1
  32. package/min/omni/with-schemas/index.js.gz +0 -0
  33. package/min/persisters/persister-react-native-sqlite/index.js +1 -0
  34. package/min/persisters/persister-react-native-sqlite/index.js.gz +0 -0
  35. package/min/persisters/persister-react-native-sqlite/with-schemas/index.js +1 -0
  36. package/min/persisters/persister-react-native-sqlite/with-schemas/index.js.gz +0 -0
  37. package/omni/index.js +23 -0
  38. package/omni/with-schemas/index.js +23 -0
  39. package/package.json +43 -6
  40. package/persisters/persister-react-native-sqlite/index.js +1189 -0
  41. package/persisters/persister-react-native-sqlite/with-schemas/index.js +1189 -0
  42. package/readme.md +8 -8
  43. package/releases.md +50 -25
@@ -1115,6 +1115,7 @@ export interface MergeableStore extends Store {
1115
1115
  * ];
1116
1116
  * ```
1117
1117
  * @category Creation
1118
+ * @essential Creating stores
1118
1119
  * @since v5.0.0
1119
1120
  */
1120
1121
  export function createMergeableStore(
@@ -1607,6 +1607,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
1607
1607
  * ];
1608
1608
  * ```
1609
1609
  * @category Creation
1610
+ * @essential Creating stores
1610
1611
  * @since v5.0.0
1611
1612
  */
1612
1613
  export function createMergeableStore(
@@ -35,6 +35,7 @@ export * from '../persisters/persister-partykit-server/index.d.ts';
35
35
  export * from '../persisters/persister-pglite/index.d.ts';
36
36
  export * from '../persisters/persister-postgres/index.d.ts';
37
37
  export * from '../persisters/persister-powersync/index.d.ts';
38
+ export * from '../persisters/persister-react-native-sqlite/index.d.ts';
38
39
  export * from '../persisters/persister-remote/index.d.ts';
39
40
  export * from '../persisters/persister-sqlite-bun/index.d.ts';
40
41
  export * from '../persisters/persister-sqlite-wasm/index.d.ts';
@@ -34,6 +34,7 @@ export * from '../../persisters/persister-partykit-server/with-schemas/index.d.t
34
34
  export * from '../../persisters/persister-pglite/with-schemas/index.d.ts';
35
35
  export * from '../../persisters/persister-postgres/with-schemas/index.d.ts';
36
36
  export * from '../../persisters/persister-powersync/with-schemas/index.d.ts';
37
+ export * from '../../persisters/persister-react-native-sqlite/with-schemas/index.d.ts';
37
38
  export * from '../../persisters/persister-remote/with-schemas/index.d.ts';
38
39
  export * from '../../persisters/persister-sqlite-bun/with-schemas/index.d.ts';
39
40
  export * from '../../persisters/persister-sqlite-wasm/with-schemas/index.d.ts';
@@ -22,6 +22,7 @@
22
22
  * |SqliteBunPersister| SQLite in Bun, via [bun:sqlite](https://bun.sh/docs/api/sqlite)|Yes|Yes*
23
23
  * |SqliteWasmPersister|SQLite in a browser, via [sqlite-wasm](https://github.com/tomayac/sqlite-wasm)|Yes|Yes*
24
24
  * |ExpoSqlitePersister|SQLite in React Native, via [expo-sqlite](https://github.com/expo/expo/tree/main/packages/expo-sqlite)|Yes|Yes*
25
+ * |ReactNativeSqlitePersister|SQLite in React Native, via [react-native-sqlite-storage](https://github.com/andpor/react-native-sqlite-storage)|Yes|Yes*
25
26
  * |PostgresPersister|PostgreSQL, via [postgres](https://github.com/porsager/postgres)|Yes|Yes*
26
27
  * |PglitePersister|PostgreSQL, via [PGlite](https://github.com/electric-sql/pglite)|Yes|Yes*
27
28
  * |CrSqliteWasmPersister|SQLite CRDTs, via [cr-sqlite-wasm](https://github.com/vlcn-io/cr-sqlite)|Yes|No
@@ -956,6 +957,7 @@ export type DpcTabularValues = {
956
957
  * sessionStorage.clear();
957
958
  * ```
958
959
  * @category Persister
960
+ * @essential Persisting stores
959
961
  * @since v1.0.0
960
962
  */
961
963
  export interface Persister<Persist extends Persists = Persists.StoreOnly> {
@@ -134,6 +134,7 @@ export interface LocalPersister
134
134
  * sessionStorage.clear();
135
135
  * ```
136
136
  * @category Creation
137
+ * @essential Persisting stores
137
138
  * @since v1.0.0
138
139
  */
139
140
  export function createSessionPersister(
@@ -176,6 +177,7 @@ export function createSessionPersister(
176
177
  * localStorage.clear();
177
178
  * ```
178
179
  * @category Creation
180
+ * @essential Persisting stores
179
181
  * @since v1.0.0
180
182
  */
181
183
  export function createLocalPersister(
@@ -147,6 +147,7 @@ export interface LocalPersister<Schemas extends OptionalSchemas>
147
147
  * sessionStorage.clear();
148
148
  * ```
149
149
  * @category Creation
150
+ * @essential Persisting stores
150
151
  * @since v1.0.0
151
152
  */
152
153
  export function createSessionPersister<Schemas extends OptionalSchemas>(
@@ -199,6 +200,7 @@ export function createSessionPersister<Schemas extends OptionalSchemas>(
199
200
  * localStorage.clear();
200
201
  * ```
201
202
  * @category Creation
203
+ * @essential Persisting stores
202
204
  * @since v1.0.0
203
205
  */
204
206
  export function createLocalPersister<Schemas extends OptionalSchemas>(
@@ -337,6 +337,7 @@ export interface DurableObjectSqlStoragePersister
337
337
  * }
338
338
  * ```
339
339
  * @category Creation
340
+ * @essential Persisting stores
340
341
  * @since v6.3.0
341
342
  */
342
343
  export function createDurableObjectSqlStoragePersister(
@@ -366,6 +366,7 @@ export interface DurableObjectSqlStoragePersister<
366
366
  * }
367
367
  * ```
368
368
  * @category Creation
369
+ * @essential Persisting stores
369
370
  * @since v6.3.0
370
371
  */
371
372
  export function createDurableObjectSqlStoragePersister<
@@ -166,6 +166,7 @@ export interface PglitePersister
166
166
  * await pglite.close();
167
167
  * ```
168
168
  * @category Creation
169
+ * @essential Persisting stores
169
170
  * @since 5.2.0
170
171
  */
171
172
  export function createPglitePersister(
@@ -185,6 +185,7 @@ export interface PglitePersister<Schemas extends OptionalSchemas>
185
185
  * await pglite.close();
186
186
  * ```
187
187
  * @category Creation
188
+ * @essential Persisting stores
188
189
  * @since 5.2.0
189
190
  */
190
191
  export function createPglitePersister<Schemas extends OptionalSchemas>(
@@ -0,0 +1,181 @@
1
+ /**
2
+ * The persister-react-native-sqlite module of the TinyBase project lets you
3
+ * save and load Store data to and from a SQLite database using the
4
+ * [`react-native-sqlite-storage`](https://github.com/andpor/react-native-sqlite-storage) module (in an appropriate React Native
5
+ * environment).
6
+ * @see Database Persistence guide
7
+ * @packageDocumentation
8
+ * @module persister-react-native-sqlite
9
+ * @since v6.4.0
10
+ */
11
+ import {type SQLiteDatabase} from 'react-native-sqlite-storage';
12
+ import type {MergeableStore} from '../../mergeable-store/index.d.ts';
13
+ import type {Store} from '../../store/index.d.ts';
14
+ import type {DatabasePersisterConfig, Persister, Persists} from '../index.d.ts';
15
+
16
+ /**
17
+ * The ReactNativeSqlitePersister interface represents a Persister that lets you
18
+ * save and load Store data to and from a `react-native-sqlite-storage`
19
+ * database.
20
+ *
21
+ * You should use the createReactNativeSqlitePersister function to create an
22
+ * ReactNativeSqlitePersister object.
23
+ *
24
+ * It is a minor extension to the Persister interface and simply provides an
25
+ * extra getDb method for accessing a reference to the database instance the
26
+ * Store is being persisted to.
27
+ * @category Persister
28
+ * @since v6.4.0
29
+ */
30
+ export interface ReactNativeSqlitePersister
31
+ extends Persister<Persists.StoreOrMergeableStore> {
32
+ /**
33
+ * The getDb method returns a reference to the database instance the Store is
34
+ * being persisted to.
35
+ * @returns A reference to the database instance.
36
+ * @example
37
+ * This example creates a Persister object against a newly-created Store and
38
+ * then gets the database instance back out again.
39
+ *
40
+ * ```js yolo
41
+ * import {enablePromise, openDatabase} from 'react-native-sqlite-storage';
42
+ * import {createStore} from 'tinybase';
43
+ * import {createReactNativeSqlitePersister} from 'tinybase/persisters/persister-react-native-sqlite';
44
+ *
45
+ * enablePromise(true);
46
+ * const db = await openDatabase({name: 'my.db', location: 'default'});
47
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
48
+ * const persister = createReactNativeSqlitePersister(
49
+ * store,
50
+ * db,
51
+ * 'my_tinybase',
52
+ * );
53
+ * console.log(persister.getDb() == db);
54
+ * // -> true
55
+ *
56
+ * await persister.destroy();
57
+ * ```
58
+ * @category Getter
59
+ * @since v6.4.0
60
+ */
61
+ getDb(): SQLiteDatabase;
62
+ }
63
+
64
+ /**
65
+ * The createReactNativeSqlitePersister function creates an
66
+ * ReactNativeSqlitePersister object that can persist the Store to a local
67
+ * `react-native-sqlite-storage` database.
68
+ *
69
+ * An ReactNativeSqlitePersister supports regular Store objects, and can also be
70
+ * used to persist the metadata of a MergeableStore when using the JSON
71
+ * serialization mode, as described below.
72
+ *
73
+ * As well as providing a reference to the Store to persist, you must provide a
74
+ * `db` parameter which identifies the database instance.
75
+ *
76
+ * **Important note:** the `react-native-sqlite-storage` module must have had
77
+ * promises enabled before the database instance is passed in. Use
78
+ * `SQLite.enablePromise(true)` before initializing the Persister.
79
+ *
80
+ * A database Persister uses one of two modes: either a JSON serialization of
81
+ * the whole Store stored in a single row of a table (the default), or a tabular
82
+ * mapping of Table Ids to database table names and vice-versa).
83
+ *
84
+ * The third argument is a DatabasePersisterConfig object that configures which
85
+ * of those modes to use, and settings for each. If the third argument is simply
86
+ * a string, it is used as the `storeTableName` property of the JSON
87
+ * serialization.
88
+ *
89
+ * See the documentation for the DpcJson and DpcTabular types for more
90
+ * information on how both of those modes can be configured.
91
+ * @param store The Store or MergeableStore to persist.
92
+ * @param db The database instance that was returned from
93
+ * `await SQLite.openDatabase(...)`.
94
+ * @param configOrStoreTableName A DatabasePersisterConfig to configure the
95
+ * persistence mode (or a string to set the `storeTableName` property of the
96
+ * JSON serialization).
97
+ * @param onSqlCommand An optional handler called every time the Persister
98
+ * executes a SQL command or query. This is suitable for logging persistence
99
+ * behavior in a development environment.
100
+ * @param onIgnoredError An optional handler for the errors that the Persister
101
+ * would otherwise ignore when trying to save or load data. This is suitable for
102
+ * debugging persistence issues in a development environment.
103
+ * @returns A reference to the new ReactNativeSqlitePersister object.
104
+ * @example
105
+ * This example creates a ReactNativeSqlitePersister object and persists the
106
+ * Store to a local SQLite database as a JSON serialization into the
107
+ * `my_tinybase` table. It makes a change to the database directly and then
108
+ * reloads it back into the Store.
109
+ *
110
+ * ```js yolo
111
+ * import {enablePromise, openDatabase} from 'react-native-sqlite-storage';
112
+ * import {createStore} from 'tinybase';
113
+ * import {createReactNativeSqlitePersister} from 'tinybase/persisters/persister-react-native-sqlite';
114
+ *
115
+ * enablePromise(true);
116
+ * const db = await openDatabase({name: 'my.db', location: 'default'});
117
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
118
+ * const persister = createReactNativeSqlitePersister(
119
+ * store,
120
+ * db,
121
+ * 'my_tinybase',
122
+ * );
123
+ *
124
+ * await persister.save();
125
+ * // Store will be saved to the database.
126
+ *
127
+ * console.log(
128
+ * (await db.executeSql('SELECT * FROM my_tinybase;'))[0].rows.raw(),
129
+ * );
130
+ * // -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
131
+ *
132
+ * await db.executeSql(
133
+ * 'UPDATE my_tinybase SET store = ' +
134
+ * `'[{"pets":{"felix":{"species":"cat"}}},{}]' WHERE _id = '_';`,
135
+ * );
136
+ * await persister.load();
137
+ * console.log(store.getTables());
138
+ * // -> {pets: {felix: {species: 'cat'}}}
139
+ *
140
+ * await persister.destroy();
141
+ * ```
142
+ * @example
143
+ * This example creates a ReactNativeSqlitePersister object and persists the
144
+ * Store to a local SQLite database with tabular mapping.
145
+ *
146
+ * ```js yolo
147
+ * import {enablePromise, openDatabase} from 'react-native-sqlite-storage';
148
+ * import {createStore} from 'tinybase';
149
+ * import {createReactNativeSqlitePersister} from 'tinybase/persisters/persister-react-native-sqlite';
150
+ *
151
+ * enablePromise(true);
152
+ * const db = await openDatabase({name: 'my.db', location: 'default'});
153
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
154
+ * const persister = createReactNativeSqlitePersister(store, db, {
155
+ * mode: 'tabular',
156
+ * tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
157
+ * });
158
+ *
159
+ * await persister.save();
160
+ * console.log((await db.executeSql('SELECT * FROM pets;'))[0].rows.raw());
161
+ * // -> [{_id: 'fido', species: 'dog'}]
162
+ *
163
+ * await db.executeSql(
164
+ * `INSERT INTO pets (_id, species) VALUES ('felix', 'cat')`,
165
+ * );
166
+ * await persister.load();
167
+ * console.log(store.getTables());
168
+ * // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
169
+ *
170
+ * await persister.destroy();
171
+ * ```
172
+ * @category Creation
173
+ * @since v6.4.0
174
+ */
175
+ export function createReactNativeSqlitePersister(
176
+ store: Store | MergeableStore,
177
+ db: SQLiteDatabase,
178
+ configOrStoreTableName?: DatabasePersisterConfig | string,
179
+ onSqlCommand?: (sql: string, params?: any[]) => void,
180
+ onIgnoredError?: (error: any) => void,
181
+ ): ReactNativeSqlitePersister;
@@ -0,0 +1,202 @@
1
+ /**
2
+ * The persister-react-native-sqlite module of the TinyBase project lets you
3
+ * save and load Store data to and from a SQLite database using the
4
+ * [`react-native-sqlite-storage`](https://github.com/andpor/react-native-sqlite-storage) module (in an appropriate React Native
5
+ * environment).
6
+ * @see Database Persistence guide
7
+ * @packageDocumentation
8
+ * @module persister-react-native-sqlite
9
+ * @since v6.4.0
10
+ */
11
+ import type {SQLiteDatabase} from 'react-native-sqlite-storage';
12
+ import type {MergeableStore} from '../../../mergeable-store/with-schemas/index.d.ts';
13
+ import type {
14
+ OptionalSchemas,
15
+ Store,
16
+ } from '../../../store/with-schemas/index.d.ts';
17
+ import type {
18
+ DatabasePersisterConfig,
19
+ Persister,
20
+ Persists,
21
+ } from '../../with-schemas/index.d.ts';
22
+
23
+ /**
24
+ * The ReactNativeSqlitePersister interface represents a Persister that lets you
25
+ * save and load Store data to and from a `react-native-sqlite-storage`
26
+ * database.
27
+ *
28
+ * You should use the createReactNativeSqlitePersister function to create an
29
+ * ReactNativeSqlitePersister object.
30
+ *
31
+ * It is a minor extension to the Persister interface and simply provides an
32
+ * extra getDb method for accessing a reference to the database instance the
33
+ * Store is being persisted to.
34
+ * @category Persister
35
+ * @since v6.4.0
36
+ */
37
+ export interface ReactNativeSqlitePersister<Schemas extends OptionalSchemas>
38
+ extends Persister<Schemas, Persists.StoreOrMergeableStore> {
39
+ /**
40
+ * The getDb method returns a reference to the database instance the Store is
41
+ * being persisted to.
42
+ * @returns A reference to the database instance.
43
+ * @example
44
+ * This example creates a Persister object against a newly-created Store and
45
+ * then gets the database instance back out again.
46
+ *
47
+ * ```js yolo
48
+ * import {enablePromise, openDatabase} from 'react-native-sqlite-storage';
49
+ * import {createStore} from 'tinybase';
50
+ * import {createReactNativeSqlitePersister} from 'tinybase/persisters/persister-react-native-sqlite';
51
+ *
52
+ * enablePromise(true);
53
+ * const db = await openDatabase({name: 'my.db', location: 'default'});
54
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
55
+ * const persister = createReactNativeSqlitePersister(
56
+ * store,
57
+ * db,
58
+ * 'my_tinybase',
59
+ * );
60
+ * console.log(persister.getDb() == db);
61
+ * // -> true
62
+ *
63
+ * await persister.destroy();
64
+ * ```
65
+ * @category Getter
66
+ * @since v6.4.0
67
+ */
68
+ getDb(): SQLiteDatabase;
69
+ }
70
+
71
+ /**
72
+ * The createReactNativeSqlitePersister function creates an
73
+ * ReactNativeSqlitePersister object that can persist the Store to a local
74
+ * `react-native-sqlite-storage` database.
75
+ *
76
+ * This has schema-based typing. The following is a simplified representation:
77
+ *
78
+ * ```ts override
79
+ * createReactNativeSqlitePersister(
80
+ * store: Store | MergeableStore,
81
+ * db: SQLiteDatabase,
82
+ * configOrStoreTableName?: DatabasePersisterConfig | string,
83
+ * onSqlCommand?: (sql: string, params?: any[]) => void,
84
+ * onIgnoredError?: (error: any) => void,
85
+ * ): ReactNativeSqlitePersister;
86
+ * ```
87
+ *
88
+ * An ReactNativeSqlitePersister supports regular Store objects, and can also be
89
+ * used to persist the metadata of a MergeableStore when using the JSON
90
+ * serialization mode, as described below.
91
+ *
92
+ * As well as providing a reference to the Store to persist, you must provide a
93
+ * `db` parameter which identifies the database instance.
94
+ *
95
+ * **Important note:** the `react-native-sqlite-storage` module must have had
96
+ * promises enabled before the database instance is passed in. Use
97
+ * `SQLite.enablePromise(true)` before initializing the Persister.
98
+ *
99
+ * A database Persister uses one of two modes: either a JSON serialization of
100
+ * the whole Store stored in a single row of a table (the default), or a tabular
101
+ * mapping of Table Ids to database table names and vice-versa).
102
+ *
103
+ * The third argument is a DatabasePersisterConfig object that configures which
104
+ * of those modes to use, and settings for each. If the third argument is simply
105
+ * a string, it is used as the `storeTableName` property of the JSON
106
+ * serialization.
107
+ *
108
+ * See the documentation for the DpcJson and DpcTabular types for more
109
+ * information on how both of those modes can be configured.
110
+ * @param store The Store or MergeableStore to persist.
111
+ * @param db The database instance that was returned from
112
+ * `await SQLite.openDatabase(...)`.
113
+ * @param configOrStoreTableName A DatabasePersisterConfig to configure the
114
+ * persistence mode (or a string to set the `storeTableName` property of the
115
+ * JSON serialization).
116
+ * @param onSqlCommand An optional handler called every time the Persister
117
+ * executes a SQL command or query. This is suitable for logging persistence
118
+ * behavior in a development environment.
119
+ * @param onIgnoredError An optional handler for the errors that the Persister
120
+ * would otherwise ignore when trying to save or load data. This is suitable for
121
+ * debugging persistence issues in a development environment.
122
+ * @returns A reference to the new ReactNativeSqlitePersister object.
123
+ * @example
124
+ * This example creates a ReactNativeSqlitePersister object and persists the
125
+ * Store to a local SQLite database as a JSON serialization into the
126
+ * `my_tinybase` table. It makes a change to the database directly and then
127
+ * reloads it back into the Store.
128
+ *
129
+ * ```js yolo
130
+ * import {enablePromise, openDatabase} from 'react-native-sqlite-storage';
131
+ * import {createStore} from 'tinybase';
132
+ * import {createReactNativeSqlitePersister} from 'tinybase/persisters/persister-react-native-sqlite';
133
+ *
134
+ * enablePromise(true);
135
+ * const db = await openDatabase({name: 'my.db', location: 'default'});
136
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
137
+ * const persister = createReactNativeSqlitePersister(
138
+ * store,
139
+ * db,
140
+ * 'my_tinybase',
141
+ * );
142
+ *
143
+ * await persister.save();
144
+ * // Store will be saved to the database.
145
+ *
146
+ * console.log(
147
+ * (await db.executeSql('SELECT * FROM my_tinybase;'))[0].rows.raw(),
148
+ * );
149
+ * // -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
150
+ *
151
+ * await db.executeSql(
152
+ * 'UPDATE my_tinybase SET store = ' +
153
+ * `'[{"pets":{"felix":{"species":"cat"}}},{}]' WHERE _id = '_';`,
154
+ * );
155
+ * await persister.load();
156
+ * console.log(store.getTables());
157
+ * // -> {pets: {felix: {species: 'cat'}}}
158
+ *
159
+ * await persister.destroy();
160
+ * ```
161
+ * @example
162
+ * This example creates a ReactNativeSqlitePersister object and persists the
163
+ * Store to a local SQLite database with tabular mapping.
164
+ *
165
+ * ```js yolo
166
+ * import {enablePromise, openDatabase} from 'react-native-sqlite-storage';
167
+ * import {createStore} from 'tinybase';
168
+ * import {createReactNativeSqlitePersister} from 'tinybase/persisters/persister-react-native-sqlite';
169
+ *
170
+ * enablePromise(true);
171
+ * const db = await openDatabase({name: 'my.db', location: 'default'});
172
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
173
+ * const persister = createReactNativeSqlitePersister(store, db, {
174
+ * mode: 'tabular',
175
+ * tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
176
+ * });
177
+ *
178
+ * await persister.save();
179
+ * console.log((await db.executeSql('SELECT * FROM pets;'))[0].rows.raw());
180
+ * // -> [{_id: 'fido', species: 'dog'}]
181
+ *
182
+ * await db.executeSql(
183
+ * `INSERT INTO pets (_id, species) VALUES ('felix', 'cat')`,
184
+ * );
185
+ * await persister.load();
186
+ * console.log(store.getTables());
187
+ * // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
188
+ *
189
+ * await persister.destroy();
190
+ * ```
191
+ * @category Creation
192
+ * @since v6.4.0
193
+ */
194
+ export function createReactNativeSqlitePersister<
195
+ Schemas extends OptionalSchemas,
196
+ >(
197
+ store: Store<Schemas> | MergeableStore<Schemas>,
198
+ db: SQLiteDatabase,
199
+ configOrStoreTableName?: DatabasePersisterConfig<Schemas> | string,
200
+ onSqlCommand?: (sql: string, params?: any[]) => void,
201
+ onIgnoredError?: (error: any) => void,
202
+ ): ReactNativeSqlitePersister<Schemas>;
@@ -163,6 +163,7 @@ export interface SqliteWasmPersister
163
163
  * await persister.destroy();
164
164
  * ```
165
165
  * @category Creation
166
+ * @essential Persisting stores
166
167
  * @since v4.0.0
167
168
  */
168
169
  export function createSqliteWasmPersister(
@@ -183,6 +183,7 @@ export interface SqliteWasmPersister<Schemas extends OptionalSchemas>
183
183
  * await persister.destroy();
184
184
  * ```
185
185
  * @category Creation
186
+ * @essential Persisting stores
186
187
  * @since v4.0.0
187
188
  */
188
189
  export function createSqliteWasmPersister<Schemas extends OptionalSchemas>(
@@ -22,6 +22,7 @@
22
22
  * |SqliteBunPersister| SQLite in Bun, via [bun:sqlite](https://bun.sh/docs/api/sqlite)|Yes|Yes*
23
23
  * |SqliteWasmPersister|SQLite in a browser, via [sqlite-wasm](https://github.com/tomayac/sqlite-wasm)|Yes|Yes*
24
24
  * |ExpoSqlitePersister|SQLite in React Native, via [expo-sqlite](https://github.com/expo/expo/tree/main/packages/expo-sqlite)|Yes|Yes*
25
+ * |ReactNativeSqlitePersister|SQLite in React Native, via [react-native-sqlite-storage](https://github.com/andpor/react-native-sqlite-storage)|Yes|Yes*
25
26
  * |PostgresPersister|PostgreSQL, via [postgres](https://github.com/porsager/postgres)|Yes|Yes*
26
27
  * |PglitePersister|PostgreSQL, via [PGlite](https://github.com/electric-sql/pglite)|Yes|Yes*
27
28
  * |CrSqliteWasmPersister|SQLite CRDTs, via [cr-sqlite-wasm](https://github.com/vlcn-io/cr-sqlite)|Yes|No
@@ -1031,6 +1032,7 @@ export type DpcTabularValues = {
1031
1032
  * sessionStorage.clear();
1032
1033
  * ```
1033
1034
  * @category Persister
1035
+ * @essential Persisting stores
1034
1036
  * @since v1.0.0
1035
1037
  */
1036
1038
  export interface Persister<
@@ -1872,6 +1872,7 @@ export type StoreListenerStats = {
1872
1872
  * @see Hello World demos
1873
1873
  * @see Todo App demos
1874
1874
  * @category Store
1875
+ * @essential Creating stores
1875
1876
  * @since v1.0.0
1876
1877
  */
1877
1878
  export interface Store {
@@ -2321,6 +2322,7 @@ export interface Store {
2321
2322
  * // -> {}
2322
2323
  * ```
2323
2324
  * @category Getter
2325
+ * @essential Getting data
2324
2326
  * @since v1.0.0
2325
2327
  */
2326
2328
  getRow(tableId: Id, rowId: Id): Row;
@@ -2394,6 +2396,7 @@ export interface Store {
2394
2396
  * // -> undefined
2395
2397
  * ```
2396
2398
  * @category Getter
2399
+ * @essential Getting data
2397
2400
  * @since v1.0.0
2398
2401
  */
2399
2402
  getCell(tableId: Id, rowId: Id, cellId: Id): CellOrUndefined;
@@ -2489,6 +2492,7 @@ export interface Store {
2489
2492
  * // -> undefined
2490
2493
  * ```
2491
2494
  * @category Getter
2495
+ * @essential Getting data
2492
2496
  * @since v3.0.0
2493
2497
  */
2494
2498
  getValue(valueId: Id): ValueOrUndefined;
@@ -3157,6 +3161,7 @@ export interface Store {
3157
3161
  * // -> {pets: {fido: {color: 'brown'}}}
3158
3162
  * ```
3159
3163
  * @category Setter
3164
+ * @essential Setting data
3160
3165
  * @since v1.0.0
3161
3166
  */
3162
3167
  setRow(tableId: Id, rowId: Id, row: Row): this;
@@ -3223,6 +3228,7 @@ export interface Store {
3223
3228
  * // -> {pets: {'0': {species: 'dog'}, '1': {species: 'cat'}}}
3224
3229
  * ```
3225
3230
  * @category Setter
3231
+ * @essential Setting data
3226
3232
  * @since v1.0.0
3227
3233
  */
3228
3234
  addRow(tableId: Id, row: Row, reuseRowIds?: boolean): Id | undefined;
@@ -3343,6 +3349,7 @@ export interface Store {
3343
3349
  * // -> {pets: {fido: {species: 'dog'}}}
3344
3350
  * ```
3345
3351
  * @category Setter
3352
+ * @essential Setting data
3346
3353
  * @since v1.0.0
3347
3354
  */
3348
3355
  setCell(tableId: Id, rowId: Id, cellId: Id, cell: Cell | MapCell): this;
@@ -3506,6 +3513,7 @@ export interface Store {
3506
3513
  * // -> {employees: 3}
3507
3514
  * ```
3508
3515
  * @category Setter
3516
+ * @essential Setting data
3509
3517
  * @since v3.0.0
3510
3518
  */
3511
3519
  setValue(valueId: Id, value: Value | MapValue): this;
@@ -4263,6 +4271,7 @@ export interface Store {
4263
4271
  * // -> {open: true}
4264
4272
  * ```
4265
4273
  * @category Transaction
4274
+ * @essential Setting data
4266
4275
  * @since v1.0.0
4267
4276
  */
4268
4277
  transaction<Return>(actions: () => Return, doRollback?: DoRollback): Return;
@@ -6025,6 +6034,7 @@ export interface Store {
6025
6034
  * store.delListener(listenerId);
6026
6035
  * ```
6027
6036
  * @category Listener
6037
+ * @essential Listening for changes
6028
6038
  * @since v1.0.0
6029
6039
  */
6030
6040
  addRowListener(
@@ -6392,6 +6402,7 @@ export interface Store {
6392
6402
  * store.delListener(listenerId);
6393
6403
  * ```
6394
6404
  * @category Listener
6405
+ * @essential Listening for changes
6395
6406
  * @since v1.0.0
6396
6407
  */
6397
6408
  addCellListener(
@@ -6794,6 +6805,7 @@ export interface Store {
6794
6805
  * store.delListener(listenerId);
6795
6806
  * ```
6796
6807
  * @category Listener
6808
+ * @essential Listening for changes
6797
6809
  * @since v3.0.0
6798
6810
  */
6799
6811
  addValueListener(
@@ -7715,6 +7727,7 @@ export interface Store {
7715
7727
  * ```
7716
7728
  * @see The Basics guides
7717
7729
  * @category Creation
7730
+ * @essential Creating stores
7718
7731
  * @since v1.0.0
7719
7732
  */
7720
7733
  export function createStore(): Store;