@statewalker/db-api 0.1.1
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/README.md +29 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +44 -0
- package/src/db.ts +25 -0
- package/src/index.ts +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mikhail Kotelnikov
|
|
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/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @statewalker/db-api
|
|
2
|
+
|
|
3
|
+
Minimal database client interface — query, execute, transaction primitives — consumed by every `@statewalker/db-*` driver.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @statewalker/db-api
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import type { DbClient } from "@statewalker/db-api";
|
|
15
|
+
|
|
16
|
+
async function listUsers(db: DbClient) {
|
|
17
|
+
return db.query("SELECT id, name FROM users");
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## API
|
|
22
|
+
|
|
23
|
+
- `DbClient` — driver-agnostic interface: `query`, `execute`, `transaction`.
|
|
24
|
+
- `Row`, `QueryResult` — result-shape types returned by drivers.
|
|
25
|
+
|
|
26
|
+
## Related
|
|
27
|
+
|
|
28
|
+
- `@statewalker/db-duckdb-browser` / `@statewalker/db-duckdb-node` — DuckDB drivers.
|
|
29
|
+
- `@statewalker/db-sqlite-browser` / `@statewalker/db-sqlite-node` — libSQL/SQLite drivers.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/db.d.ts
|
|
2
|
+
/** A plain record returned by queries when no specific type is provided. */
|
|
3
|
+
type DbEntry = Record<string, unknown>;
|
|
4
|
+
/** Minimal database interface — implementation-agnostic. */
|
|
5
|
+
type Db = {
|
|
6
|
+
/** Execute a SQL query and return rows as typed objects. */
|
|
7
|
+
query<T = DbEntry>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
8
|
+
/** Execute a SQL statement that returns no rows (DDL / DML). */
|
|
9
|
+
exec(sql: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Flush committed writes to durable storage. For backends that buffer (e.g.
|
|
12
|
+
* DuckDB-WASM over OPFS, which only writes its file on CHECKPOINT) this makes
|
|
13
|
+
* prior writes survive an abrupt teardown such as a page reload. Optional:
|
|
14
|
+
* in-memory or auto-syncing backends omit it.
|
|
15
|
+
*/
|
|
16
|
+
flush?(): Promise<void>;
|
|
17
|
+
/** Release all resources held by this database. */
|
|
18
|
+
close(): Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
/** Options accepted by every `newXxxDuckDb` factory. */
|
|
21
|
+
type DbOptions = {
|
|
22
|
+
/** File path (node) or OPFS path (browser). Omit for in-memory. */
|
|
23
|
+
path?: string;
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export type { Db, DbEntry, DbOptions };
|
|
27
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/db.ts"],"mappings":";;KACY,UAAU;;KAGV;;EAEV,MAAM,IAAI,SAAS,aAAa,qBAAqB,QAAQ;;EAE7D,KAAK,cAAc;;;;;;;EAOnB,UAAU;;EAEV,SAAS;;;KAIC;;EAEV"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@statewalker/db-api",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Minimal database client interface: query, execute, transaction primitives consumed by every @statewalker/db-* driver.",
|
|
7
|
+
"homepage": "https://github.com/statewalker/statewalker-db",
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "Mikhail Kotelnikov",
|
|
10
|
+
"email": "mikhail.kotelnikov@gmail.com"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+ssh://git@github.com/statewalker/statewalker-db.git"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./src/index.ts"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"src"
|
|
23
|
+
],
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"rimraf": "^6.1.3",
|
|
26
|
+
"tsdown": "^0.22.14",
|
|
27
|
+
"typescript": "^7.0.2",
|
|
28
|
+
"vitest": "^4.1.10"
|
|
29
|
+
},
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsdown",
|
|
36
|
+
"dev": "tsdown --watch",
|
|
37
|
+
"test": "vitest run --passWithNoTests",
|
|
38
|
+
"test:watch": "vitest",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"clean": "rimraf dist",
|
|
41
|
+
"lint": "biome check --write .",
|
|
42
|
+
"format": "biome format --write ."
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/db.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** A plain record returned by queries when no specific type is provided. */
|
|
2
|
+
export type DbEntry = Record<string, unknown>;
|
|
3
|
+
|
|
4
|
+
/** Minimal database interface — implementation-agnostic. */
|
|
5
|
+
export type Db = {
|
|
6
|
+
/** Execute a SQL query and return rows as typed objects. */
|
|
7
|
+
query<T = DbEntry>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
8
|
+
/** Execute a SQL statement that returns no rows (DDL / DML). */
|
|
9
|
+
exec(sql: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Flush committed writes to durable storage. For backends that buffer (e.g.
|
|
12
|
+
* DuckDB-WASM over OPFS, which only writes its file on CHECKPOINT) this makes
|
|
13
|
+
* prior writes survive an abrupt teardown such as a page reload. Optional:
|
|
14
|
+
* in-memory or auto-syncing backends omit it.
|
|
15
|
+
*/
|
|
16
|
+
flush?(): Promise<void>;
|
|
17
|
+
/** Release all resources held by this database. */
|
|
18
|
+
close(): Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Options accepted by every `newXxxDuckDb` factory. */
|
|
22
|
+
export type DbOptions = {
|
|
23
|
+
/** File path (node) or OPFS path (browser). Omit for in-memory. */
|
|
24
|
+
path?: string;
|
|
25
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { Db, DbEntry, DbOptions } from "./db.js";
|