tinybase 9.7.0-beta.0 → 9.7.0
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.
- package/@types/omni/index.d.ts +1 -0
- package/@types/omni/with-schemas/index.d.ts +1 -0
- package/@types/persisters/persister-electric-sql/index.d.ts +12 -0
- package/@types/persisters/persister-electric-sql/with-schemas/index.d.ts +12 -0
- package/@types/persisters/persister-sqlite-node/index.d.ts +184 -0
- package/@types/persisters/persister-sqlite-node/with-schemas/index.d.ts +208 -0
- package/@types/persisters/persister-sqlite3/index.d.ts +12 -0
- package/@types/persisters/persister-sqlite3/with-schemas/index.d.ts +12 -0
- package/@types/ui-react-dom/index.d.ts +10 -10
- package/@types/ui-react-dom/with-schemas/index.d.ts +10 -10
- package/@types/ui-react-dom-charts/index.d.ts +7 -7
- package/@types/ui-react-dom-charts/with-schemas/index.d.ts +7 -7
- package/@types/ui-react-inspector/index.d.ts +1 -1
- package/@types/ui-react-inspector/with-schemas/index.d.ts +1 -1
- package/@types/ui-solid-dom/index.d.ts +10 -10
- package/@types/ui-solid-dom/with-schemas/index.d.ts +10 -10
- package/@types/ui-solid-inspector/index.d.ts +1 -1
- package/@types/ui-solid-inspector/with-schemas/index.d.ts +1 -1
- package/@types/ui-svelte-dom/index.d.ts +10 -10
- package/@types/ui-svelte-dom/with-schemas/index.d.ts +10 -10
- package/@types/ui-svelte-inspector/index.d.ts +1 -1
- package/@types/ui-svelte-inspector/with-schemas/index.d.ts +1 -1
- package/agents.md +45 -0
- package/min/omni/index.js +1 -1
- package/min/omni/index.js.gz +0 -0
- package/min/omni/with-schemas/index.js +1 -1
- package/min/omni/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-node/index.js +1 -0
- package/min/persisters/persister-sqlite-node/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-node/with-schemas/index.js +1 -0
- package/min/persisters/persister-sqlite-node/with-schemas/index.js.gz +0 -0
- package/omni/index.js +22 -0
- package/omni/with-schemas/index.js +22 -0
- package/package.json +45 -9
- package/persisters/persister-sqlite-node/index.js +1762 -0
- package/persisters/persister-sqlite-node/with-schemas/index.js +1762 -0
- package/readme.md +3 -3
- package/releases.md +24 -2
package/@types/omni/index.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export * from '../persisters/persister-react-native-mmkv/index.d.ts';
|
|
|
43
43
|
export * from '../persisters/persister-react-native-sqlite/index.d.ts';
|
|
44
44
|
export * from '../persisters/persister-remote/index.d.ts';
|
|
45
45
|
export * from '../persisters/persister-sqlite-bun/index.d.ts';
|
|
46
|
+
export * from '../persisters/persister-sqlite-node/index.d.ts';
|
|
46
47
|
export * from '../persisters/persister-sqlite-wasm/index.d.ts';
|
|
47
48
|
export * from '../persisters/persister-sqlite3/index.d.ts';
|
|
48
49
|
export * from '../persisters/persister-supabase/index.d.ts';
|
|
@@ -42,6 +42,7 @@ export * from '../../persisters/persister-react-native-mmkv/with-schemas/index.d
|
|
|
42
42
|
export * from '../../persisters/persister-react-native-sqlite/with-schemas/index.d.ts';
|
|
43
43
|
export * from '../../persisters/persister-remote/with-schemas/index.d.ts';
|
|
44
44
|
export * from '../../persisters/persister-sqlite-bun/with-schemas/index.d.ts';
|
|
45
|
+
export * from '../../persisters/persister-sqlite-node/with-schemas/index.d.ts';
|
|
45
46
|
export * from '../../persisters/persister-sqlite-wasm/with-schemas/index.d.ts';
|
|
46
47
|
export * from '../../persisters/persister-sqlite3/with-schemas/index.d.ts';
|
|
47
48
|
export * from '../../persisters/persister-supabase/with-schemas/index.d.ts';
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
* The persister-electric-sql module of the TinyBase project lets you save and
|
|
3
3
|
* load Store data to and from a local ElectricSQL database (in an appropriate
|
|
4
4
|
* environment).
|
|
5
|
+
*
|
|
6
|
+
* This module is deprecated as of v9.7.0 and will be removed in v10.0.0. The
|
|
7
|
+
* `electric-sql` module that it binds to was deprecated by its authors, has not
|
|
8
|
+
* been published since 2024, and has been superseded by a rebuilt sync engine
|
|
9
|
+
* with a different architecture. If you are working with PostgreSQL, the
|
|
10
|
+
* PgPersister, PostgresPersister and PglitePersister are all actively
|
|
11
|
+
* supported.
|
|
12
|
+
* @deprecated The `electric-sql` module that this binds to is no longer
|
|
13
|
+
* maintained. This module will be removed in v10.0.0.
|
|
5
14
|
* @see Database Persistence guide
|
|
6
15
|
* @packageDocumentation
|
|
7
16
|
* @module persister-electric-sql
|
|
@@ -66,6 +75,9 @@ export interface ElectricSqlPersister extends Persister {
|
|
|
66
75
|
* The createElectricSqlPersister function creates an ElectricSqlPersister
|
|
67
76
|
* object that can persist a Store to a local ElectricSQL database.
|
|
68
77
|
*
|
|
78
|
+
* This function is deprecated as of v9.7.0 and will be removed in v10.0.0, as
|
|
79
|
+
* the `electric-sql` module that it binds to is no longer maintained.
|
|
80
|
+
*
|
|
69
81
|
* An ElectricSqlPersister only supports regular Store objects, and cannot be
|
|
70
82
|
* used to persist the metadata of a MergeableStore.
|
|
71
83
|
*
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
* The persister-electric-sql module of the TinyBase project lets you save and
|
|
3
3
|
* load Store data to and from a local ElectricSQL database (in an appropriate
|
|
4
4
|
* environment).
|
|
5
|
+
*
|
|
6
|
+
* This module is deprecated as of v9.7.0 and will be removed in v10.0.0. The
|
|
7
|
+
* `electric-sql` module that it binds to was deprecated by its authors, has not
|
|
8
|
+
* been published since 2024, and has been superseded by a rebuilt sync engine
|
|
9
|
+
* with a different architecture. If you are working with PostgreSQL, the
|
|
10
|
+
* PgPersister, PostgresPersister and PglitePersister are all actively
|
|
11
|
+
* supported.
|
|
12
|
+
* @deprecated The `electric-sql` module that this binds to is no longer
|
|
13
|
+
* maintained. This module will be removed in v10.0.0.
|
|
5
14
|
* @see Database Persistence guide
|
|
6
15
|
* @packageDocumentation
|
|
7
16
|
* @module persister-electric-sql
|
|
@@ -86,6 +95,9 @@ export interface ElectricSqlPersister<
|
|
|
86
95
|
* ): ElectricSqlPersister;
|
|
87
96
|
* ```
|
|
88
97
|
*
|
|
98
|
+
* This function is deprecated as of v9.7.0 and will be removed in v10.0.0, as
|
|
99
|
+
* the `electric-sql` module that it binds to is no longer maintained.
|
|
100
|
+
*
|
|
89
101
|
* An ElectricSqlPersister only supports regular Store objects, and cannot be
|
|
90
102
|
* used to persist the metadata of a MergeableStore.
|
|
91
103
|
*
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The persister-sqlite-node module of the TinyBase project lets you save and
|
|
3
|
+
* load Store data to and from a local SQLite database, via the synchronous
|
|
4
|
+
* [`node:sqlite`](https://nodejs.org/api/sqlite.html) module built into
|
|
5
|
+
* Node.js.
|
|
6
|
+
* @see Database Persistence guide
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
* @module persister-sqlite-node
|
|
9
|
+
* @since 9.7.0
|
|
10
|
+
*/
|
|
11
|
+
import type {DatabaseSync} from 'node:sqlite';
|
|
12
|
+
import type {MergeableStore} from '../../mergeable-store/index.d.ts';
|
|
13
|
+
import type {Store} from '../../store/index.d.ts';
|
|
14
|
+
import type {
|
|
15
|
+
DatabasePersisterConfig,
|
|
16
|
+
DpcJson,
|
|
17
|
+
Persister,
|
|
18
|
+
Persists,
|
|
19
|
+
} from '../index.d.ts';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The SqliteNodePersister interface represents a Persister that lets you save
|
|
23
|
+
* and load Store data to and from a local SQLite database.
|
|
24
|
+
*
|
|
25
|
+
* You should use the createSqliteNodePersister function to create a
|
|
26
|
+
* SqliteNodePersister object.
|
|
27
|
+
*
|
|
28
|
+
* It is a minor extension to the Persister interface and simply provides an
|
|
29
|
+
* extra getDb method for accessing a reference to the database the Store is
|
|
30
|
+
* being persisted to.
|
|
31
|
+
* @category Persister
|
|
32
|
+
* @since 9.7.0
|
|
33
|
+
*/
|
|
34
|
+
export interface SqliteNodePersister extends Persister<Persists.StoreOrMergeableStore> {
|
|
35
|
+
/**
|
|
36
|
+
* The getDb method returns a reference to the database the Store is being
|
|
37
|
+
* persisted to.
|
|
38
|
+
* @returns A reference to the database.
|
|
39
|
+
* @example
|
|
40
|
+
* This example creates a Persister object against a newly-created Store and
|
|
41
|
+
* then gets the database back out again.
|
|
42
|
+
*
|
|
43
|
+
* ```js
|
|
44
|
+
* import {DatabaseSync} from 'node:sqlite';
|
|
45
|
+
* import {createStore} from 'tinybase';
|
|
46
|
+
* import {createSqliteNodePersister} from 'tinybase/persisters/persister-sqlite-node';
|
|
47
|
+
*
|
|
48
|
+
* const db = new DatabaseSync(':memory:');
|
|
49
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
50
|
+
* const persister = createSqliteNodePersister(store, db, 'my_tinybase');
|
|
51
|
+
*
|
|
52
|
+
* console.log(persister.getDb() == db);
|
|
53
|
+
* // -> true
|
|
54
|
+
*
|
|
55
|
+
* await persister.destroy();
|
|
56
|
+
* db.close();
|
|
57
|
+
* ```
|
|
58
|
+
* @category Getter
|
|
59
|
+
* @since 9.7.0
|
|
60
|
+
*/
|
|
61
|
+
getDb(): DatabaseSync;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The createSqliteNodePersister function creates a SqliteNodePersister object
|
|
66
|
+
* that can persist a Store to a local SQLite database.
|
|
67
|
+
*
|
|
68
|
+
* A SqliteNodePersister supports regular Store objects, and can also be used to
|
|
69
|
+
* persist the metadata of a MergeableStore when using the JSON serialization
|
|
70
|
+
* mode, as described below.
|
|
71
|
+
*
|
|
72
|
+
* As well as providing a reference to the Store to persist, you must provide a
|
|
73
|
+
* `db` parameter which is the database returned from `new DatabaseSync(...)`.
|
|
74
|
+
*
|
|
75
|
+
* Since the `node:sqlite` module is built into Node.js, this is the only
|
|
76
|
+
* SQLite-based Persister that requires no additional dependency at all. Note
|
|
77
|
+
* that the module is only available in newer versions of Node.js, and that it
|
|
78
|
+
* is still marked as experimental, so its API may change.
|
|
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
|
+
*
|
|
92
|
+
* Note that `node:sqlite` does not signal when the database changes, so if you
|
|
93
|
+
* enable automatic loading with the startAutoLoad method, it polls the database
|
|
94
|
+
* for changes. The Sqlite3Persister, which uses the asynchronous `sqlite3`
|
|
95
|
+
* module, is notified of changes as they happen, and may suit you better if
|
|
96
|
+
* that matters.
|
|
97
|
+
* @param store The Store or MergeableStore to persist.
|
|
98
|
+
* @param db The database that was returned from `new DatabaseSync(...)`.
|
|
99
|
+
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
|
|
100
|
+
* persistence mode (or a string to set the `storeTableName` property of the
|
|
101
|
+
* JSON serialization).
|
|
102
|
+
* @param onSqlCommand An optional handler called every time the Persister
|
|
103
|
+
* executes a SQL command or query. This is suitable for logging persistence
|
|
104
|
+
* behavior in a development environment.
|
|
105
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
106
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
107
|
+
* debugging persistence issues in a development environment.
|
|
108
|
+
* @returns A reference to the new SqliteNodePersister object.
|
|
109
|
+
* @example
|
|
110
|
+
* This example creates a SqliteNodePersister object and persists the Store to a
|
|
111
|
+
* local SQLite database as a JSON serialization into the `my_tinybase` table.
|
|
112
|
+
* It makes a change to the database directly and then reloads it back into the
|
|
113
|
+
* Store.
|
|
114
|
+
*
|
|
115
|
+
* ```js
|
|
116
|
+
* import {DatabaseSync} from 'node:sqlite';
|
|
117
|
+
* import {createStore} from 'tinybase';
|
|
118
|
+
* import {createSqliteNodePersister} from 'tinybase/persisters/persister-sqlite-node';
|
|
119
|
+
*
|
|
120
|
+
* const db = new DatabaseSync(':memory:');
|
|
121
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
122
|
+
* const persister = createSqliteNodePersister(store, db, 'my_tinybase');
|
|
123
|
+
*
|
|
124
|
+
* await persister.save();
|
|
125
|
+
* // Store will be saved to the database.
|
|
126
|
+
*
|
|
127
|
+
* console.log(db.prepare('SELECT * FROM my_tinybase;').all());
|
|
128
|
+
* // -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
|
|
129
|
+
*
|
|
130
|
+
* db.prepare('UPDATE my_tinybase SET store = ? WHERE _id = ?;').run(
|
|
131
|
+
* '[{"pets":{"felix":{"species":"cat"}}},{}]',
|
|
132
|
+
* '_',
|
|
133
|
+
* );
|
|
134
|
+
* await persister.load();
|
|
135
|
+
* console.log(store.getTables());
|
|
136
|
+
* // -> {pets: {felix: {species: 'cat'}}}
|
|
137
|
+
*
|
|
138
|
+
* await persister.destroy();
|
|
139
|
+
* db.close();
|
|
140
|
+
* ```
|
|
141
|
+
* @example
|
|
142
|
+
* This example creates a SqliteNodePersister object and persists the Store to a
|
|
143
|
+
* local SQLite database with tabular mapping.
|
|
144
|
+
*
|
|
145
|
+
* ```js
|
|
146
|
+
* import {DatabaseSync} from 'node:sqlite';
|
|
147
|
+
* import {createStore} from 'tinybase';
|
|
148
|
+
* import {createSqliteNodePersister} from 'tinybase/persisters/persister-sqlite-node';
|
|
149
|
+
*
|
|
150
|
+
* const db = new DatabaseSync(':memory:');
|
|
151
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
152
|
+
* const persister = createSqliteNodePersister(store, db, {
|
|
153
|
+
* mode: 'tabular',
|
|
154
|
+
* tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
|
|
155
|
+
* });
|
|
156
|
+
*
|
|
157
|
+
* await persister.save();
|
|
158
|
+
* console.log(db.prepare('SELECT * FROM pets;').all());
|
|
159
|
+
* // -> [{_id: 'fido', species: 'dog'}]
|
|
160
|
+
*
|
|
161
|
+
* db.prepare(
|
|
162
|
+
* `INSERT INTO pets (_id, species) VALUES ('felix', 'cat')`,
|
|
163
|
+
* ).run();
|
|
164
|
+
* await persister.load();
|
|
165
|
+
* console.log(store.getTables());
|
|
166
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
167
|
+
*
|
|
168
|
+
* await persister.destroy();
|
|
169
|
+
* db.close();
|
|
170
|
+
* ```
|
|
171
|
+
* @category Creation
|
|
172
|
+
* @since 9.7.0
|
|
173
|
+
*/
|
|
174
|
+
export function createSqliteNodePersister<StoreType extends Store>(
|
|
175
|
+
store: StoreType,
|
|
176
|
+
db: DatabaseSync,
|
|
177
|
+
configOrStoreTableName?:
|
|
178
|
+
| (NoInfer<StoreType> extends MergeableStore
|
|
179
|
+
? DpcJson
|
|
180
|
+
: DatabasePersisterConfig)
|
|
181
|
+
| string,
|
|
182
|
+
onSqlCommand?: (sql: string, params?: any[]) => void,
|
|
183
|
+
onIgnoredError?: (error: any) => void,
|
|
184
|
+
): SqliteNodePersister;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The persister-sqlite-node module of the TinyBase project lets you save and
|
|
3
|
+
* load Store data to and from a local SQLite database, via the synchronous
|
|
4
|
+
* [`node:sqlite`](https://nodejs.org/api/sqlite.html) module built into
|
|
5
|
+
* Node.js.
|
|
6
|
+
* @see Database Persistence guide
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
* @module persister-sqlite-node
|
|
9
|
+
* @since 9.7.0
|
|
10
|
+
*/
|
|
11
|
+
import type {DatabaseSync} from 'node:sqlite';
|
|
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
|
+
DpcJson,
|
|
20
|
+
Persister,
|
|
21
|
+
Persists,
|
|
22
|
+
} from '../../with-schemas/index.d.ts';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The SqliteNodePersister interface represents a Persister that lets you save
|
|
26
|
+
* and load Store data to and from a local SQLite database.
|
|
27
|
+
*
|
|
28
|
+
* You should use the createSqliteNodePersister function to create a
|
|
29
|
+
* SqliteNodePersister 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 the Store is
|
|
33
|
+
* being persisted to.
|
|
34
|
+
* @category Persister
|
|
35
|
+
* @since 9.7.0
|
|
36
|
+
*/
|
|
37
|
+
export interface SqliteNodePersister<
|
|
38
|
+
Schemas extends OptionalSchemas,
|
|
39
|
+
> extends Persister<Schemas, Persists.StoreOrMergeableStore> {
|
|
40
|
+
/**
|
|
41
|
+
* The getDb method returns a reference to the database the Store is being
|
|
42
|
+
* persisted to.
|
|
43
|
+
* @returns A reference to the database.
|
|
44
|
+
* @example
|
|
45
|
+
* This example creates a Persister object against a newly-created Store and
|
|
46
|
+
* then gets the database back out again.
|
|
47
|
+
*
|
|
48
|
+
* ```js
|
|
49
|
+
* import {DatabaseSync} from 'node:sqlite';
|
|
50
|
+
* import {createStore} from 'tinybase';
|
|
51
|
+
* import {createSqliteNodePersister} from 'tinybase/persisters/persister-sqlite-node';
|
|
52
|
+
*
|
|
53
|
+
* const db = new DatabaseSync(':memory:');
|
|
54
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
55
|
+
* const persister = createSqliteNodePersister(store, db, 'my_tinybase');
|
|
56
|
+
*
|
|
57
|
+
* console.log(persister.getDb() == db);
|
|
58
|
+
* // -> true
|
|
59
|
+
*
|
|
60
|
+
* await persister.destroy();
|
|
61
|
+
* db.close();
|
|
62
|
+
* ```
|
|
63
|
+
* @category Getter
|
|
64
|
+
* @since 9.7.0
|
|
65
|
+
*/
|
|
66
|
+
getDb(): DatabaseSync;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The createSqliteNodePersister function creates a SqliteNodePersister object
|
|
71
|
+
* that can persist a Store to a local SQLite database.
|
|
72
|
+
*
|
|
73
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
74
|
+
*
|
|
75
|
+
* ```ts override
|
|
76
|
+
* createSqliteNodePersister<StoreType extends Store>(
|
|
77
|
+
* store: StoreType,
|
|
78
|
+
* db: DatabaseSync,
|
|
79
|
+
* configOrStoreTableName?:
|
|
80
|
+
* | (NoInfer<StoreType> extends MergeableStore
|
|
81
|
+
* ? DpcJson
|
|
82
|
+
* : DatabasePersisterConfig)
|
|
83
|
+
* | string,
|
|
84
|
+
* onSqlCommand?: (sql: string, params?: any[]) => void,
|
|
85
|
+
* onIgnoredError?: (error: any) => void,
|
|
86
|
+
* ): SqliteNodePersister;
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* A SqliteNodePersister supports regular Store objects, and can also be used to
|
|
90
|
+
* persist the metadata of a MergeableStore when using the JSON serialization
|
|
91
|
+
* mode, as described below.
|
|
92
|
+
*
|
|
93
|
+
* As well as providing a reference to the Store to persist, you must provide a
|
|
94
|
+
* `db` parameter which is the database returned from `new DatabaseSync(...)`.
|
|
95
|
+
*
|
|
96
|
+
* Since the `node:sqlite` module is built into Node.js, this is the only
|
|
97
|
+
* SQLite-based Persister that requires no additional dependency at all. Note
|
|
98
|
+
* that the module is only available in newer versions of Node.js, and that it
|
|
99
|
+
* is still marked as experimental, so its API may change.
|
|
100
|
+
*
|
|
101
|
+
* A database Persister uses one of two modes: either a JSON serialization of
|
|
102
|
+
* the whole Store stored in a single row of a table (the default), or a tabular
|
|
103
|
+
* mapping of Table Ids to database table names and vice-versa).
|
|
104
|
+
*
|
|
105
|
+
* The third argument is a DatabasePersisterConfig object that configures which
|
|
106
|
+
* of those modes to use, and settings for each. If the third argument is simply
|
|
107
|
+
* a string, it is used as the `storeTableName` property of the JSON
|
|
108
|
+
* serialization.
|
|
109
|
+
*
|
|
110
|
+
* See the documentation for the DpcJson and DpcTabular types for more
|
|
111
|
+
* information on how both of those modes can be configured.
|
|
112
|
+
*
|
|
113
|
+
* Note that `node:sqlite` does not signal when the database changes, so if you
|
|
114
|
+
* enable automatic loading with the startAutoLoad method, it polls the database
|
|
115
|
+
* for changes. The Sqlite3Persister, which uses the asynchronous `sqlite3`
|
|
116
|
+
* module, is notified of changes as they happen, and may suit you better if
|
|
117
|
+
* that matters.
|
|
118
|
+
* @param store The Store or MergeableStore to persist.
|
|
119
|
+
* @param db The database that was returned from `new DatabaseSync(...)`.
|
|
120
|
+
* @param configOrStoreTableName A DatabasePersisterConfig to configure the
|
|
121
|
+
* persistence mode (or a string to set the `storeTableName` property of the
|
|
122
|
+
* JSON serialization).
|
|
123
|
+
* @param onSqlCommand An optional handler called every time the Persister
|
|
124
|
+
* executes a SQL command or query. This is suitable for logging persistence
|
|
125
|
+
* behavior in a development environment.
|
|
126
|
+
* @param onIgnoredError An optional handler for the errors that the Persister
|
|
127
|
+
* would otherwise ignore when trying to save or load data. This is suitable for
|
|
128
|
+
* debugging persistence issues in a development environment.
|
|
129
|
+
* @returns A reference to the new SqliteNodePersister object.
|
|
130
|
+
* @example
|
|
131
|
+
* This example creates a SqliteNodePersister object and persists the Store to a
|
|
132
|
+
* local SQLite database as a JSON serialization into the `my_tinybase` table.
|
|
133
|
+
* It makes a change to the database directly and then reloads it back into the
|
|
134
|
+
* Store.
|
|
135
|
+
*
|
|
136
|
+
* ```js
|
|
137
|
+
* import {DatabaseSync} from 'node:sqlite';
|
|
138
|
+
* import {createStore} from 'tinybase';
|
|
139
|
+
* import {createSqliteNodePersister} from 'tinybase/persisters/persister-sqlite-node';
|
|
140
|
+
*
|
|
141
|
+
* const db = new DatabaseSync(':memory:');
|
|
142
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
143
|
+
* const persister = createSqliteNodePersister(store, db, 'my_tinybase');
|
|
144
|
+
*
|
|
145
|
+
* await persister.save();
|
|
146
|
+
* // Store will be saved to the database.
|
|
147
|
+
*
|
|
148
|
+
* console.log(db.prepare('SELECT * FROM my_tinybase;').all());
|
|
149
|
+
* // -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
|
|
150
|
+
*
|
|
151
|
+
* db.prepare('UPDATE my_tinybase SET store = ? WHERE _id = ?;').run(
|
|
152
|
+
* '[{"pets":{"felix":{"species":"cat"}}},{}]',
|
|
153
|
+
* '_',
|
|
154
|
+
* );
|
|
155
|
+
* await persister.load();
|
|
156
|
+
* console.log(store.getTables());
|
|
157
|
+
* // -> {pets: {felix: {species: 'cat'}}}
|
|
158
|
+
*
|
|
159
|
+
* await persister.destroy();
|
|
160
|
+
* db.close();
|
|
161
|
+
* ```
|
|
162
|
+
* @example
|
|
163
|
+
* This example creates a SqliteNodePersister object and persists the Store to a
|
|
164
|
+
* local SQLite database with tabular mapping.
|
|
165
|
+
*
|
|
166
|
+
* ```js
|
|
167
|
+
* import {DatabaseSync} from 'node:sqlite';
|
|
168
|
+
* import {createStore} from 'tinybase';
|
|
169
|
+
* import {createSqliteNodePersister} from 'tinybase/persisters/persister-sqlite-node';
|
|
170
|
+
*
|
|
171
|
+
* const db = new DatabaseSync(':memory:');
|
|
172
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
173
|
+
* const persister = createSqliteNodePersister(store, db, {
|
|
174
|
+
* mode: 'tabular',
|
|
175
|
+
* tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
|
|
176
|
+
* });
|
|
177
|
+
*
|
|
178
|
+
* await persister.save();
|
|
179
|
+
* console.log(db.prepare('SELECT * FROM pets;').all());
|
|
180
|
+
* // -> [{_id: 'fido', species: 'dog'}]
|
|
181
|
+
*
|
|
182
|
+
* db.prepare(
|
|
183
|
+
* `INSERT INTO pets (_id, species) VALUES ('felix', 'cat')`,
|
|
184
|
+
* ).run();
|
|
185
|
+
* await persister.load();
|
|
186
|
+
* console.log(store.getTables());
|
|
187
|
+
* // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
|
|
188
|
+
*
|
|
189
|
+
* await persister.destroy();
|
|
190
|
+
* db.close();
|
|
191
|
+
* ```
|
|
192
|
+
* @category Creation
|
|
193
|
+
* @since 9.7.0
|
|
194
|
+
*/
|
|
195
|
+
export function createSqliteNodePersister<Schemas extends OptionalSchemas>(
|
|
196
|
+
store: MergeableStore<Schemas>,
|
|
197
|
+
db: DatabaseSync,
|
|
198
|
+
configOrStoreTableName?: DpcJson | string,
|
|
199
|
+
onSqlCommand?: (sql: string, params?: any[]) => void,
|
|
200
|
+
onIgnoredError?: (error: any) => void,
|
|
201
|
+
): SqliteNodePersister<Schemas>;
|
|
202
|
+
export function createSqliteNodePersister<Schemas extends OptionalSchemas>(
|
|
203
|
+
store: Store<Schemas> & {getMergeableContent?: never},
|
|
204
|
+
db: DatabaseSync,
|
|
205
|
+
configOrStoreTableName?: DatabasePersisterConfig<Schemas> | string,
|
|
206
|
+
onSqlCommand?: (sql: string, params?: any[]) => void,
|
|
207
|
+
onIgnoredError?: (error: any) => void,
|
|
208
|
+
): SqliteNodePersister<Schemas>;
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
* The persister-sqlite3 module of the TinyBase project lets you save and load
|
|
3
3
|
* Store data to and from a local SQLite database (in an appropriate
|
|
4
4
|
* environment).
|
|
5
|
+
*
|
|
6
|
+
* This module is deprecated as of v9.7.0 and will be removed in v10.0.0. The
|
|
7
|
+
* `sqlite3` module that it binds to is no longer maintained, and SQLite is now
|
|
8
|
+
* built into Node.js itself, so you should use the persister-sqlite-node module
|
|
9
|
+
* and its SqliteNodePersister instead. The BetterSqlite3Persister is a good
|
|
10
|
+
* alternative if you need to support versions of Node.js that predate the
|
|
11
|
+
* built-in `node:sqlite` module.
|
|
12
|
+
* @deprecated Use the persister-sqlite-node module instead. This module will be
|
|
13
|
+
* removed in v10.0.0.
|
|
5
14
|
* @see Database Persistence guide
|
|
6
15
|
* @packageDocumentation
|
|
7
16
|
* @module persister-sqlite3
|
|
@@ -63,6 +72,9 @@ export interface Sqlite3Persister extends Persister<Persists.StoreOrMergeableSto
|
|
|
63
72
|
* The createSqlite3Persister function creates a Sqlite3Persister object that
|
|
64
73
|
* can persist the Store to a local SQLite database.
|
|
65
74
|
*
|
|
75
|
+
* This function is deprecated as of v9.7.0 and will be removed in v10.0.0. Use
|
|
76
|
+
* the createSqliteNodePersister function instead.
|
|
77
|
+
*
|
|
66
78
|
* A Sqlite3Persister supports regular Store objects, and can also be used to
|
|
67
79
|
* persist the metadata of a MergeableStore when using the JSON serialization
|
|
68
80
|
* mode, as described below.
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
* The persister-sqlite3 module of the TinyBase project lets you save and load
|
|
3
3
|
* Store data to and from a local SQLite database (in an appropriate
|
|
4
4
|
* environment).
|
|
5
|
+
*
|
|
6
|
+
* This module is deprecated as of v9.7.0 and will be removed in v10.0.0. The
|
|
7
|
+
* `sqlite3` module that it binds to is no longer maintained, and SQLite is now
|
|
8
|
+
* built into Node.js itself, so you should use the persister-sqlite-node module
|
|
9
|
+
* and its SqliteNodePersister instead. The BetterSqlite3Persister is a good
|
|
10
|
+
* alternative if you need to support versions of Node.js that predate the
|
|
11
|
+
* built-in `node:sqlite` module.
|
|
12
|
+
* @deprecated Use the persister-sqlite-node module instead. This module will be
|
|
13
|
+
* removed in v10.0.0.
|
|
5
14
|
* @see Database Persistence guide
|
|
6
15
|
* @packageDocumentation
|
|
7
16
|
* @module persister-sqlite3
|
|
@@ -84,6 +93,9 @@ export interface Sqlite3Persister<
|
|
|
84
93
|
* ): Sqlite3Persister;
|
|
85
94
|
* ```
|
|
86
95
|
*
|
|
96
|
+
* This function is deprecated as of v9.7.0 and will be removed in v10.0.0. Use
|
|
97
|
+
* the createSqliteNodePersister function instead.
|
|
98
|
+
*
|
|
87
99
|
* A Sqlite3Persister supports regular Store objects, and can also be used to
|
|
88
100
|
* persist the metadata of a MergeableStore when using the JSON serialization
|
|
89
101
|
* mode, as described below.
|
|
@@ -692,7 +692,7 @@ export type SortedTablePaginatorProps = {
|
|
|
692
692
|
*
|
|
693
693
|
* See the <TableInHtmlTable /> (React) demo for this component in action:
|
|
694
694
|
*
|
|
695
|
-
* 
|
|
697
697
|
*
|
|
698
698
|
* The component's props identify which Table to render based on Table Id, and
|
|
@@ -838,7 +838,7 @@ export function TableInHtmlTable(
|
|
|
838
838
|
* See the <SortedTableInHtmlTable /> (React) demo for this component in
|
|
839
839
|
* action:
|
|
840
840
|
*
|
|
841
|
-
* 
|
|
843
843
|
*
|
|
844
844
|
* The component's props identify which Table to render based on Table Id, and
|
|
@@ -1011,7 +1011,7 @@ export function SortedTableInHtmlTable(
|
|
|
1011
1011
|
*
|
|
1012
1012
|
* See the <ValuesInHtmlTable /> (React) demo for this component in action:
|
|
1013
1013
|
*
|
|
1014
|
-
* 
|
|
1016
1016
|
*
|
|
1017
1017
|
* The component's props identify which Row to render based on Table Id, Row Id,
|
|
@@ -1142,7 +1142,7 @@ export function ValuesInHtmlTable(
|
|
|
1142
1142
|
*
|
|
1143
1143
|
* See the <SliceInHtmlTable /> (React) demo for this component in action:
|
|
1144
1144
|
*
|
|
1145
|
-
* 
|
|
1147
1147
|
*
|
|
1148
1148
|
* The component's props identify which Slice to render based on Index Id, Slice
|
|
@@ -1300,7 +1300,7 @@ export function SliceInHtmlTable(
|
|
|
1300
1300
|
* See the <RelationshipInHtmlTable /> (React) demo for this component in
|
|
1301
1301
|
* action:
|
|
1302
1302
|
*
|
|
1303
|
-
* 
|
|
1305
1305
|
*
|
|
1306
1306
|
* The component's props identify which Relationship to render based on
|
|
@@ -1478,7 +1478,7 @@ export function RelationshipInHtmlTable(
|
|
|
1478
1478
|
* See the <ResultTableInHtmlTable /> (React) demo for this component in
|
|
1479
1479
|
* action:
|
|
1480
1480
|
*
|
|
1481
|
-
* 
|
|
1483
1483
|
*
|
|
1484
1484
|
* The component's props identify which ResultTable to render based on query Id,
|
|
@@ -1631,7 +1631,7 @@ export function ResultTableInHtmlTable(
|
|
|
1631
1631
|
* See the <ResultSortedTableInHtmlTable /> (React) demo for this component in
|
|
1632
1632
|
* action:
|
|
1633
1633
|
*
|
|
1634
|
-
* 
|
|
1636
1636
|
*
|
|
1637
1637
|
* The component's props identify which ResultTable to render based on query Id,
|
|
@@ -1805,7 +1805,7 @@ export function ResultSortedTableInHtmlTable(
|
|
|
1805
1805
|
*
|
|
1806
1806
|
* See the <EditableCellView /> (React) demo for this component in action:
|
|
1807
1807
|
*
|
|
1808
|
-
* 
|
|
1810
1810
|
*
|
|
1811
1811
|
* The component's props identify which Cell to render based on Table Id, Row
|
|
@@ -1876,7 +1876,7 @@ export function EditableCellView(
|
|
|
1876
1876
|
*
|
|
1877
1877
|
* See the <EditableValueView /> (React) demo for this component in action:
|
|
1878
1878
|
*
|
|
1879
|
-
* 
|
|
1881
1881
|
*
|
|
1882
1882
|
* The component's props identify which Value to render based on Table Id, Row
|
|
@@ -1947,7 +1947,7 @@ export function EditableValueView(
|
|
|
1947
1947
|
* See the <SortedTableInHtmlTable /> (React) demo for this component in
|
|
1948
1948
|
* action:
|
|
1949
1949
|
*
|
|
1950
|
-
* 
|
|
1952
1952
|
*
|
|
1953
1953
|
* The component displays 'previous' and 'next' buttons for paging through the
|