tempest-db-js 0.1.0 β†’ 0.3.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 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
- > ⚠️ **Status: pre-alpha (v0.0.0).** Phase 1 type-inference is proven; the public API is still taking shape. Not yet published to npm.
8
+ > βœ… **Status: alpha (v0.3.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 + PostgreSQL execution**, a **MySQL** dialect, joins, relations, Alembic-style migrations (sync + **async** runner) with 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). Targets: **SQLite** (`better-sqlite3`) then **PostgreSQL** (`postgres.js`), performance-first.
108
+ See [ROADMAP.md](./ROADMAP.md). Shipped (v0.3.0): SQLite + PostgreSQL execution (both tested in CI, Postgres against a live database), a MySQL dialect, joins, relations, sync + async migration runners with a `tempest-db` CLI, repository, aggregations/upsert, opt-in active-record. Next: MySQL execution in CI + `RETURNING` round-trip, async CLI wiring, then `tempest-ts-sdk`.
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