@coffre/db 0.0.0 → 0.1.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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -3
  3. package/dist/commits-BuW-NL3n.js +30 -0
  4. package/dist/connect.d.ts +21 -0
  5. package/dist/connect.js +155 -0
  6. package/dist/database-CWpo5aF0.d.ts +39 -0
  7. package/dist/dialect.d.ts +88 -0
  8. package/dist/dialect.js +128 -0
  9. package/dist/hyperdrive.d.ts +32 -0
  10. package/dist/hyperdrive.js +53 -0
  11. package/dist/index.d.ts +3 -0
  12. package/dist/index.js +34 -0
  13. package/dist/log.d.ts +72 -0
  14. package/dist/log.js +133 -0
  15. package/dist/migrate.d.ts +10 -0
  16. package/dist/migrate.js +129 -0
  17. package/dist/migrations/postgres/0000_baseline.sql +502 -0
  18. package/dist/migrations/postgres/meta/0000_snapshot.json +1939 -0
  19. package/dist/migrations/postgres/meta/_journal.json +13 -0
  20. package/dist/migrations/sqlite/0000_baseline.sql +293 -0
  21. package/dist/migrations/sqlite/meta/0000_snapshot.json +1811 -0
  22. package/dist/migrations/sqlite/meta/_journal.json +13 -0
  23. package/dist/portable.d.ts +33 -0
  24. package/dist/portable.js +12 -0
  25. package/dist/relations-DqgxtlKu.js +58 -0
  26. package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
  27. package/dist/schema-Cd4WOnB5.d.ts +2503 -0
  28. package/dist/schema-sqlite.d.ts +2587 -0
  29. package/dist/schema-sqlite.js +401 -0
  30. package/dist/schema-version.d.ts +11 -0
  31. package/dist/schema-version.js +16 -0
  32. package/dist/schema.d.ts +2 -0
  33. package/dist/schema.js +448 -0
  34. package/package.json +91 -5
  35. package/src/baseline/postgres.sql +238 -0
  36. package/src/baseline/sqlite.sql +27 -0
  37. package/src/baseline.ts +104 -0
  38. package/src/commits.ts +47 -0
  39. package/src/connect.ts +168 -0
  40. package/src/database.ts +63 -0
  41. package/src/dialect.ts +174 -0
  42. package/src/drizzle.postgres.config.ts +7 -0
  43. package/src/drizzle.sqlite.config.ts +7 -0
  44. package/src/hyperdrive.ts +62 -0
  45. package/src/log.ts +177 -0
  46. package/src/migrate-main.ts +8 -0
  47. package/src/migrate.ts +206 -0
  48. package/src/migrations/postgres/0000_baseline.sql +502 -0
  49. package/src/migrations/postgres/meta/0000_snapshot.json +1939 -0
  50. package/src/migrations/postgres/meta/_journal.json +13 -0
  51. package/src/migrations/sqlite/0000_baseline.sql +293 -0
  52. package/src/migrations/sqlite/meta/0000_snapshot.json +1811 -0
  53. package/src/migrations/sqlite/meta/_journal.json +13 -0
  54. package/src/portable.ts +54 -0
  55. package/src/relations.ts +53 -0
  56. package/src/schema-version.ts +13 -0
  57. package/src/schema.sqlite.ts +511 -0
  58. package/src/schema.ts +548 -0
  59. package/src/verify-runtime.ts +120 -0
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": "7",
3
+ "dialect": "sqlite",
4
+ "entries": [
5
+ {
6
+ "idx": 0,
7
+ "version": "6",
8
+ "when": 1790874462505,
9
+ "tag": "0000_baseline",
10
+ "breakpoints": true
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,33 @@
1
+ import { l as schema_d_exports } from "./schema-Cd4WOnB5.js";
2
+ import { t as Database } from "./database-CWpo5aF0.js";
3
+ import { t as schema_sqlite_d_exports } from "./schema-sqlite.js";
4
+ import { LibSQLDatabase } from "drizzle-orm/libsql";
5
+ //#region src/portable.d.ts
6
+ /**
7
+ * The one place a SQLite database becomes a Postgres one.
8
+ *
9
+ * Drizzle has no type that spans dialects, so the queries are written once,
10
+ * against the Postgres schema, and a SQLite database is handed to
11
+ * them under the Postgres type. That holds because both schemas have the
12
+ * same tables with the same row types (checked below, at compile time, and
13
+ * in schema-parity.test.ts, at run time), and because every query runs on
14
+ * the database's own tables: queries.ts reads them from the database it is
15
+ * given (`tablesOf`), never from an import. A Postgres column on a SQLite
16
+ * database would encode its values the Postgres way.
17
+ */
18
+ export type PostgresSchema = typeof schema_d_exports;
19
+ /** Some of a schema's tables, read as their Postgres twins. */
20
+ export declare function asPostgres<Tables extends Partial<Record<keyof PostgresSchema, unknown>>>(tables: Tables): Pick<PostgresSchema, keyof Tables & keyof PostgresSchema>;
21
+ /** A SQLite database, read as a Postgres one. */
22
+ export declare function asPostgresDatabase(db: LibSQLDatabase<typeof schema_sqlite_d_exports>): Database;
23
+ type TableName = { [K in keyof PostgresSchema]: PostgresSchema[K] extends {
24
+ $inferSelect: object;
25
+ } ? K : never; }[keyof PostgresSchema];
26
+ type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;
27
+ /** The tables whose rows differ from their Postgres twin's; never if none. */
28
+ type Mismatched<Schema extends Record<TableName, {
29
+ $inferSelect: object;
30
+ }>> = { [K in TableName]: Equal<Schema[K]['$inferSelect'], PostgresSchema[K]['$inferSelect']> extends true ? never : K; }[TableName];
31
+ type None<T extends never> = T;
32
+ export type SqliteRowsMatch = None<Mismatched<typeof schema_sqlite_d_exports>>;
33
+ //#endregion
@@ -0,0 +1,12 @@
1
+ import { n as trackCommits } from "./commits-BuW-NL3n.js";
2
+ //#region src/portable.ts
3
+ /** Some of a schema's tables, read as their Postgres twins. */
4
+ function asPostgres(tables) {
5
+ return tables;
6
+ }
7
+ /** A SQLite database, read as a Postgres one. */
8
+ function asPostgresDatabase(db) {
9
+ return trackCommits(db);
10
+ }
11
+ //#endregion
12
+ export { asPostgres, asPostgresDatabase };
@@ -0,0 +1,58 @@
1
+ import { relations, sql } from "drizzle-orm";
2
+ //#region src/relations.ts
3
+ /**
4
+ * What both schemas share beyond their columns: the relations and the
5
+ * one generated column.
6
+ *
7
+ * Relations are for Drizzle's relational queries (`db.query.syncs
8
+ * .findMany({ with })`), which read a row and what hangs off it in one
9
+ * statement on every dialect. They add no constraints; the foreign keys in
10
+ * each schema do that. Each schema calls this with its own tables, so a
11
+ * relational query on SQLite joins SQLite tables.
12
+ */
13
+ function relationsOf(t) {
14
+ return {
15
+ environmentsRelations: relations(t.environments, ({ one }) => ({ project: one(t.projects, {
16
+ fields: [t.environments.projectId],
17
+ references: [t.projects.id]
18
+ }) })),
19
+ secretsRelations: relations(t.secrets, ({ one }) => ({
20
+ project: one(t.projects, {
21
+ fields: [t.secrets.projectId],
22
+ references: [t.projects.id]
23
+ }),
24
+ environment: one(t.environments, {
25
+ fields: [t.secrets.environmentId],
26
+ references: [t.environments.id]
27
+ })
28
+ })),
29
+ syncsRelations: relations(t.syncs, ({ one, many }) => ({
30
+ project: one(t.projects, {
31
+ fields: [t.syncs.projectId],
32
+ references: [t.projects.id]
33
+ }),
34
+ environment: one(t.environments, {
35
+ fields: [t.syncs.environmentId],
36
+ references: [t.environments.id]
37
+ }),
38
+ credential: one(t.secrets, {
39
+ fields: [t.syncs.credentialSecretId],
40
+ references: [t.secrets.id]
41
+ }),
42
+ keys: many(t.syncKeys)
43
+ })),
44
+ syncKeysRelations: relations(t.syncKeys, ({ one }) => ({ sync: one(t.syncs, {
45
+ fields: [t.syncKeys.syncId],
46
+ references: [t.syncs.id]
47
+ }) }))
48
+ };
49
+ }
50
+ /**
51
+ * `identities.active_subject`: the subject while the account is bound, null
52
+ * once revoked. A unique index on (provider, issuer_hash, active_subject)
53
+ * binds an account to one person at a time. Plain column names, so the
54
+ * expression reads the same on both databases.
55
+ */
56
+ const ACTIVE_SUBJECT = sql`CASE WHEN revoked_at IS NULL THEN subject END`;
57
+ //#endregion
58
+ export { relationsOf as n, ACTIVE_SUBJECT as t };
@@ -0,0 +1,13 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ export { __exportAll as t };