tinybase 6.1.0-beta.2 → 6.1.0-beta.4

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.
@@ -27,6 +27,18 @@ import type {
27
27
  ValueOrUndefined,
28
28
  } from '../store/index.d.ts';
29
29
 
30
+ /**
31
+ * The GetNow type is used to represent a function that returns the current time
32
+ * in milliseconds.
33
+ *
34
+ * This is used internally within the mergeable-store module, but is used for
35
+ * the createMergeableStore function's second optional argument to allow
36
+ * applications to override the clock used to generate timestamps.
37
+ * @category Stamps
38
+ * @since v6.1.0
39
+ */
40
+ export type GetNow = () => number;
41
+
30
42
  /**
31
43
  * The Hash type is used within the mergeable-store module to quickly compare
32
44
  * the content of two objects.
@@ -328,7 +340,7 @@ export interface MergeableStore extends Store {
328
340
  * ```js
329
341
  * import {createMergeableStore} from 'tinybase';
330
342
  *
331
- * const store = createMergeableStore('store1'); // !resetHlc
343
+ * const store = createMergeableStore('store1'); // !reset
332
344
  *
333
345
  * store.setCell('pets', 'fido', 'color', 'brown');
334
346
  *
@@ -380,7 +392,7 @@ export interface MergeableStore extends Store {
380
392
  * ```js
381
393
  * import {createMergeableStore} from 'tinybase';
382
394
  *
383
- * const store = createMergeableStore('store1'); // !resetHlc
395
+ * const store = createMergeableStore('store1'); // !reset
384
396
  *
385
397
  * store.setCell('pets', 'fido', 'color', 'brown');
386
398
  * console.log(store.getMergeableContentHashes());
@@ -414,7 +426,7 @@ export interface MergeableStore extends Store {
414
426
  * ```js
415
427
  * import {createMergeableStore} from 'tinybase';
416
428
  *
417
- * const store = createMergeableStore('store1'); // !resetHlc
429
+ * const store = createMergeableStore('store1'); // !reset
418
430
  *
419
431
  * store.setCell('pets', 'fido', 'color', 'brown');
420
432
  * console.log(store.getMergeableTableHashes());
@@ -447,7 +459,7 @@ export interface MergeableStore extends Store {
447
459
  * ```js
448
460
  * import {createMergeableStore} from 'tinybase';
449
461
  *
450
- * const store1 = createMergeableStore('store1'); // !resetHlc
462
+ * const store1 = createMergeableStore('store1'); // !reset
451
463
  * store1.setTables({pets: {fido: {color: 'brown'}}});
452
464
  *
453
465
  * const store2 = createMergeableStore('store2');
@@ -500,7 +512,7 @@ export interface MergeableStore extends Store {
500
512
  * ```js
501
513
  * import {createMergeableStore} from 'tinybase';
502
514
  *
503
- * const store1 = createMergeableStore('store1'); // !resetHlc
515
+ * const store1 = createMergeableStore('store1'); // !reset
504
516
  * store1.setTables({pets: {fido: {color: 'brown'}, felix: {color: 'tan'}}});
505
517
  *
506
518
  * const store2 = createMergeableStore('store2');
@@ -536,7 +548,7 @@ export interface MergeableStore extends Store {
536
548
  * ```js
537
549
  * import {createMergeableStore} from 'tinybase';
538
550
  *
539
- * const store1 = createMergeableStore('store1'); // !resetHlc
551
+ * const store1 = createMergeableStore('store1'); // !reset
540
552
  * store1.setTables({pets: {fido: {color: 'brown'}}});
541
553
  *
542
554
  * const store2 = createMergeableStore('store2');
@@ -594,7 +606,7 @@ export interface MergeableStore extends Store {
594
606
  * ```js
595
607
  * import {createMergeableStore} from 'tinybase';
596
608
  *
597
- * const store1 = createMergeableStore('store1'); // !resetHlc
609
+ * const store1 = createMergeableStore('store1'); // !reset
598
610
  * store1.setTables({pets: {fido: {color: 'brown', species: 'dog'}}});
599
611
  *
600
612
  * const store2 = createMergeableStore('store2');
@@ -634,7 +646,7 @@ export interface MergeableStore extends Store {
634
646
  * ```js
635
647
  * import {createMergeableStore} from 'tinybase';
636
648
  *
637
- * const store1 = createMergeableStore('store1'); // !resetHlc
649
+ * const store1 = createMergeableStore('store1'); // !reset
638
650
  * store1.setTables({pets: {fido: {color: 'brown'}}});
639
651
  *
640
652
  * const store2 = createMergeableStore('store2');
@@ -710,7 +722,7 @@ export interface MergeableStore extends Store {
710
722
  * ```js
711
723
  * import {createMergeableStore} from 'tinybase';
712
724
  *
713
- * const store = createMergeableStore('store1'); // !resetHlc
725
+ * const store = createMergeableStore('store1'); // !reset
714
726
  *
715
727
  * store.setValue('employees', 3);
716
728
  * console.log(store.getMergeableValueHashes());
@@ -743,7 +755,7 @@ export interface MergeableStore extends Store {
743
755
  * ```js
744
756
  * import {createMergeableStore} from 'tinybase';
745
757
  *
746
- * const store1 = createMergeableStore('store1'); // !resetHlc
758
+ * const store1 = createMergeableStore('store1'); // !reset
747
759
  * store1.setValues({employees: 3});
748
760
  *
749
761
  * const store2 = createMergeableStore('store2');
@@ -788,7 +800,7 @@ export interface MergeableStore extends Store {
788
800
  * ```js
789
801
  * import {createMergeableStore} from 'tinybase';
790
802
  *
791
- * const store1 = createMergeableStore('store1'); // !resetHlc
803
+ * const store1 = createMergeableStore('store1'); // !reset
792
804
  * store1.setValues({employees: 3});
793
805
  * console.log(store1.getMergeableContent());
794
806
  * // ->
@@ -836,7 +848,7 @@ export interface MergeableStore extends Store {
836
848
  * ```js
837
849
  * import {createMergeableStore} from 'tinybase';
838
850
  *
839
- * const store1 = createMergeableStore('store1'); // !resetHlc
851
+ * const store1 = createMergeableStore('store1'); // !reset
840
852
  * store1.setValues({employees: 3});
841
853
  *
842
854
  * const store2 = createMergeableStore('store2');
@@ -870,7 +882,7 @@ export interface MergeableStore extends Store {
870
882
  * ```js
871
883
  * import {createMergeableStore} from 'tinybase';
872
884
  *
873
- * const store = createMergeableStore('store1'); // !resetHlc
885
+ * const store = createMergeableStore('store1'); // !reset
874
886
  * store.setTables({pets: {fido: {species: 'dog', color: 'brown'}}});
875
887
  * store.setValues({open: true});
876
888
  *
@@ -1034,12 +1046,22 @@ export interface MergeableStore extends Store {
1034
1046
  * The createMergeableStore function creates a MergeableStore, and is the main
1035
1047
  * entry point into the mergeable-store module.
1036
1048
  *
1037
- * There is one optional parameter which is a uniqueId for the MergeableStore.
1038
- * This is used to distinguish conflicting changes made in the same millisecond
1039
- * by two different MergeableStore objects as its hash is added to the end of
1040
- * the HLC timestamps. Generally this can be omitted unless you have a need for
1041
- * deterministic HLCs, such as in a testing scenario. Otherwise, TinyBase will
1042
- * assign a unique Id to the Store at the time of creation.
1049
+ * There are two optional parameters which are only for testing and advanced
1050
+ * usage.
1051
+ *
1052
+ * The first is a uniqueId for the MergeableStore, used to distinguish
1053
+ * conflicting changes made in the same millisecond by two different
1054
+ * MergeableStore objects as its hash is added to the end of the HLC timestamps.
1055
+ * Generally this can be omitted unless you have a need for deterministic HLCs,
1056
+ * such as in a testing scenario. Otherwise, TinyBase will assign a unique Id to
1057
+ * the Store at the time of creation.
1058
+ *
1059
+ * Since v6.1.0, the second is a function that can be used to replace the way
1060
+ * the timestamp is generated for HLCs (by default JavaScript's `Date.now()`
1061
+ * method).
1062
+ * @param uniqueId An optional unique Id for the MergeableStore.
1063
+ * @param getNow An optional function that generates millisecond timestamps,
1064
+ * since v6.1.0.
1043
1065
  * @returns A reference to the new MergeableStore.
1044
1066
  * @example
1045
1067
  * This example creates a MergeableStore.
@@ -1136,4 +1158,7 @@ export interface MergeableStore extends Store {
1136
1158
  * @category Creation
1137
1159
  * @since v5.0.0
1138
1160
  */
1139
- export function createMergeableStore(uniqueId?: Id): MergeableStore;
1161
+ export function createMergeableStore(
1162
+ uniqueId?: Id,
1163
+ getNow?: GetNow,
1164
+ ): MergeableStore;
@@ -40,6 +40,18 @@ import type {
40
40
  ValuesSchema,
41
41
  } from '../../store/with-schemas/index.d.ts';
42
42
 
43
+ /**
44
+ * The GetNow type is used to represent a function that returns the current time
45
+ * in milliseconds.
46
+ *
47
+ * This is used internally within the mergeable-store module, but is used for
48
+ * the createMergeableStore function's second optional argument to allow
49
+ * applications to override the clock used to generate timestamps.
50
+ * @category Stamps
51
+ * @since v6.1.0
52
+ */
53
+ export type GetNow = () => number;
54
+
43
55
  /**
44
56
  * The Hash type is used within the mergeable-store module to quickly compare
45
57
  * the content of two objects.
@@ -491,7 +503,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
491
503
  * ```js
492
504
  * import {createMergeableStore} from 'tinybase';
493
505
  *
494
- * const store = createMergeableStore('store1'); // !resetHlc
506
+ * const store = createMergeableStore('store1'); // !reset
495
507
  *
496
508
  * store.setCell('pets', 'fido', 'color', 'brown');
497
509
  *
@@ -543,7 +555,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
543
555
  * ```js
544
556
  * import {createMergeableStore} from 'tinybase';
545
557
  *
546
- * const store = createMergeableStore('store1'); // !resetHlc
558
+ * const store = createMergeableStore('store1'); // !reset
547
559
  *
548
560
  * store.setCell('pets', 'fido', 'color', 'brown');
549
561
  * console.log(store.getMergeableContentHashes());
@@ -583,7 +595,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
583
595
  * ```js
584
596
  * import {createMergeableStore} from 'tinybase';
585
597
  *
586
- * const store = createMergeableStore('store1'); // !resetHlc
598
+ * const store = createMergeableStore('store1'); // !reset
587
599
  *
588
600
  * store.setCell('pets', 'fido', 'color', 'brown');
589
601
  * console.log(store.getMergeableTableHashes());
@@ -624,7 +636,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
624
636
  * ```js
625
637
  * import {createMergeableStore} from 'tinybase';
626
638
  *
627
- * const store1 = createMergeableStore('store1'); // !resetHlc
639
+ * const store1 = createMergeableStore('store1'); // !reset
628
640
  * store1.setTables({pets: {fido: {color: 'brown'}}});
629
641
  *
630
642
  * const store2 = createMergeableStore('store2');
@@ -686,7 +698,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
686
698
  * ```js
687
699
  * import {createMergeableStore} from 'tinybase';
688
700
  *
689
- * const store1 = createMergeableStore('store1'); // !resetHlc
701
+ * const store1 = createMergeableStore('store1'); // !reset
690
702
  * store1.setTables({pets: {fido: {color: 'brown'}, felix: {color: 'tan'}}});
691
703
  *
692
704
  * const store2 = createMergeableStore('store2');
@@ -732,7 +744,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
732
744
  * ```js
733
745
  * import {createMergeableStore} from 'tinybase';
734
746
  *
735
- * const store1 = createMergeableStore('store1'); // !resetHlc
747
+ * const store1 = createMergeableStore('store1'); // !reset
736
748
  * store1.setTables({pets: {fido: {color: 'brown'}}});
737
749
  *
738
750
  * const store2 = createMergeableStore('store2');
@@ -799,7 +811,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
799
811
  * ```js
800
812
  * import {createMergeableStore} from 'tinybase';
801
813
  *
802
- * const store1 = createMergeableStore('store1'); // !resetHlc
814
+ * const store1 = createMergeableStore('store1'); // !reset
803
815
  * store1.setTables({pets: {fido: {color: 'brown', species: 'dog'}}});
804
816
  *
805
817
  * const store2 = createMergeableStore('store2');
@@ -847,7 +859,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
847
859
  * ```js
848
860
  * import {createMergeableStore} from 'tinybase';
849
861
  *
850
- * const store1 = createMergeableStore('store1'); // !resetHlc
862
+ * const store1 = createMergeableStore('store1'); // !reset
851
863
  * store1.setTables({pets: {fido: {color: 'brown'}}});
852
864
  *
853
865
  * const store2 = createMergeableStore('store2');
@@ -931,7 +943,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
931
943
  * ```js
932
944
  * import {createMergeableStore} from 'tinybase';
933
945
  *
934
- * const store = createMergeableStore('store1'); // !resetHlc
946
+ * const store = createMergeableStore('store1'); // !reset
935
947
  *
936
948
  * store.setValue('employees', 3);
937
949
  * console.log(store.getMergeableValueHashes());
@@ -970,7 +982,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
970
982
  * ```js
971
983
  * import {createMergeableStore} from 'tinybase';
972
984
  *
973
- * const store1 = createMergeableStore('store1'); // !resetHlc
985
+ * const store1 = createMergeableStore('store1'); // !reset
974
986
  * store1.setValues({employees: 3});
975
987
  *
976
988
  * const store2 = createMergeableStore('store2');
@@ -1023,7 +1035,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
1023
1035
  * ```js
1024
1036
  * import {createMergeableStore} from 'tinybase';
1025
1037
  *
1026
- * const store1 = createMergeableStore('store1'); // !resetHlc
1038
+ * const store1 = createMergeableStore('store1'); // !reset
1027
1039
  * store1.setValues({employees: 3});
1028
1040
  * console.log(store1.getMergeableContent());
1029
1041
  * // ->
@@ -1079,7 +1091,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
1079
1091
  * ```js
1080
1092
  * import {createMergeableStore} from 'tinybase';
1081
1093
  *
1082
- * const store1 = createMergeableStore('store1'); // !resetHlc
1094
+ * const store1 = createMergeableStore('store1'); // !reset
1083
1095
  * store1.setValues({employees: 3});
1084
1096
  *
1085
1097
  * const store2 = createMergeableStore('store2');
@@ -1121,7 +1133,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
1121
1133
  * ```js
1122
1134
  * import {createMergeableStore} from 'tinybase';
1123
1135
  *
1124
- * const store = createMergeableStore('store1'); // !resetHlc
1136
+ * const store = createMergeableStore('store1'); // !reset
1125
1137
  * store.setTables({pets: {fido: {species: 'dog', color: 'brown'}}});
1126
1138
  * store.setValues({open: true});
1127
1139
  *
@@ -1520,15 +1532,28 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
1520
1532
  * This has schema-based typing. The following is a simplified representation:
1521
1533
  *
1522
1534
  * ```ts override
1523
- * createMergeableStore(uniqueId?: Id): MergeableStore;
1535
+ * createMergeableStore(
1536
+ * uniqueId?: Id,
1537
+ * getNow?: GetNow,
1538
+ * ): MergeableStore;
1524
1539
  * ```
1525
1540
  *
1526
- * There is one optional parameter which is a uniqueId for the MergeableStore.
1527
- * This is used to distinguish conflicting changes made in the same millisecond
1528
- * by two different MergeableStore objects as its hash is added to the end of
1529
- * the HLC timestamps. Generally this can be omitted unless you have a need for
1530
- * deterministic HLCs, such as in a testing scenario. Otherwise, TinyBase will
1531
- * assign a unique Id to the Store at the time of creation.
1541
+ * There are two optional parameters which are only for testing and advanced
1542
+ * usage.
1543
+ *
1544
+ * The first is a uniqueId for the MergeableStore, used to distinguish
1545
+ * conflicting changes made in the same millisecond by two different
1546
+ * MergeableStore objects as its hash is added to the end of the HLC timestamps.
1547
+ * Generally this can be omitted unless you have a need for deterministic HLCs,
1548
+ * such as in a testing scenario. Otherwise, TinyBase will assign a unique Id to
1549
+ * the Store at the time of creation.
1550
+ *
1551
+ * Since v6.1.0, the second is a function that can be used to replace the way
1552
+ * the timestamp is generated for HLCs (by default JavaScript's `Date.now()`
1553
+ * method).
1554
+ * @param uniqueId An optional unique Id for the MergeableStore.
1555
+ * @param getNow An optional function that generates millisecond timestamps,
1556
+ * since v6.1.0.
1532
1557
  * @returns A reference to the new MergeableStore.
1533
1558
  * @example
1534
1559
  * This example creates a MergeableStore.
@@ -1625,4 +1650,7 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
1625
1650
  * @category Creation
1626
1651
  * @since v5.0.0
1627
1652
  */
1628
- export function createMergeableStore(uniqueId?: Id): MergeableStore<NoSchemas>;
1653
+ export function createMergeableStore(
1654
+ uniqueId?: Id,
1655
+ getNow?: GetNow,
1656
+ ): MergeableStore<NoSchemas>;
@@ -17,6 +17,7 @@
17
17
  * |IndexedDbPersister|Browser IndexedDB|Yes|No
18
18
  * |RemotePersister|Remote server|Yes|No
19
19
  * |Sqlite3Persister|SQLite in Node, via [sqlite3](https://github.com/TryGhost/node-sqlite3)|Yes|Yes*
20
+ * |SqliteBunPersister| SQLite in Bun, via [bun:sqlite](https://bun.sh/docs/api/sqlite)|Yes|Yes*
20
21
  * |SqliteWasmPersister|SQLite in a browser, via [sqlite-wasm](https://github.com/tomayac/sqlite-wasm)|Yes|Yes*
21
22
  * |ExpoSqlitePersister|SQLite in React Native, via [expo-sqlite](https://github.com/expo/expo/tree/main/packages/expo-sqlite)|Yes|Yes*
22
23
  * |PostgresPersister|PostgreSQL, via [postgres](https://github.com/porsager/postgres)|Yes|Yes*
@@ -1710,7 +1711,7 @@ export type DatabaseChangeListener = (tableName: string) => void;
1710
1711
  * // -> '[{"pets":{"fido":{"species":"dog"}}},{}]'
1711
1712
  * storePersister.destroy();
1712
1713
  *
1713
- * const mergeableStore = createMergeableStore('mergeableStore1'); // !resetHlc
1714
+ * const mergeableStore = createMergeableStore('mergeableStore1'); // !reset
1714
1715
  * mergeableStore.setTables({pets: {fido: {species: 'dog'}}});
1715
1716
  * const mergeableStorePersister = createJsonPersister(mergeableStore);
1716
1717
  * await mergeableStorePersister.save();
@@ -0,0 +1,159 @@
1
+ /**
2
+ * The persister-sqlite-bun module of the TinyBase project lets you save and
3
+ * load Store data to and from a local Bun SQLite database (in an appropriate
4
+ * environment).
5
+ * @see Database Persistence guide
6
+ * @packageDocumentation
7
+ * @module persister-sqlite-bun
8
+ * @since v6.1.0
9
+ */
10
+ import type {Database} from 'bun:sqlite';
11
+ import type {MergeableStore} from '../../mergeable-store/index.d.ts';
12
+ import type {Store} from '../../store/index.d.ts';
13
+ import type {DatabasePersisterConfig, Persister, Persists} from '../index.d.ts';
14
+
15
+ /**
16
+ * The SqliteBunPersister interface represents a Persister that lets you save
17
+ * and load Store data to and from a local Bun SQLite database.
18
+ *
19
+ * You should use the createSqliteBunPersister function to create a
20
+ * SqliteBunPersister object.
21
+ *
22
+ * It is a minor extension to the Persister interface and simply provides an
23
+ * extra getDb method for accessing a reference to the database instance the
24
+ * Store is being persisted to.
25
+ * @category Persister
26
+ * @since v6.1.0
27
+ */
28
+ export interface SqliteBunPersister
29
+ extends Persister<Persists.StoreOrMergeableStore> {
30
+ /**
31
+ * The getDb method returns a reference to the database instance the Store is
32
+ * being persisted to.
33
+ * @returns A reference to the database instance.
34
+ * @example
35
+ * This example creates a Persister object against a newly-created Store and
36
+ * then gets the database instance back out again.
37
+ *
38
+ * ```js bun
39
+ * import {Database} from 'bun:sqlite';
40
+ * import {createStore} from 'tinybase';
41
+ * import {createSqliteBunPersister} from 'tinybase/persisters/persister-sqlite-bun';
42
+ *
43
+ * const db = new Database(':memory:');
44
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
45
+ * const persister = createSqliteBunPersister(store, db, 'my_tinybase');
46
+ *
47
+ * console.log(persister.getDb() == db);
48
+ * // -> true
49
+ *
50
+ * persister.destroy();
51
+ * ```
52
+ * @category Getter
53
+ * @since v6.1.0
54
+ */
55
+ getDb(): Database;
56
+ }
57
+
58
+ /**
59
+ * The createSqliteBunPersister function creates a SqliteBunPersister object
60
+ * that can persist the Store to a local Bun SQLite database.
61
+ *
62
+ * A SqliteBunPersister supports regular Store objects, and can also be used to
63
+ * persist the metadata of a MergeableStore when using the JSON serialization
64
+ * mode, as described below.
65
+ *
66
+ * As well as providing a reference to the Store to persist, you must provide a
67
+ * `db` parameter which identifies the database instance.
68
+ *
69
+ * A database Persister uses one of two modes: either a JSON serialization of
70
+ * the whole Store stored in a single row of a table (the default), or a tabular
71
+ * mapping of Table Ids to database table names and vice-versa).
72
+ *
73
+ * The third argument is a DatabasePersisterConfig object that configures which
74
+ * of those modes to use, and settings for each. If the third argument is simply
75
+ * a string, it is used as the `storeTableName` property of the JSON
76
+ * serialization.
77
+ *
78
+ * See the documentation for the DpcJson and DpcTabular types for more
79
+ * information on how both of those modes can be configured.
80
+ * @param store The Store or MergeableStore to persist.
81
+ * @param db The database instance that was returned from `new Database(...)`.
82
+ * @param configOrStoreTableName A DatabasePersisterConfig to configure the
83
+ * persistence mode (or a string to set the `storeTableName` property of the
84
+ * JSON serialization).
85
+ * @param onSqlCommand An optional handler called every time the Persister
86
+ * executes a SQL command or query. This is suitable for logging persistence
87
+ * behavior in a development environment.
88
+ * @param onIgnoredError An optional handler for the errors that the Persister
89
+ * would otherwise ignore when trying to save or load data. This is suitable for
90
+ * debugging persistence issues in a development environment.
91
+ * @returns A reference to the new SqliteBunPersister object.
92
+ * @example
93
+ * This example creates a SqliteBunPersister object and persists the Store to a
94
+ * local SQLite database as a JSON serialization into the `my_tinybase` table.
95
+ * It makes a change to the database directly and then reloads it back into the
96
+ * Store.
97
+ *
98
+ * ```js bun
99
+ * import {Database} from 'bun:sqlite';
100
+ * import {createStore} from 'tinybase';
101
+ * import {createSqliteBunPersister} from 'tinybase/persisters/persister-sqlite-bun';
102
+ *
103
+ * const db = new Database(':memory:');
104
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
105
+ * const persister = createSqliteBunPersister(store, db, 'my_tinybase');
106
+ *
107
+ * await persister.save();
108
+ * // Store will be saved to the database.
109
+ *
110
+ * console.log(db.query('SELECT * FROM my_tinybase;').all());
111
+ * // -> [{_id: '_', store: '[{"pets":{"fido":{"species":"dog"}}},{}]'}]
112
+ *
113
+ * db.query(
114
+ * 'UPDATE my_tinybase SET store = ' +
115
+ * `'[{"pets":{"felix":{"species":"cat"}}},{}]' WHERE _id = '_';`,
116
+ * ).run();
117
+ * await persister.load();
118
+ * console.log(store.getTables());
119
+ * // -> {pets: {felix: {species: 'cat'}}}
120
+ *
121
+ * persister.destroy();
122
+ * ```
123
+ * @example
124
+ * This example creates a SqliteBunPersister object and persists the Store to a
125
+ * local SQLite database with tabular mapping.
126
+ *
127
+ * ```js bun
128
+ * import {Database} from 'bun:sqlite';
129
+ * import {createStore} from 'tinybase';
130
+ * import {createSqliteBunPersister} from 'tinybase/persisters/persister-sqlite-bun';
131
+ *
132
+ * const db = new Database(':memory:');
133
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
134
+ * const persister = createSqliteBunPersister(store, db, {
135
+ * mode: 'tabular',
136
+ * tables: {load: {pets: 'pets'}, save: {pets: 'pets'}},
137
+ * });
138
+ *
139
+ * await persister.save();
140
+ * console.log(db.query('SELECT * FROM pets;').all());
141
+ * // -> [{_id: 'fido', species: 'dog'}]
142
+ *
143
+ * db.query(`INSERT INTO pets (_id, species) VALUES ('felix', 'cat')`).run();
144
+ * await persister.load();
145
+ * console.log(store.getTables());
146
+ * // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
147
+ *
148
+ * persister.destroy();
149
+ * ```
150
+ * @category Creation
151
+ * @since v6.1.0
152
+ */
153
+ export function createSqliteBunPersister(
154
+ store: Store | MergeableStore,
155
+ db: Database,
156
+ configOrStoreTableName?: DatabasePersisterConfig | string,
157
+ onSqlCommand?: (sql: string, params?: any[]) => void,
158
+ onIgnoredError?: (error: any) => void,
159
+ ): SqliteBunPersister;