@storyshelf/db-sqlite 0.1.0 → 0.1.2
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/LICENSE +21 -0
- package/dist/index.mjs +8 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +31 -22
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Siddhant Gupta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.mjs
CHANGED
|
@@ -10,6 +10,12 @@ import { DDL } from "@storyshelf/core/ddl";
|
|
|
10
10
|
function idOf(table) {
|
|
11
11
|
return getTableColumns(table)["id"];
|
|
12
12
|
}
|
|
13
|
+
function applyListOptions(query, opts) {
|
|
14
|
+
if (opts.where) query.where(opts.where);
|
|
15
|
+
if (opts.orderBy) query.orderBy(opts.orderBy);
|
|
16
|
+
if (opts.limit !== void 0) query.limit(opts.limit);
|
|
17
|
+
if (opts.offset !== void 0) query.offset(opts.offset);
|
|
18
|
+
}
|
|
13
19
|
/**
|
|
14
20
|
* Create a SQLite-backed DatabaseAdapter using better-sqlite3 and Drizzle ORM.
|
|
15
21
|
*
|
|
@@ -24,7 +30,7 @@ function createSqliteDatabase(path) {
|
|
|
24
30
|
return {
|
|
25
31
|
metadata: {
|
|
26
32
|
name: "SQLite",
|
|
27
|
-
version: "0.
|
|
33
|
+
version: globalThis.__PKG_VERSION__ ?? "0.0.0",
|
|
28
34
|
description: "SQLite database adapter (better-sqlite3 + Drizzle)",
|
|
29
35
|
kind: "sqlite"
|
|
30
36
|
},
|
|
@@ -42,10 +48,7 @@ function createSqliteDatabase(path) {
|
|
|
42
48
|
},
|
|
43
49
|
async list(table, opts = {}) {
|
|
44
50
|
const query = db.select().from(table);
|
|
45
|
-
|
|
46
|
-
if (opts.orderBy) query.orderBy(opts.orderBy);
|
|
47
|
-
if (opts.limit !== void 0) query.limit(opts.limit);
|
|
48
|
-
if (opts.offset !== void 0) query.offset(opts.offset);
|
|
51
|
+
applyListOptions(query, opts);
|
|
49
52
|
return query.all();
|
|
50
53
|
},
|
|
51
54
|
async count(table, where) {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { eq, getTableColumns } from \"drizzle-orm\";\nimport { drizzle } from \"drizzle-orm/better-sqlite3\";\nimport type { AnySQLiteTable, SQLiteColumn } from \"drizzle-orm/sqlite-core\";\nimport Database from \"better-sqlite3\";\n\nimport type { DatabaseAdapter, ListOptions } from \"@storyshelf/core/adapter/database\";\nimport { schema } from \"@storyshelf/core/schema\";\nimport { DDL } from \"@storyshelf/core/ddl\";\n\ndeclare const __PKG_VERSION__: string;\n\nfunction idOf(table: AnySQLiteTable): SQLiteColumn {\n // eslint-disable-next-line no-non-null-assertion -- every table has an `id` column\n return getTableColumns(table)[\"id\"]!;\n}\n\n/**\n * Create a SQLite-backed DatabaseAdapter using better-sqlite3 and Drizzle ORM.\n *\n * @param path - Filesystem path to the SQLite database file.\n * @returns A DatabaseAdapter backed by the given SQLite file (WAL mode).\n */\nexport function createSqliteDatabase(path: string): DatabaseAdapter {\n const sqlite = new Database(path);\n sqlite.pragma(\"journal_mode = WAL\");\n sqlite.pragma(\"busy_timeout = 5000\");\n const db = drizzle(sqlite, { schema });\n\n //
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { eq, getTableColumns } from \"drizzle-orm\";\nimport { drizzle } from \"drizzle-orm/better-sqlite3\";\nimport type { AnySQLiteTable, SQLiteColumn } from \"drizzle-orm/sqlite-core\";\nimport Database from \"better-sqlite3\";\n\nimport type { DatabaseAdapter, ListOptions } from \"@storyshelf/core/adapter/database\";\nimport { schema } from \"@storyshelf/core/schema\";\nimport { DDL } from \"@storyshelf/core/ddl\";\n\ndeclare const __PKG_VERSION__: string | undefined;\n\nfunction idOf(table: AnySQLiteTable): SQLiteColumn {\n // eslint-disable-next-line no-non-null-assertion -- every table has an `id` column\n return getTableColumns(table)[\"id\"]!;\n}\n\n/* eslint-disable typescript/no-explicit-any, typescript/no-unsafe-call, typescript/no-unsafe-member-access -- drizzle query builder is intentionally loosely typed */\nfunction applyListOptions(\n query: any,\n opts: ListOptions,\n): void {\n if (opts.where) {\n query.where(opts.where);\n }\n if (opts.orderBy) {\n query.orderBy(opts.orderBy);\n }\n if (opts.limit !== undefined) {\n query.limit(opts.limit);\n }\n if (opts.offset !== undefined) {\n query.offset(opts.offset);\n }\n}\n/* eslint-enable typescript/no-explicit-any, typescript/no-unsafe-call, typescript/no-unsafe-member-access */\n\n/**\n * Create a SQLite-backed DatabaseAdapter using better-sqlite3 and Drizzle ORM.\n *\n * @param path - Filesystem path to the SQLite database file.\n * @returns A DatabaseAdapter backed by the given SQLite file (WAL mode).\n */\nexport function createSqliteDatabase(path: string): DatabaseAdapter {\n const sqlite = new Database(path);\n sqlite.pragma(\"journal_mode = WAL\");\n sqlite.pragma(\"busy_timeout = 5000\");\n const db = drizzle(sqlite, { schema });\n\n // Better-sqlite3 is synchronous, so `async` is required only by the\n // DatabaseAdapter interface (no `await`), and drizzle's `.get()`/`[\"id\"]`\n // Are guaranteed present despite the undefined-able types. Both rules are\n // False positives here.\n /* eslint-disable require-await, no-non-null-assertion, no-unnecessary-type-assertion */\n return {\n metadata: {\n name: \"SQLite\",\n version: (globalThis as unknown as { __PKG_VERSION__?: string }).__PKG_VERSION__ ?? \"0.0.0\",\n description: \"SQLite database adapter (better-sqlite3 + Drizzle)\",\n kind: \"sqlite\",\n },\n async insert(table, values) {\n return db.insert(table).values(values).returning().get()!;\n },\n async update(table, id, values) {\n return db.update(table).set(values).where(eq(idOf(table), id)).returning().get()!;\n },\n async get(table, id) {\n return db.select().from(table).where(eq(idOf(table), id)).limit(1).get() ?? null;\n },\n async remove(table, id) {\n db.delete(table).where(eq(idOf(table), id)).run();\n },\n async list(table, opts: ListOptions = {}) {\n const query = db.select().from(table);\n applyListOptions(query, opts);\n return query.all();\n },\n async count(table, where) {\n return db.$count(table, where);\n },\n async all(query) {\n return db.all(query);\n },\n async migrate() {\n sqlite.exec(DDL);\n try {\n sqlite.exec(\"ALTER TABLE projects ADD COLUMN storybook_meta TEXT\");\n } catch {\n // Column already exists or other error — ignore for idempotency\n }\n },\n async close() {\n sqlite.close();\n },\n };\n /* eslint-enable require-await, no-non-null-assertion, no-unnecessary-type-assertion */\n}\n"],"mappings":";;;;;;;;;AAWA,SAAS,KAAK,OAAqC;CAEjD,OAAO,gBAAgB,KAAK,CAAC,CAAC;AAChC;AAGA,SAAS,iBACP,OACA,MACM;CACN,IAAI,KAAK,OACP,MA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MAAM,IAAI;EACnB;EACA,MAAM,MAAM,OAAO,OAAO;GACxB,OAAO,GAAG,OAAO,OAAO,KAAK;EAC/B;EACA,MAAM,IAAI,OAAO;GACf,OAAO,GAAG,IAAI,KAAK;EACrB;EACA,MAAM,UAAU;GACd,OAAO,KAAK,GAAG;GACf,IAAI;IACF,OAAO,KAAK,qDAAqD;GACnE,QAAQ,CAER;EACF;EACA,MAAM,QAAQ;GACZ,OAAO,MAAM;EACf;CACF;AAEF"}
|
package/package.json
CHANGED
|
@@ -1,43 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyshelf/db-sqlite",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "0.1.2",
|
|
5
4
|
"description": "SQLite database adapter for StoryShelf (better-sqlite3 + Drizzle).",
|
|
5
|
+
"homepage": "https://github.com/GuptaSiddhant/StoryShelf#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/GuptaSiddhant/StoryShelf/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
6
10
|
"author": {
|
|
7
11
|
"name": "Siddhant Gupta",
|
|
8
12
|
"url": "https://guptasiddhant.com"
|
|
9
13
|
},
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"sideEffects": false,
|
|
12
14
|
"repository": {
|
|
13
15
|
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/GuptaSiddhant/
|
|
16
|
+
"url": "git+https://github.com/GuptaSiddhant/StoryShelf.git",
|
|
15
17
|
"directory": "packages/db-sqlite"
|
|
16
18
|
},
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"types": "./dist/index.d.mts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"source": "./src/index.ts",
|
|
28
|
+
"default": "./dist/index.mjs"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
20
31
|
},
|
|
21
32
|
"publishConfig": {
|
|
22
|
-
"access": "public",
|
|
23
33
|
"exports": {
|
|
24
34
|
".": "./dist/index.mjs",
|
|
25
35
|
"./package.json": "./package.json"
|
|
26
|
-
}
|
|
36
|
+
},
|
|
37
|
+
"access": "public"
|
|
27
38
|
},
|
|
28
|
-
"files": [
|
|
29
|
-
"dist"
|
|
30
|
-
],
|
|
31
39
|
"scripts": {
|
|
32
40
|
"build": "tsdown",
|
|
33
41
|
"dev": "tsdown -w",
|
|
34
|
-
"fmt": "oxfmt
|
|
42
|
+
"fmt": "oxfmt ./src",
|
|
35
43
|
"lint": "oxlint --type-aware --type-check ./src",
|
|
36
44
|
"test": "vitest run",
|
|
37
45
|
"prepublishOnly": "nub run build"
|
|
38
46
|
},
|
|
39
47
|
"dependencies": {
|
|
40
|
-
"@storyshelf/core": "
|
|
48
|
+
"@storyshelf/core": "^0.1.2",
|
|
41
49
|
"better-sqlite3": "^12.4.1",
|
|
42
50
|
"drizzle-orm": "^0.44.0"
|
|
43
51
|
},
|
|
@@ -52,12 +60,13 @@
|
|
|
52
60
|
"typescript": "catalog:",
|
|
53
61
|
"vitest": "catalog:"
|
|
54
62
|
},
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
"jsr": {
|
|
64
|
+
"runtimeCompat": {
|
|
65
|
+
"node": true,
|
|
66
|
+
"deno": true,
|
|
67
|
+
"browser": false,
|
|
68
|
+
"workerd": false,
|
|
69
|
+
"bun": true
|
|
70
|
+
}
|
|
62
71
|
}
|
|
63
72
|
}
|