@setupless/drizzle 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.
Files changed (45) hide show
  1. package/README.md +14 -6
  2. package/dist/cjs/index.d.ts +2 -0
  3. package/dist/cjs/index.js +5 -0
  4. package/dist/cjs/package.json +1 -0
  5. package/dist/cjs/pg/createdAt.d.ts +9 -0
  6. package/dist/cjs/pg/createdAt.js +13 -0
  7. package/dist/cjs/pg/id.d.ts +10 -0
  8. package/dist/cjs/pg/id.js +19 -0
  9. package/dist/cjs/pg/index.d.ts +4 -0
  10. package/dist/cjs/pg/index.js +11 -0
  11. package/dist/cjs/pg/timestamps.d.ts +9 -0
  12. package/dist/cjs/pg/timestamps.js +14 -0
  13. package/dist/cjs/pg/updatedAt.d.ts +9 -0
  14. package/dist/cjs/pg/updatedAt.js +17 -0
  15. package/dist/cjs/sqlite/createdAt.d.ts +7 -0
  16. package/dist/cjs/sqlite/createdAt.js +16 -0
  17. package/dist/cjs/sqlite/id.d.ts +10 -0
  18. package/dist/cjs/sqlite/id.js +21 -0
  19. package/dist/cjs/sqlite/index.d.ts +4 -0
  20. package/dist/cjs/sqlite/index.js +11 -0
  21. package/dist/cjs/sqlite/timestamps.d.ts +7 -0
  22. package/dist/cjs/sqlite/timestamps.js +14 -0
  23. package/dist/cjs/sqlite/updatedAt.d.ts +7 -0
  24. package/dist/cjs/sqlite/updatedAt.js +17 -0
  25. package/dist/pg/createdAt.d.ts +9 -0
  26. package/dist/pg/createdAt.js +10 -0
  27. package/dist/pg/id.d.ts +2 -2
  28. package/dist/pg/id.js +2 -2
  29. package/dist/pg/index.d.ts +3 -0
  30. package/dist/pg/index.js +3 -0
  31. package/dist/pg/timestamps.d.ts +9 -0
  32. package/dist/pg/timestamps.js +11 -0
  33. package/dist/pg/updatedAt.d.ts +9 -0
  34. package/dist/pg/updatedAt.js +14 -0
  35. package/dist/sqlite/createdAt.d.ts +7 -0
  36. package/dist/sqlite/createdAt.js +13 -0
  37. package/dist/sqlite/id.d.ts +2 -2
  38. package/dist/sqlite/id.js +2 -2
  39. package/dist/sqlite/index.d.ts +3 -0
  40. package/dist/sqlite/index.js +3 -0
  41. package/dist/sqlite/timestamps.d.ts +7 -0
  42. package/dist/sqlite/timestamps.js +11 -0
  43. package/dist/sqlite/updatedAt.d.ts +7 -0
  44. package/dist/sqlite/updatedAt.js +14 -0
  45. package/package.json +26 -8
package/README.md CHANGED
@@ -7,21 +7,29 @@ npm install @setupless/drizzle drizzle-orm
7
7
  # or: bun add @setupless/drizzle drizzle-orm
8
8
  ```
9
9
 
10
- | Function | Description | Databases |
11
- | ------------ | ------------------------------------- | ------------------ |
12
- | `id()` | Auto-incrementing integer primary key | PostgreSQL, SQLite |
13
- | `id("uuid")` | Generated UUID primary key | PostgreSQL, SQLite |
10
+ | Function | Description | Databases |
11
+ | -------------- | ----------------------------------------------- | ------------------ |
12
+ | `id()` | Auto-incrementing integer primary key | PostgreSQL, SQLite |
13
+ | `id("uuid")` | Generated UUID primary key | PostgreSQL, SQLite |
14
+ | `createdAt()` | Timestamp with the current time as its default | PostgreSQL, SQLite |
15
+ | `updatedAt()` | Timestamp set on insert and Drizzle-run updates | PostgreSQL, SQLite |
16
+ | `timestamps()` | `createdAt()` and `updatedAt()` columns | PostgreSQL, SQLite |
14
17
 
15
18
  ```ts
16
19
  import { pgTable } from "drizzle-orm/pg-core";
17
- import { id } from "@setupless/drizzle/pg";
20
+ import { id, timestamps } from "@setupless/drizzle/pg";
18
21
 
19
22
  export const users = pgTable("users", {
20
23
  ...id(),
24
+ ...timestamps({ withTimezone: true }),
21
25
  });
22
26
  ```
23
27
 
24
28
  Import from `/sqlite` for SQLite. The package root also exports `pg` and
25
- `sqlite` namespaces.
29
+ `sqlite` namespaces. `updatedAt()` uses Drizzle's `$onUpdate` callback; it does
30
+ not create a database trigger for updates made outside Drizzle.
31
+
32
+ PostgreSQL timestamp helpers accept a `withTimezone` option. SQLite stores the
33
+ timestamps as text and does not accept this option.
26
34
 
27
35
  Licensed under [Apache 2.0](LICENSE).
@@ -0,0 +1,2 @@
1
+ export * as pg from "./pg/index.js";
2
+ export * as sqlite from "./sqlite/index.js";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sqlite = exports.pg = void 0;
4
+ exports.pg = require("./pg/index.js");
5
+ exports.sqlite = require("./sqlite/index.js");
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Defines a non-null `createdAt` timestamp column with a database default of
3
+ * `now()`.
4
+ */
5
+ export default function createdAt({ withTimezone, }?: {
6
+ withTimezone?: boolean;
7
+ }): {
8
+ createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"created_at">>>;
9
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = createdAt;
4
+ const pg_core_1 = require("drizzle-orm/pg-core");
5
+ /**
6
+ * Defines a non-null `createdAt` timestamp column with a database default of
7
+ * `now()`.
8
+ */
9
+ function createdAt({ withTimezone, } = {}) {
10
+ return {
11
+ createdAt: (0, pg_core_1.timestamp)("created_at", { withTimezone }).notNull().defaultNow(),
12
+ };
13
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Defines an `id` primary-key column.
3
+ *
4
+ * PostgreSQL generates UUID values through the column's database default.
5
+ */
6
+ export default function id(strategy?: "auto" | "uuid"): {
7
+ id: import("drizzle-orm").IsIdentity<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgIntegerBuilderInitial<"id">>>, "always">;
8
+ } | {
9
+ id: import("drizzle-orm").HasDefault<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"id">>>>;
10
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = id;
4
+ const pg_core_1 = require("drizzle-orm/pg-core");
5
+ /**
6
+ * Defines an `id` primary-key column.
7
+ *
8
+ * PostgreSQL generates UUID values through the column's database default.
9
+ */
10
+ function id(strategy = "auto") {
11
+ switch (strategy) {
12
+ case "auto":
13
+ return { id: (0, pg_core_1.integer)("id").primaryKey().generatedAlwaysAsIdentity() };
14
+ case "uuid":
15
+ return {
16
+ id: (0, pg_core_1.uuid)("id").primaryKey().defaultRandom(),
17
+ };
18
+ }
19
+ }
@@ -0,0 +1,4 @@
1
+ export { default as createdAt } from "./createdAt.js";
2
+ export { default as id } from "./id.js";
3
+ export { default as timestamps } from "./timestamps.js";
4
+ export { default as updatedAt } from "./updatedAt.js";
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updatedAt = exports.timestamps = exports.id = exports.createdAt = void 0;
4
+ var createdAt_js_1 = require("./createdAt.js");
5
+ Object.defineProperty(exports, "createdAt", { enumerable: true, get: function () { return createdAt_js_1.default; } });
6
+ var id_js_1 = require("./id.js");
7
+ Object.defineProperty(exports, "id", { enumerable: true, get: function () { return id_js_1.default; } });
8
+ var timestamps_js_1 = require("./timestamps.js");
9
+ Object.defineProperty(exports, "timestamps", { enumerable: true, get: function () { return timestamps_js_1.default; } });
10
+ var updatedAt_js_1 = require("./updatedAt.js");
11
+ Object.defineProperty(exports, "updatedAt", { enumerable: true, get: function () { return updatedAt_js_1.default; } });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Defines non-null `createdAt` and `updatedAt` timestamp columns.
3
+ */
4
+ export default function timestamps({ withTimezone, }?: {
5
+ withTimezone?: boolean;
6
+ }): {
7
+ updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core/index.js").PgTimestampBuilderInitial<"updated_at">>>>;
8
+ createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core/index.js").PgTimestampBuilderInitial<"created_at">>>;
9
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = timestamps;
4
+ const createdAt_js_1 = require("./createdAt.js");
5
+ const updatedAt_js_1 = require("./updatedAt.js");
6
+ /**
7
+ * Defines non-null `createdAt` and `updatedAt` timestamp columns.
8
+ */
9
+ function timestamps({ withTimezone, } = {}) {
10
+ return {
11
+ ...(0, createdAt_js_1.default)({ withTimezone }),
12
+ ...(0, updatedAt_js_1.default)({ withTimezone }),
13
+ };
14
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Defines a non-null `updatedAt` timestamp column. The database supplies the
3
+ * insert default, and Drizzle supplies the value for updates it executes.
4
+ */
5
+ export default function updatedAt({ withTimezone, }?: {
6
+ withTimezone?: boolean;
7
+ }): {
8
+ updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"updated_at">>>>;
9
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = updatedAt;
4
+ const drizzle_orm_1 = require("drizzle-orm");
5
+ const pg_core_1 = require("drizzle-orm/pg-core");
6
+ /**
7
+ * Defines a non-null `updatedAt` timestamp column. The database supplies the
8
+ * insert default, and Drizzle supplies the value for updates it executes.
9
+ */
10
+ function updatedAt({ withTimezone, } = {}) {
11
+ return {
12
+ updatedAt: (0, pg_core_1.timestamp)("updated_at", { withTimezone })
13
+ .notNull()
14
+ .defaultNow()
15
+ .$onUpdate(() => (0, drizzle_orm_1.sql) `now()`),
16
+ };
17
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Defines a non-null `createdAt` text column with a database default of
3
+ * `current_timestamp`.
4
+ */
5
+ export default function createdAt(): {
6
+ createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"created_at", [string, ...string[]], number | undefined>>>;
7
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = createdAt;
4
+ const drizzle_orm_1 = require("drizzle-orm");
5
+ const sqlite_core_1 = require("drizzle-orm/sqlite-core");
6
+ /**
7
+ * Defines a non-null `createdAt` text column with a database default of
8
+ * `current_timestamp`.
9
+ */
10
+ function createdAt() {
11
+ return {
12
+ createdAt: (0, sqlite_core_1.text)("created_at")
13
+ .notNull()
14
+ .default((0, drizzle_orm_1.sql) `(current_timestamp)`),
15
+ };
16
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Defines an `id` primary-key column.
3
+ *
4
+ * Drizzle generates UUID values in the application through `$defaultFn`.
5
+ */
6
+ export default function id(strategy?: "auto" | "uuid"): {
7
+ id: import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteIntegerBuilderInitial<"id">>>>;
8
+ } | {
9
+ id: import("drizzle-orm").HasRuntimeDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"id", [string, ...string[]], number | undefined>>>>>;
10
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = id;
4
+ const sqlite_core_1 = require("drizzle-orm/sqlite-core");
5
+ /**
6
+ * Defines an `id` primary-key column.
7
+ *
8
+ * Drizzle generates UUID values in the application through `$defaultFn`.
9
+ */
10
+ function id(strategy = "auto") {
11
+ switch (strategy) {
12
+ case "auto":
13
+ return { id: (0, sqlite_core_1.integer)("id").primaryKey({ autoIncrement: true }) };
14
+ case "uuid":
15
+ return {
16
+ id: (0, sqlite_core_1.text)("id")
17
+ .primaryKey()
18
+ .$defaultFn(() => crypto.randomUUID()),
19
+ };
20
+ }
21
+ }
@@ -0,0 +1,4 @@
1
+ export { default as createdAt } from "./createdAt.js";
2
+ export { default as id } from "./id.js";
3
+ export { default as timestamps } from "./timestamps.js";
4
+ export { default as updatedAt } from "./updatedAt.js";
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updatedAt = exports.timestamps = exports.id = exports.createdAt = void 0;
4
+ var createdAt_js_1 = require("./createdAt.js");
5
+ Object.defineProperty(exports, "createdAt", { enumerable: true, get: function () { return createdAt_js_1.default; } });
6
+ var id_js_1 = require("./id.js");
7
+ Object.defineProperty(exports, "id", { enumerable: true, get: function () { return id_js_1.default; } });
8
+ var timestamps_js_1 = require("./timestamps.js");
9
+ Object.defineProperty(exports, "timestamps", { enumerable: true, get: function () { return timestamps_js_1.default; } });
10
+ var updatedAt_js_1 = require("./updatedAt.js");
11
+ Object.defineProperty(exports, "updatedAt", { enumerable: true, get: function () { return updatedAt_js_1.default; } });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Defines non-null `createdAt` and `updatedAt` text columns.
3
+ */
4
+ export default function timestamps(): {
5
+ updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core/index.js").SQLiteTextBuilderInitial<"updated_at", [string, ...string[]], number | undefined>>>>;
6
+ createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core/index.js").SQLiteTextBuilderInitial<"created_at", [string, ...string[]], number | undefined>>>;
7
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = timestamps;
4
+ const createdAt_js_1 = require("./createdAt.js");
5
+ const updatedAt_js_1 = require("./updatedAt.js");
6
+ /**
7
+ * Defines non-null `createdAt` and `updatedAt` text columns.
8
+ */
9
+ function timestamps() {
10
+ return {
11
+ ...(0, createdAt_js_1.default)(),
12
+ ...(0, updatedAt_js_1.default)(),
13
+ };
14
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Defines a non-null `updatedAt` text column. The database supplies the insert
3
+ * default, and Drizzle supplies the value for updates it executes.
4
+ */
5
+ export default function updatedAt(): {
6
+ updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"updated_at", [string, ...string[]], number | undefined>>>>;
7
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = updatedAt;
4
+ const drizzle_orm_1 = require("drizzle-orm");
5
+ const sqlite_core_1 = require("drizzle-orm/sqlite-core");
6
+ /**
7
+ * Defines a non-null `updatedAt` text column. The database supplies the insert
8
+ * default, and Drizzle supplies the value for updates it executes.
9
+ */
10
+ function updatedAt() {
11
+ return {
12
+ updatedAt: (0, sqlite_core_1.text)("updated_at")
13
+ .notNull()
14
+ .default((0, drizzle_orm_1.sql) `(current_timestamp)`)
15
+ .$onUpdate(() => (0, drizzle_orm_1.sql) `(current_timestamp)`),
16
+ };
17
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Defines a non-null `createdAt` timestamp column with a database default of
3
+ * `now()`.
4
+ */
5
+ export default function createdAt({ withTimezone, }?: {
6
+ withTimezone?: boolean;
7
+ }): {
8
+ createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"created_at">>>;
9
+ };
@@ -0,0 +1,10 @@
1
+ import { timestamp } from "drizzle-orm/pg-core";
2
+ /**
3
+ * Defines a non-null `createdAt` timestamp column with a database default of
4
+ * `now()`.
5
+ */
6
+ export default function createdAt({ withTimezone, } = {}) {
7
+ return {
8
+ createdAt: timestamp("created_at", { withTimezone }).notNull().defaultNow(),
9
+ };
10
+ }
package/dist/pg/id.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * PostgreSQL generates UUID values through the column's database default.
5
5
  */
6
6
  export default function id(strategy?: "auto" | "uuid"): {
7
- id: import("drizzle-orm").IsIdentity<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgIntegerBuilderInitial<"">>>, "always">;
7
+ id: import("drizzle-orm").IsIdentity<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgIntegerBuilderInitial<"id">>>, "always">;
8
8
  } | {
9
- id: import("drizzle-orm").HasDefault<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"">>>>;
9
+ id: import("drizzle-orm").HasDefault<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"id">>>>;
10
10
  };
package/dist/pg/id.js CHANGED
@@ -7,10 +7,10 @@ import { integer, uuid } from "drizzle-orm/pg-core";
7
7
  export default function id(strategy = "auto") {
8
8
  switch (strategy) {
9
9
  case "auto":
10
- return { id: integer().primaryKey().generatedAlwaysAsIdentity() };
10
+ return { id: integer("id").primaryKey().generatedAlwaysAsIdentity() };
11
11
  case "uuid":
12
12
  return {
13
- id: uuid().primaryKey().defaultRandom(),
13
+ id: uuid("id").primaryKey().defaultRandom(),
14
14
  };
15
15
  }
16
16
  }
@@ -1 +1,4 @@
1
+ export { default as createdAt } from "./createdAt.js";
1
2
  export { default as id } from "./id.js";
3
+ export { default as timestamps } from "./timestamps.js";
4
+ export { default as updatedAt } from "./updatedAt.js";
package/dist/pg/index.js CHANGED
@@ -1 +1,4 @@
1
+ export { default as createdAt } from "./createdAt.js";
1
2
  export { default as id } from "./id.js";
3
+ export { default as timestamps } from "./timestamps.js";
4
+ export { default as updatedAt } from "./updatedAt.js";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Defines non-null `createdAt` and `updatedAt` timestamp columns.
3
+ */
4
+ export default function timestamps({ withTimezone, }?: {
5
+ withTimezone?: boolean;
6
+ }): {
7
+ updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"updated_at">>>>;
8
+ createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"created_at">>>;
9
+ };
@@ -0,0 +1,11 @@
1
+ import createdAt from "./createdAt.js";
2
+ import updatedAt from "./updatedAt.js";
3
+ /**
4
+ * Defines non-null `createdAt` and `updatedAt` timestamp columns.
5
+ */
6
+ export default function timestamps({ withTimezone, } = {}) {
7
+ return {
8
+ ...createdAt({ withTimezone }),
9
+ ...updatedAt({ withTimezone }),
10
+ };
11
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Defines a non-null `updatedAt` timestamp column. The database supplies the
3
+ * insert default, and Drizzle supplies the value for updates it executes.
4
+ */
5
+ export default function updatedAt({ withTimezone, }?: {
6
+ withTimezone?: boolean;
7
+ }): {
8
+ updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<"updated_at">>>>;
9
+ };
@@ -0,0 +1,14 @@
1
+ import { sql } from "drizzle-orm";
2
+ import { timestamp } from "drizzle-orm/pg-core";
3
+ /**
4
+ * Defines a non-null `updatedAt` timestamp column. The database supplies the
5
+ * insert default, and Drizzle supplies the value for updates it executes.
6
+ */
7
+ export default function updatedAt({ withTimezone, } = {}) {
8
+ return {
9
+ updatedAt: timestamp("updated_at", { withTimezone })
10
+ .notNull()
11
+ .defaultNow()
12
+ .$onUpdate(() => sql `now()`),
13
+ };
14
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Defines a non-null `createdAt` text column with a database default of
3
+ * `current_timestamp`.
4
+ */
5
+ export default function createdAt(): {
6
+ createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"created_at", [string, ...string[]], number | undefined>>>;
7
+ };
@@ -0,0 +1,13 @@
1
+ import { sql } from "drizzle-orm";
2
+ import { text } from "drizzle-orm/sqlite-core";
3
+ /**
4
+ * Defines a non-null `createdAt` text column with a database default of
5
+ * `current_timestamp`.
6
+ */
7
+ export default function createdAt() {
8
+ return {
9
+ createdAt: text("created_at")
10
+ .notNull()
11
+ .default(sql `(current_timestamp)`),
12
+ };
13
+ }
@@ -4,7 +4,7 @@
4
4
  * Drizzle generates UUID values in the application through `$defaultFn`.
5
5
  */
6
6
  export default function id(strategy?: "auto" | "uuid"): {
7
- id: import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteIntegerBuilderInitial<"">>>>;
7
+ id: import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteIntegerBuilderInitial<"id">>>>;
8
8
  } | {
9
- id: import("drizzle-orm").HasRuntimeDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"", [string, ...string[]], undefined>>>>>;
9
+ id: import("drizzle-orm").HasRuntimeDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"id", [string, ...string[]], number | undefined>>>>>;
10
10
  };
package/dist/sqlite/id.js CHANGED
@@ -7,10 +7,10 @@ import { integer, text } from "drizzle-orm/sqlite-core";
7
7
  export default function id(strategy = "auto") {
8
8
  switch (strategy) {
9
9
  case "auto":
10
- return { id: integer().primaryKey({ autoIncrement: true }) };
10
+ return { id: integer("id").primaryKey({ autoIncrement: true }) };
11
11
  case "uuid":
12
12
  return {
13
- id: text()
13
+ id: text("id")
14
14
  .primaryKey()
15
15
  .$defaultFn(() => crypto.randomUUID()),
16
16
  };
@@ -1 +1,4 @@
1
+ export { default as createdAt } from "./createdAt.js";
1
2
  export { default as id } from "./id.js";
3
+ export { default as timestamps } from "./timestamps.js";
4
+ export { default as updatedAt } from "./updatedAt.js";
@@ -1 +1,4 @@
1
+ export { default as createdAt } from "./createdAt.js";
1
2
  export { default as id } from "./id.js";
3
+ export { default as timestamps } from "./timestamps.js";
4
+ export { default as updatedAt } from "./updatedAt.js";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Defines non-null `createdAt` and `updatedAt` text columns.
3
+ */
4
+ export default function timestamps(): {
5
+ updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"updated_at", [string, ...string[]], number | undefined>>>>;
6
+ createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"created_at", [string, ...string[]], number | undefined>>>;
7
+ };
@@ -0,0 +1,11 @@
1
+ import createdAt from "./createdAt.js";
2
+ import updatedAt from "./updatedAt.js";
3
+ /**
4
+ * Defines non-null `createdAt` and `updatedAt` text columns.
5
+ */
6
+ export default function timestamps() {
7
+ return {
8
+ ...createdAt(),
9
+ ...updatedAt(),
10
+ };
11
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Defines a non-null `updatedAt` text column. The database supplies the insert
3
+ * default, and Drizzle supplies the value for updates it executes.
4
+ */
5
+ export default function updatedAt(): {
6
+ updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"updated_at", [string, ...string[]], number | undefined>>>>;
7
+ };
@@ -0,0 +1,14 @@
1
+ import { sql } from "drizzle-orm";
2
+ import { text } from "drizzle-orm/sqlite-core";
3
+ /**
4
+ * Defines a non-null `updatedAt` text column. The database supplies the insert
5
+ * default, and Drizzle supplies the value for updates it executes.
6
+ */
7
+ export default function updatedAt() {
8
+ return {
9
+ updatedAt: text("updated_at")
10
+ .notNull()
11
+ .default(sql `(current_timestamp)`)
12
+ .$onUpdate(() => sql `(current_timestamp)`),
13
+ };
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@setupless/drizzle",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Small, typed helpers for defining Drizzle ORM schemas",
5
5
  "homepage": "https://github.com/Setupless/drizzle#readme",
6
6
  "bugs": {
@@ -16,21 +16,39 @@
16
16
  ],
17
17
  "type": "module",
18
18
  "sideEffects": false,
19
- "main": "./dist/index.js",
19
+ "main": "./dist/cjs/index.js",
20
20
  "module": "./dist/index.js",
21
21
  "types": "./dist/index.d.ts",
22
22
  "exports": {
23
23
  ".": {
24
- "types": "./dist/index.d.ts",
25
- "import": "./dist/index.js"
24
+ "import": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ },
28
+ "require": {
29
+ "types": "./dist/cjs/index.d.ts",
30
+ "default": "./dist/cjs/index.js"
31
+ }
26
32
  },
27
33
  "./pg": {
28
- "types": "./dist/pg/index.d.ts",
29
- "import": "./dist/pg/index.js"
34
+ "import": {
35
+ "types": "./dist/pg/index.d.ts",
36
+ "default": "./dist/pg/index.js"
37
+ },
38
+ "require": {
39
+ "types": "./dist/cjs/pg/index.d.ts",
40
+ "default": "./dist/cjs/pg/index.js"
41
+ }
30
42
  },
31
43
  "./sqlite": {
32
- "types": "./dist/sqlite/index.d.ts",
33
- "import": "./dist/sqlite/index.js"
44
+ "import": {
45
+ "types": "./dist/sqlite/index.d.ts",
46
+ "default": "./dist/sqlite/index.js"
47
+ },
48
+ "require": {
49
+ "types": "./dist/cjs/sqlite/index.d.ts",
50
+ "default": "./dist/cjs/sqlite/index.js"
51
+ }
34
52
  }
35
53
  },
36
54
  "publishConfig": {