@chromav/sizzler 0.1.1 → 0.1.3
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 +7 -7
- package/dist/columns/foreign-key.d.ts.map +1 -1
- package/dist/columns/helpers.d.ts.map +1 -1
- package/dist/columns/primary-key.d.ts.map +1 -1
- package/dist/columns/timestamps.d.ts +21 -6
- package/dist/columns/timestamps.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/node/seeding/json-seeder.d.ts.map +1 -1
- package/dist/node/seeding/reset.d.ts +2 -2
- package/dist/node/seeding/reset.d.ts.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
Stop bikeshedding IDs, timestamps, and foreign keys. Define your schema, seed your database, and get back to building.
|
|
6
6
|
|
|
7
7
|
```typescript
|
|
8
|
-
import { primaryKey, foreignKey, createdAt, updatedAt, table, text, enums } from "sizzler";
|
|
8
|
+
import { primaryKey, foreignKey, createdAt, updatedAt, table, text, enums } from "@chromav/sizzler";
|
|
9
9
|
|
|
10
10
|
const status = ["pending", "in_progress", "done"] as const;
|
|
11
11
|
|
|
@@ -42,10 +42,10 @@ Every factory returns a standard Drizzle column builder. Chain `.notNull()`, `.u
|
|
|
42
42
|
|
|
43
43
|
### 2. Local dev helpers
|
|
44
44
|
|
|
45
|
-
The
|
|
45
|
+
The `@chromav/sizzler/node` entry point gets you connected and seeded fast:
|
|
46
46
|
|
|
47
47
|
```typescript
|
|
48
|
-
import { computeD1Filename, getLocalD1Path, createJSONSeeder, resetDatabase } from "sizzler/node";
|
|
48
|
+
import { computeD1Filename, getLocalD1Path, createJSONSeeder, resetDatabase } from "@chromav/sizzler/node";
|
|
49
49
|
|
|
50
50
|
// Compute the exact filename miniflare uses for a D1 database
|
|
51
51
|
const filename = computeD1Filename("3c9d1256-e9bd-4617-ad46-22315915a680");
|
|
@@ -69,12 +69,12 @@ No more hunting for SQLite files in `.wrangler/`. No more reverse-engineering mi
|
|
|
69
69
|
|
|
70
70
|
### 3. Golden snapshots
|
|
71
71
|
|
|
72
|
-
Also on
|
|
72
|
+
Also on `@chromav/sizzler/node`: helpers for creating and restoring self-contained SQLite
|
|
73
73
|
"golden" snapshots — the foundation of fast, reproducible E2E tests (build the DB
|
|
74
74
|
once, restore the file per run instead of migrating + seeding every time).
|
|
75
75
|
|
|
76
76
|
```typescript
|
|
77
|
-
import { createSnapshot, restoreSnapshot } from "sizzler/node";
|
|
77
|
+
import { createSnapshot, restoreSnapshot } from "@chromav/sizzler/node";
|
|
78
78
|
|
|
79
79
|
// Create a golden snapshot from a live DB: checkpoints the WAL into the main
|
|
80
80
|
// file (so the .sqlite is self-contained), copies it, and verifies it has data.
|
|
@@ -105,7 +105,7 @@ file to snapshot or restore.
|
|
|
105
105
|
## Installation
|
|
106
106
|
|
|
107
107
|
```bash
|
|
108
|
-
npm install sizzler drizzle-orm
|
|
108
|
+
npm install @chromav/sizzler drizzle-orm
|
|
109
109
|
```
|
|
110
110
|
|
|
111
111
|
## The boilerplate it replaces
|
|
@@ -133,7 +133,7 @@ export const tasks = sqliteTable("tasks", {
|
|
|
133
133
|
**After:**
|
|
134
134
|
|
|
135
135
|
```typescript
|
|
136
|
-
import { primaryKey, foreignKey, createdAt, updatedAt, table, text, enums } from "sizzler";
|
|
136
|
+
import { primaryKey, foreignKey, createdAt, updatedAt, table, text, enums } from "@chromav/sizzler";
|
|
137
137
|
|
|
138
138
|
const status = ["pending", "in_progress", "done"] as const;
|
|
139
139
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"foreign-key.d.ts","sourceRoot":"","sources":["../../src/columns/foreign-key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AAGjC,KAAK,YAAY,GAAG;IAClB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,SAAS,GAAG,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"foreign-key.d.ts","sourceRoot":"","sources":["../../src/columns/foreign-key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AAGjC,KAAK,YAAY,GAAG;IAClB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,SAAS,GAAG,MAAM,GAAG,MAAM,QACxD,MAAM,OACP,YAAY,SACX,CAAC,YACG,YAAY,KACrB,CAAC,SAAS,SAAS,GAAG,oBAAoB,GAAG,iBAAiB,CAAC,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAKzC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/columns/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,WAAW,EACpB,OAAO,IAAI,aAAa,EACxB,IAAI,IAAI,UAAU,EAElB,IAAI,IAAI,UAAU,EACnB,MAAM,yBAAyB,CAAC;AAEjC,KAAK,UAAU,GAAG,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;AAGjD,eAAO,MAAM,KAAK,4DAAc,CAAC;AACjC,eAAO,MAAM,KAAK,oBAAc,CAAC;AACjC,eAAO,MAAM,OAAO,sBAAgB,CAAC;AACrC,eAAO,MAAM,IAAI,mBAAa,CAAC;AAC/B,eAAO,MAAM,IAAI,mBAAa,CAAC;AAE/B;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/columns/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,WAAW,EACpB,OAAO,IAAI,aAAa,EACxB,IAAI,IAAI,UAAU,EAElB,IAAI,IAAI,UAAU,EACnB,MAAM,yBAAyB,CAAC;AAEjC,KAAK,UAAU,GAAG,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;AAGjD,eAAO,MAAM,KAAK,4DAAc,CAAC;AACjC,eAAO,MAAM,KAAK,oBAAc,CAAC;AACjC,eAAO,MAAM,OAAO,sBAAgB,CAAC;AACrC,eAAO,MAAM,IAAI,mBAAa,CAAC;AAC/B,eAAO,MAAM,IAAI,mBAAa,CAAC;AAE/B;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,SAAU,MAAM,2DAAuC,CAAC;AAE5E;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,UAAU,QAAQ,MAAM,UAAU,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,6HAGxC,CAAC;AAEtD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,GAAG,MAAM,EAAE,QAAQ,MAAM,4FAA4C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primary-key.d.ts","sourceRoot":"","sources":["../../src/columns/primary-key.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"primary-key.d.ts","sourceRoot":"","sources":["../../src/columns/primary-key.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,6OAIM,CAAC"}
|
|
@@ -45,13 +45,28 @@ export declare const timestamp_ms: (columnName: string) => import("drizzle-orm/s
|
|
|
45
45
|
*/
|
|
46
46
|
export declare const createdAt: () => import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTimestampBuilder>>;
|
|
47
47
|
/**
|
|
48
|
-
* Creates an updated_at timestamp column
|
|
49
|
-
* Uses SQLite's unixepoch() for the default value.
|
|
48
|
+
* Creates an updated_at timestamp column that maintains itself.
|
|
50
49
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
50
|
+
* `unixepoch()` supplies the value on INSERT; `$onUpdate` re-stamps it on every
|
|
51
|
+
* UPDATE. The `$onUpdate` half matters more than it looks: drizzle applies it in
|
|
52
|
+
* `buildUpdateSet` at the **dialect** layer, so it fires for every `.update().set()`
|
|
53
|
+
* — ORM helpers, hand-written statements, and anything inside `db.batch()` alike.
|
|
54
|
+
* There is no code path that silently skips it, which is the point: without it the
|
|
55
|
+
* column is insert-time-only and freezes at `created_at` for the life of the row.
|
|
53
56
|
*
|
|
54
|
-
*
|
|
57
|
+
* `$onUpdate` is runtime-only and invisible to drizzle-kit, so adding it needs no
|
|
58
|
+
* migration.
|
|
59
|
+
*
|
|
60
|
+
* **Opting out of one write.** A caller-supplied value wins (drizzle only applies
|
|
61
|
+
* `onUpdateFn` when the column is absent from `set`), so a write that must NOT
|
|
62
|
+
* count as a modification — acquiring a lock, bookkeeping — can hold the column
|
|
63
|
+
* still by setting it to itself:
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* db.update(tasks).set({ lockedAt: now, updatedAt: sql`updated_at` })
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @returns A non-null timestamp column defaulting to, and refreshed with, current time
|
|
55
70
|
*
|
|
56
71
|
* @example
|
|
57
72
|
* ```ts
|
|
@@ -61,5 +76,5 @@ export declare const createdAt: () => import("drizzle-orm").HasDefault<import("d
|
|
|
61
76
|
* });
|
|
62
77
|
* ```
|
|
63
78
|
*/
|
|
64
|
-
export declare const updatedAt: () => import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTimestampBuilder
|
|
79
|
+
export declare const updatedAt: () => import("drizzle-orm").HasDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTimestampBuilder>>>;
|
|
65
80
|
//# sourceMappingURL=timestamps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timestamps.d.ts","sourceRoot":"","sources":["../../src/columns/timestamps.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"timestamps.d.ts","sourceRoot":"","sources":["../../src/columns/timestamps.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,SAAS,eAAgB,MAAM,6DAA+C,CAAC;AAE5F;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,YAAY,eAAgB,MAAM,6DAAkD,CAAC;AAElG;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS,iIAAsE,CAAC;AAE7F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,SAAS,mKAIU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ import { integer as integer3 } from "drizzle-orm/sqlite-core";
|
|
|
32
32
|
var timestamp = (columnName) => integer3(columnName, { mode: "timestamp" });
|
|
33
33
|
var timestamp_ms = (columnName) => integer3(columnName, { mode: "timestamp_ms" });
|
|
34
34
|
var createdAt = () => timestamp("created_at").notNull().default(sql`(unixepoch())`);
|
|
35
|
-
var updatedAt = () => timestamp("updated_at").notNull().default(sql`(unixepoch())`);
|
|
35
|
+
var updatedAt = () => timestamp("updated_at").notNull().default(sql`(unixepoch())`).$onUpdate(() => /* @__PURE__ */ new Date());
|
|
36
36
|
export {
|
|
37
37
|
boolean,
|
|
38
38
|
createdAt,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-seeder.d.ts","sourceRoot":"","sources":["../../../src/node/seeding/json-seeder.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;CAC5D;AAyBD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB;eAMvC,CAAC,0BAA0B,MAAM,KAAG,CAAC;wBAW5B,CAAC,0BAA0B,MAAM,KAAG,CAAC,EAAE;+BAUhC,MAAM,KAAG,OAAO;EASnD;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB;IAC7B;;;;;;;;;;OAUG;
|
|
1
|
+
{"version":3,"file":"json-seeder.d.ts","sourceRoot":"","sources":["../../../src/node/seeding/json-seeder.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;CAC5D;AAyBD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB;eAMvC,CAAC,0BAA0B,MAAM,KAAG,CAAC;wBAW5B,CAAC,0BAA0B,MAAM,KAAG,CAAC,EAAE;+BAUhC,MAAM,KAAG,OAAO;EASnD;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB;IAC7B;;;;;;;;;;OAUG;IACH,UAAU,eAAe,MAAM,EAAE,4BACY,OAAO,KAAK,OAAO;IAOhE;;;;;;;;;;OAUG;IACH,YAAY,eAAe,MAAM,EAAE,4BACU,OAAO,KAAK,OAAO;CAMjE,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SQLiteAsyncDatabase } from "drizzle-orm/sqlite-core";
|
|
2
2
|
/**
|
|
3
3
|
* Reset database with enhanced error handling and logging.
|
|
4
4
|
* Requires explicit confirmation to prevent accidental data loss.
|
|
@@ -17,7 +17,7 @@ import type { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";
|
|
|
17
17
|
* });
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
export declare function resetDatabase(db:
|
|
20
|
+
export declare function resetDatabase(db: SQLiteAsyncDatabase<"sync" | "async", unknown>, schema: Record<string, unknown>, options?: {
|
|
21
21
|
confirm?: boolean;
|
|
22
22
|
verbose?: boolean;
|
|
23
23
|
logger?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reset.d.ts","sourceRoot":"","sources":["../../../src/node/seeding/reset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"reset.d.ts","sourceRoot":"","sources":["../../../src/node/seeding/reset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAGnE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,aAAa,CACjC,EAAE,EAAE,mBAAmB,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,CAAC,EAClD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE;QAAE,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;QAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;KAAE,CAAC;CAChF,iBAwBP"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chromav/sizzler",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Sizzling column factories and utilities for Drizzle ORM with SQLite, D1, and Turso",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/better-sqlite3": "^7.6.13",
|
|
47
47
|
"better-sqlite3": "^12.0.0",
|
|
48
|
-
"drizzle-orm": "1.0.0-
|
|
49
|
-
"drizzle-seed": "
|
|
48
|
+
"drizzle-orm": "1.0.0-rc.5-ab785fc",
|
|
49
|
+
"drizzle-seed": "1.0.0-rc.5-ab785fc",
|
|
50
50
|
"tsup": "^8.5.1",
|
|
51
|
-
"typescript": "^
|
|
51
|
+
"typescript": "^7.0.2",
|
|
52
52
|
"vitest": "^4.1.5"
|
|
53
53
|
},
|
|
54
54
|
"keywords": [
|