@coffre/db 0.0.0 → 0.1.1
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/LICENSE +21 -0
- package/README.md +19 -3
- package/dist/commits-BuW-NL3n.js +30 -0
- package/dist/connect.d.ts +26 -0
- package/dist/connect.js +156 -0
- package/dist/database-CWpo5aF0.d.ts +39 -0
- package/dist/dialect.d.ts +88 -0
- package/dist/dialect.js +128 -0
- package/dist/hyperdrive.d.ts +32 -0
- package/dist/hyperdrive.js +54 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +34 -0
- package/dist/log.d.ts +72 -0
- package/dist/log.js +133 -0
- package/dist/migrate.d.ts +10 -0
- package/dist/migrate.js +130 -0
- package/dist/migrations/postgres/0000_baseline.sql +505 -0
- package/dist/migrations/postgres/meta/0000_snapshot.json +1939 -0
- package/dist/migrations/postgres/meta/_journal.json +13 -0
- package/dist/migrations/sqlite/0000_baseline.sql +293 -0
- package/dist/migrations/sqlite/meta/0000_snapshot.json +1811 -0
- package/dist/migrations/sqlite/meta/_journal.json +13 -0
- package/dist/portable.d.ts +33 -0
- package/dist/portable.js +12 -0
- package/dist/postgres-Bmar8y0q.js +29 -0
- package/dist/relations-DqgxtlKu.js +58 -0
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/schema-Cd4WOnB5.d.ts +2503 -0
- package/dist/schema-sqlite.d.ts +2587 -0
- package/dist/schema-sqlite.js +401 -0
- package/dist/schema-version.d.ts +11 -0
- package/dist/schema-version.js +16 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +448 -0
- package/package.json +92 -5
- package/src/baseline/postgres.sql +241 -0
- package/src/baseline/sqlite.sql +27 -0
- package/src/baseline.ts +104 -0
- package/src/commits.ts +47 -0
- package/src/connect.ts +171 -0
- package/src/database.ts +63 -0
- package/src/dialect.ts +174 -0
- package/src/drizzle.postgres.config.ts +7 -0
- package/src/drizzle.sqlite.config.ts +7 -0
- package/src/hyperdrive.ts +63 -0
- package/src/log.ts +177 -0
- package/src/migrate-main.ts +8 -0
- package/src/migrate.ts +207 -0
- package/src/migrations/postgres/0000_baseline.sql +505 -0
- package/src/migrations/postgres/meta/0000_snapshot.json +1939 -0
- package/src/migrations/postgres/meta/_journal.json +13 -0
- package/src/migrations/sqlite/0000_baseline.sql +293 -0
- package/src/migrations/sqlite/meta/0000_snapshot.json +1811 -0
- package/src/migrations/sqlite/meta/_journal.json +13 -0
- package/src/portable.ts +54 -0
- package/src/postgres.ts +35 -0
- package/src/relations.ts +53 -0
- package/src/schema-version.ts +13 -0
- package/src/schema.sqlite.ts +511 -0
- package/src/schema.ts +548 -0
- package/src/verify-runtime.ts +122 -0
|
@@ -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
|
package/dist/portable.js
ADDED
|
@@ -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,29 @@
|
|
|
1
|
+
import { checkServerIdentity } from "node:tls";
|
|
2
|
+
import { parseIntoClientConfig } from "pg-connection-string";
|
|
3
|
+
//#region src/postgres.ts
|
|
4
|
+
/** Keep libpq's system-root shortcut from being read as a certificate filename by pg. */
|
|
5
|
+
function postgresConnection(url) {
|
|
6
|
+
let parsed;
|
|
7
|
+
try {
|
|
8
|
+
parsed = new URL(url);
|
|
9
|
+
} catch {
|
|
10
|
+
throw new Error("invalid Postgres URL");
|
|
11
|
+
}
|
|
12
|
+
const parameters = parsed.searchParams;
|
|
13
|
+
if (parameters.getAll("sslrootcert").at(-1) !== "system") return { connectionString: url };
|
|
14
|
+
const mode = parameters.getAll("sslmode").at(-1);
|
|
15
|
+
if (mode !== void 0 && mode !== "verify-full") throw new Error("sslrootcert=system requires sslmode=verify-full");
|
|
16
|
+
parameters.delete("sslrootcert");
|
|
17
|
+
parameters.set("sslmode", "verify-full");
|
|
18
|
+
const config = parseIntoClientConfig(parsed.toString());
|
|
19
|
+
const host = config.host;
|
|
20
|
+
if (!host) throw new Error("sslrootcert=system requires a Postgres hostname");
|
|
21
|
+
config.ssl = {
|
|
22
|
+
...config.ssl,
|
|
23
|
+
rejectUnauthorized: true,
|
|
24
|
+
checkServerIdentity: (_hostname, certificate) => checkServerIdentity(host, certificate)
|
|
25
|
+
};
|
|
26
|
+
return config;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { postgresConnection as t };
|
|
@@ -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 };
|