tempest-db-js 0.1.0 β 0.2.0
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/README.md +70 -2
- package/dist/bin.cjs +1132 -0
- package/dist/bin.cjs.map +1 -0
- package/dist/bin.d.cts +27 -0
- package/dist/bin.d.ts +27 -0
- package/dist/bin.js +111 -0
- package/dist/bin.js.map +1 -0
- package/dist/{chunk-F36ZSQAN.js β chunk-AGDD7K3F.js} +461 -47
- package/dist/chunk-AGDD7K3F.js.map +1 -0
- package/dist/chunk-QMW4NKMH.js +1060 -0
- package/dist/chunk-QMW4NKMH.js.map +1 -0
- package/dist/index.cjs +467 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +293 -10
- package/dist/index.d.ts +293 -10
- package/dist/index.js +1 -1
- package/dist/migrations/index.cjs +143 -24
- package/dist/migrations/index.cjs.map +1 -1
- package/dist/migrations/index.d.cts +75 -1
- package/dist/migrations/index.d.ts +75 -1
- package/dist/migrations/index.js +2 -923
- package/dist/migrations/index.js.map +1 -1
- package/package.json +13 -5
- package/dist/chunk-F36ZSQAN.js.map +0 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
π **Documentation:** [PortuguΓͺs (BR)](https://mauriciobenjamin700.github.io/tempest-db-js/) Β· [English (US)](https://mauriciobenjamin700.github.io/tempest-db-js/en/)
|
|
7
7
|
|
|
8
|
-
>
|
|
8
|
+
> β
**Status: alpha (v0.2.0), published on [npm](https://www.npmjs.com/package/tempest-db-js).** The full path works end-to-end β declarative models, typed query builder (aggregations, `DISTINCT`, upsert), **real SQLite execution** (tested against `node:sqlite`), joins, relations, Alembic-style migrations + a `tempest-db` CLI, a typed `BaseRepository`, and an opt-in active-record layer. The public API may still shift before v1.0.
|
|
9
9
|
|
|
10
10
|
## Why tempest-db-js
|
|
11
11
|
|
|
@@ -36,9 +36,76 @@ No manual `interface`, no codegen step, no schema/type drift. The class **is** t
|
|
|
36
36
|
|
|
37
37
|
SQLAlchemy reads `Mapped[int]` at runtime via descriptors; TypeScript erases types at compile time. tempest-db-js bridges this by making each column a **runtime-typed builder** (`column.integer()`) that carries both its SQL type (runtime) and its static type (inference). You get class-based ergonomics **and** strong query-result inference β the trade-off being that returned rows are inferred plain objects, not active-record class instances (a post-MVP stretch goal).
|
|
38
38
|
|
|
39
|
+
## Install & run
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install tempest-db-js
|
|
43
|
+
# SQLite needs no extra driver (uses Node's built-in node:sqlite).
|
|
44
|
+
# For PostgreSQL: npm install postgres
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { Model, column, select, insert, createSyncEngine } from "tempest-db-js";
|
|
49
|
+
|
|
50
|
+
class Task extends Model {
|
|
51
|
+
static tablename = "tasks";
|
|
52
|
+
id = column.integer().primaryKey();
|
|
53
|
+
title = column.text().notNull();
|
|
54
|
+
done = column.boolean().notNull();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const engine = createSyncEngine("sqlite://:memory:");
|
|
58
|
+
const session = engine.session();
|
|
59
|
+
|
|
60
|
+
session.execute(insert(Task).values({ title: "ship docs", done: false }));
|
|
61
|
+
|
|
62
|
+
const pending = session.execute(select(Task).where({ done: false })).all();
|
|
63
|
+
// ^ inferred as { id: number; title: string; done: boolean }[] β no annotation
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Real execution is tested against a live SQLite database (`node:sqlite`) β type coercion, `RETURNING`, transactions, and rollback included. PostgreSQL runs via `postgres.js`.
|
|
67
|
+
|
|
68
|
+
Sessions and engines are **disposable** β `using session = engine.session()` (or `await using engine = createEngine(...)`) closes the driver/pool automatically at scope exit.
|
|
69
|
+
|
|
70
|
+
## Beyond CRUD
|
|
71
|
+
|
|
72
|
+
Typed extras, each with a [docs recipe](https://mauriciobenjamin700.github.io/tempest-db-js/):
|
|
73
|
+
|
|
74
|
+
- **Aggregations** β `select(Order).aggregate(["status"], { n: count(), total: sum("amount") })` β rows typed as `{ status; n; total }`. Plus `.distinct()`.
|
|
75
|
+
- **Upsert** β `insert(Row).values(...).onConflictDoUpdate(["key"], { ... })` / `.onConflictDoNothing(["key"])` (portable SQLite β PostgreSQL).
|
|
76
|
+
- **Active-record (opt-in)** β `activeRecord(User, session)` β `save`/`update`/`delete`/`reload` over `.data`; the plain-object default is unchanged.
|
|
77
|
+
- **Query logging & errors** β `createEngine(url, { onQuery })` traces every statement; a failed statement throws `QueryExecutionError` carrying the SQL + params.
|
|
78
|
+
|
|
79
|
+
## Migrations CLI
|
|
80
|
+
|
|
81
|
+
Alembic-style migrations ship with a `tempest-db` binary. Point it at a config that exports your driver, dialect, migrations, and models:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
// tempest-db.config.mjs
|
|
85
|
+
import { defineMigrationConfig } from "tempest-db-js/migrations";
|
|
86
|
+
import { NodeSqliteDriver } from "tempest-db-js";
|
|
87
|
+
import { migrations } from "./migrations/index.js";
|
|
88
|
+
import { User } from "./models.js";
|
|
89
|
+
|
|
90
|
+
export default defineMigrationConfig({
|
|
91
|
+
driver: NodeSqliteDriver.open("app.db"),
|
|
92
|
+
dialect: "sqlite",
|
|
93
|
+
migrations,
|
|
94
|
+
models: [User],
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
npx tempest-db revision -m "add users" --autogenerate # detects renames interactively
|
|
100
|
+
npx tempest-db upgrade # apply pending migrations
|
|
101
|
+
npx tempest-db current | history | heads | check
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
HTTP integration recipes (Hono, Express, Fastify) live in the [docs](https://mauriciobenjamin700.github.io/tempest-db-js/).
|
|
105
|
+
|
|
39
106
|
## Roadmap
|
|
40
107
|
|
|
41
|
-
See [ROADMAP.md](./ROADMAP.md).
|
|
108
|
+
See [ROADMAP.md](./ROADMAP.md). Shipped: SQLite + PostgreSQL execution, joins, relations, migrations, repository. Next: `tempest-ts-sdk` integration and PostgreSQL CI against a live database.
|
|
42
109
|
|
|
43
110
|
## Development
|
|
44
111
|
|
|
@@ -47,6 +114,7 @@ npm install
|
|
|
47
114
|
npm run test:types # tsc --noEmit β the type-level test suite
|
|
48
115
|
npm test # vitest runtime tests
|
|
49
116
|
npm run build # tsup β dual ESM + CJS + .d.ts
|
|
117
|
+
npm run bench # SQLite benchmark vs Drizzle/Kysely (see BENCHMARKS.md)
|
|
50
118
|
```
|
|
51
119
|
|
|
52
120
|
## License
|