Skip to content

Commit 0222465

Browse files
committed
[persisters] SqliteWasmPersister
1 parent 5b3b468 commit 0222465

File tree

4 files changed

+67
-12
lines changed

4 files changed

+67
-12
lines changed

src/persisters/persister-sqlite-wasm.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import {DatabasePersisterConfig, Persister} from '../types/persisters';
1+
import {
2+
SqliteWasmPersister,
3+
createSqliteWasmPersister as createSqliteWasmPersisterDecl,
4+
} from '../types/persisters/persister-sqlite-wasm';
25
import {UpdateListener, createSqlitePersister} from './sqlite/create';
6+
import {DatabasePersisterConfig} from '../types/persisters';
37
import {IdObj} from '../common/obj';
48
import {Store} from '../types/store';
5-
import {createSqliteWasmPersister as createSqliteWasmPersisterDecl} from '../types/persisters/persister-sqlite-wasm';
69

710
export const createSqliteWasmPersister = ((
811
store: Store,
@@ -11,7 +14,7 @@ export const createSqliteWasmPersister = ((
1114
configOrStoreTableName?: DatabasePersisterConfig | string,
1215
onSqlCommand?: (sql: string, args?: any[]) => void,
1316
onIgnoredError?: (error: any) => void,
14-
): Persister =>
17+
): SqliteWasmPersister =>
1518
createSqlitePersister(
1619
store,
1720
configOrStoreTableName,
@@ -29,4 +32,4 @@ export const createSqliteWasmPersister = ((
2932
onSqlCommand,
3033
onIgnoredError,
3134
db,
32-
)) as typeof createSqliteWasmPersisterDecl;
35+
) as SqliteWasmPersister) as typeof createSqliteWasmPersisterDecl;

src/types/docs/persisters/persister-sqlite-wasm.js

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,45 @@
88
* @since v4.0.0
99
*/
1010
/// persister-sqlite-wasm
11+
/**
12+
* The SqliteWasmPersister interface is a minor extension to the Persister
13+
* interface.
14+
*
15+
* It simply provides an extra getDb method for accessing a reference to the
16+
* database instance the Store is being persisted to.
17+
* @since v4.3.14
18+
*/
19+
/// SqliteWasmPersister
20+
{
21+
/**
22+
* The getDb method returns a reference to the database instance the Store is
23+
* being persisted to.
24+
* @returns A reference to the database instance.
25+
* @example
26+
* This example creates a Persister object against a newly-created Store and
27+
* then gets the database instance back out again.
28+
*
29+
* ```js
30+
* const sqlite3 = await sqlite3InitModule();
31+
* const db = new sqlite3.oo1.DB(':memory:', 'c');
32+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
33+
* const persister = createSqliteWasmPersister(
34+
* store,
35+
* sqlite3,
36+
* db,
37+
* 'my_tinybase',
38+
* );
39+
*
40+
* console.log(persister.getDb() == db);
41+
* // -> true
42+
*
43+
* persister.destroy();
44+
* ```
45+
* @category Getter
46+
* @since v4.3.14
47+
*/
48+
/// SqliteWasmPersister.getDb
49+
}
1150
/**
1251
* The createSqliteWasmPersister function creates a Persister object that can
1352
* persist the Store to a local SQLite database (in an appropriate environment).
@@ -40,11 +79,11 @@
4079
* @param onIgnoredError An optional handler for the errors that the Persister
4180
* would otherwise ignore when trying to save or load data. This is suitable for
4281
* debugging persistence issues in a development environment, since v4.0.4.
43-
* @returns A reference to the new Persister object.
82+
* @returns A reference to the new SqliteWasmPersister object.
4483
* @example
45-
* This example creates a Persister object and persists the Store to a local
46-
* SQLite database as a JSON serialization into the `my_tinybase` table. It
47-
* makes a change to the database directly and then reloads it back into the
84+
* This example creates a SqliteWasmPersister object and persists the Store to a
85+
* local SQLite database as a JSON serialization into the `my_tinybase` table.
86+
* It makes a change to the database directly and then reloads it back into the
4887
* Store.
4988
*
5089
* ```js
@@ -75,8 +114,8 @@
75114
* persister.destroy();
76115
* ```
77116
* @example
78-
* This example creates a Persister object and persists the Store to a local
79-
* SQLite database with tabular mapping.
117+
* This example creates a SqliteWasmPersister object and persists the Store to a
118+
* local SQLite database with tabular mapping.
80119
*
81120
* ```js
82121
* const sqlite3 = await sqlite3InitModule();

src/types/persisters/persister-sqlite-wasm.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
import {DatabasePersisterConfig, Persister} from '../persisters';
44
import {Store} from '../store';
55

6+
/// SqliteWasmPersister
7+
export interface SqliteWasmPersister extends Persister {
8+
/// SqliteWasmPersister.getDb
9+
getDb: () => any;
10+
}
11+
612
/// createSqliteWasmPersister
713
export function createSqliteWasmPersister(
814
store: Store,
@@ -11,4 +17,4 @@ export function createSqliteWasmPersister(
1117
configOrStoreTableName?: DatabasePersisterConfig | string,
1218
onSqlCommand?: (sql: string, args?: any[]) => void,
1319
onIgnoredError?: (error: any) => void,
14-
): Persister;
20+
): SqliteWasmPersister;

src/types/with-schemas/persisters/persister-sqlite-wasm.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
import {DatabasePersisterConfig, Persister} from '../persisters';
44
import {OptionalSchemas, Store} from '../store';
55

6+
/// SqliteWasmPersister
7+
export interface SqliteWasmPersister<Schemas extends OptionalSchemas>
8+
extends Persister<Schemas> {
9+
/// SqliteWasmPersister.getDb
10+
getDb: () => any;
11+
}
12+
613
/// createSqliteWasmPersister
714
export function createSqliteWasmPersister<Schemas extends OptionalSchemas>(
815
store: Store<Schemas>,
@@ -11,4 +18,4 @@ export function createSqliteWasmPersister<Schemas extends OptionalSchemas>(
1118
configOrStoreTableName?: DatabasePersisterConfig<Schemas> | string,
1219
onSqlCommand?: (sql: string, args?: any[]) => void,
1320
onIgnoredError?: (error: any) => void,
14-
): Persister<Schemas>;
21+
): SqliteWasmPersister<Schemas>;

0 commit comments

Comments
 (0)