@syncular/dialect-better-sqlite3 0.0.1-60

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.
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @syncular/dialect-better-sqlite3 - better-sqlite3 dialect for sync
3
+ *
4
+ * Provides a Kysely dialect for better-sqlite3 (Node.js) with SerializePlugin
5
+ * for automatic JSON serialization/deserialization.
6
+ * SQLite-compatible — use with @syncular/server-dialect-sqlite.
7
+ */
8
+ import { SerializePlugin } from '@syncular/core';
9
+ import type { Database as BetterSqlite3Database } from 'better-sqlite3';
10
+ import { Kysely } from 'kysely';
11
+ interface BetterSqlite3PathOptions {
12
+ /** Path to SQLite database file, or ':memory:' for in-memory */
13
+ path: string;
14
+ }
15
+ interface BetterSqlite3InstanceOptions {
16
+ /** An existing better-sqlite3 Database instance */
17
+ database: BetterSqlite3Database;
18
+ }
19
+ type BetterSqlite3Options = BetterSqlite3PathOptions | BetterSqlite3InstanceOptions;
20
+ /**
21
+ * Create a Kysely instance with better-sqlite3 dialect and SerializePlugin.
22
+ *
23
+ * @example
24
+ * const db = createBetterSqlite3Db<MyDb>({ path: './data.db' });
25
+ * const db = createBetterSqlite3Db<MyDb>({ path: ':memory:' });
26
+ *
27
+ * // Existing instance
28
+ * import Database from 'better-sqlite3';
29
+ * const db = createBetterSqlite3Db<MyDb>({ database: new Database(':memory:') });
30
+ */
31
+ export declare function createBetterSqlite3Db<T>(options: BetterSqlite3Options): Kysely<T>;
32
+ export declare function createSerializePlugin(): SerializePlugin;
33
+ export {};
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,IAAI,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAExE,OAAO,EAAE,MAAM,EAAiB,MAAM,QAAQ,CAAC;AAE/C,UAAU,wBAAwB;IAChC,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,4BAA4B;IACpC,mDAAmD;IACnD,QAAQ,EAAE,qBAAqB,CAAC;CACjC;AAED,KAAK,oBAAoB,GACrB,wBAAwB,GACxB,4BAA4B,CAAC;AAEjC;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,OAAO,EAAE,oBAAoB,GAC5B,MAAM,CAAC,CAAC,CAAC,CAKX;AAaD,wBAAgB,qBAAqB,IAAI,eAAe,CAEvD"}
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @syncular/dialect-better-sqlite3 - better-sqlite3 dialect for sync
3
+ *
4
+ * Provides a Kysely dialect for better-sqlite3 (Node.js) with SerializePlugin
5
+ * for automatic JSON serialization/deserialization.
6
+ * SQLite-compatible — use with @syncular/server-dialect-sqlite.
7
+ */
8
+ import { SerializePlugin } from '@syncular/core';
9
+ import Database from 'better-sqlite3';
10
+ import { Kysely, SqliteDialect } from 'kysely';
11
+ /**
12
+ * Create a Kysely instance with better-sqlite3 dialect and SerializePlugin.
13
+ *
14
+ * @example
15
+ * const db = createBetterSqlite3Db<MyDb>({ path: './data.db' });
16
+ * const db = createBetterSqlite3Db<MyDb>({ path: ':memory:' });
17
+ *
18
+ * // Existing instance
19
+ * import Database from 'better-sqlite3';
20
+ * const db = createBetterSqlite3Db<MyDb>({ database: new Database(':memory:') });
21
+ */
22
+ export function createBetterSqlite3Db(options) {
23
+ return new Kysely({
24
+ dialect: createBetterSqlite3Dialect(options),
25
+ plugins: [new SerializePlugin()],
26
+ });
27
+ }
28
+ /**
29
+ * Create the better-sqlite3 dialect directly (without SerializePlugin).
30
+ */
31
+ function createBetterSqlite3Dialect(options) {
32
+ const database = 'database' in options ? options.database : new Database(options.path);
33
+ return new SqliteDialect({ database });
34
+ }
35
+ export function createSerializePlugin() {
36
+ return new SerializePlugin();
37
+ }
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAgB/C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAA6B,EAClB;IACX,OAAO,IAAI,MAAM,CAAI;QACnB,OAAO,EAAE,0BAA0B,CAAC,OAAO,CAAC;QAC5C,OAAO,EAAE,CAAC,IAAI,eAAe,EAAE,CAAC;KACjC,CAAC,CAAC;AAAA,CACJ;AAED;;GAEG;AACH,SAAS,0BAA0B,CACjC,OAA6B,EACd;IACf,MAAM,QAAQ,GACZ,UAAU,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,OAAO,IAAI,aAAa,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;AAAA,CACxC;AAED,MAAM,UAAU,qBAAqB,GAAoB;IACvD,OAAO,IAAI,eAAe,EAAE,CAAC;AAAA,CAC9B"}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@syncular/dialect-better-sqlite3",
3
+ "version": "0.0.1-60",
4
+ "description": "better-sqlite3 dialect for the Syncular client",
5
+ "license": "MIT",
6
+ "author": "Benjamin Kniffler",
7
+ "homepage": "https://syncular.dev",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/syncular/syncular.git",
11
+ "directory": "packages/dialect-better-sqlite3"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/syncular/syncular/issues"
15
+ },
16
+ "keywords": [
17
+ "sync",
18
+ "offline-first",
19
+ "realtime",
20
+ "database",
21
+ "typescript",
22
+ "better-sqlite3",
23
+ "sqlite"
24
+ ],
25
+ "private": false,
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "type": "module",
30
+ "exports": {
31
+ ".": {
32
+ "bun": "./src/index.ts",
33
+ "import": {
34
+ "types": "./dist/index.d.ts",
35
+ "default": "./dist/index.js"
36
+ }
37
+ }
38
+ },
39
+ "scripts": {
40
+ "tsgo": "tsgo --noEmit",
41
+ "build": "rm -rf dist && tsgo",
42
+ "release": "bun pm pack --destination . && npm publish ./*.tgz --tag latest && rm -f ./*.tgz"
43
+ },
44
+ "dependencies": {
45
+ "@syncular/core": "0.0.1",
46
+ "@types/better-sqlite3": "^7.6.13",
47
+ "better-sqlite3": "^12.6.2"
48
+ },
49
+ "peerDependencies": {
50
+ "kysely": "^0.28.0"
51
+ },
52
+ "devDependencies": {
53
+ "@syncular/config": "0.0.0",
54
+ "kysely": "*"
55
+ },
56
+ "files": [
57
+ "dist",
58
+ "src"
59
+ ]
60
+ }
package/src/index.ts ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @syncular/dialect-better-sqlite3 - better-sqlite3 dialect for sync
3
+ *
4
+ * Provides a Kysely dialect for better-sqlite3 (Node.js) with SerializePlugin
5
+ * for automatic JSON serialization/deserialization.
6
+ * SQLite-compatible — use with @syncular/server-dialect-sqlite.
7
+ */
8
+
9
+ import { SerializePlugin } from '@syncular/core';
10
+ import type { Database as BetterSqlite3Database } from 'better-sqlite3';
11
+ import Database from 'better-sqlite3';
12
+ import { Kysely, SqliteDialect } from 'kysely';
13
+
14
+ interface BetterSqlite3PathOptions {
15
+ /** Path to SQLite database file, or ':memory:' for in-memory */
16
+ path: string;
17
+ }
18
+
19
+ interface BetterSqlite3InstanceOptions {
20
+ /** An existing better-sqlite3 Database instance */
21
+ database: BetterSqlite3Database;
22
+ }
23
+
24
+ type BetterSqlite3Options =
25
+ | BetterSqlite3PathOptions
26
+ | BetterSqlite3InstanceOptions;
27
+
28
+ /**
29
+ * Create a Kysely instance with better-sqlite3 dialect and SerializePlugin.
30
+ *
31
+ * @example
32
+ * const db = createBetterSqlite3Db<MyDb>({ path: './data.db' });
33
+ * const db = createBetterSqlite3Db<MyDb>({ path: ':memory:' });
34
+ *
35
+ * // Existing instance
36
+ * import Database from 'better-sqlite3';
37
+ * const db = createBetterSqlite3Db<MyDb>({ database: new Database(':memory:') });
38
+ */
39
+ export function createBetterSqlite3Db<T>(
40
+ options: BetterSqlite3Options
41
+ ): Kysely<T> {
42
+ return new Kysely<T>({
43
+ dialect: createBetterSqlite3Dialect(options),
44
+ plugins: [new SerializePlugin()],
45
+ });
46
+ }
47
+
48
+ /**
49
+ * Create the better-sqlite3 dialect directly (without SerializePlugin).
50
+ */
51
+ function createBetterSqlite3Dialect(
52
+ options: BetterSqlite3Options
53
+ ): SqliteDialect {
54
+ const database =
55
+ 'database' in options ? options.database : new Database(options.path);
56
+ return new SqliteDialect({ database });
57
+ }
58
+
59
+ export function createSerializePlugin(): SerializePlugin {
60
+ return new SerializePlugin();
61
+ }