@lunora/hyperdrive 1.0.0-alpha.9 → 1.0.0-alpha.90
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.md +6 -0
- package/dist/global.d.mts +100 -45
- package/dist/global.d.ts +100 -45
- package/dist/global.mjs +1 -9
- package/dist/index.d.mts +135 -152
- package/dist/index.d.ts +135 -152
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/buildMysqlExec-CPwtojyL.mjs +1 -0
- package/dist/packem_shared/createHyperdrive-DEXMfGd0.mjs +1 -0
- package/dist/packem_shared/mysqlDialect-DitNAlpV.mjs +1 -0
- package/dist/packem_shared/projectSourceRow-DN8ywPRl.mjs +1 -0
- package/dist/packem_shared/types.d-DE1NYxyA.d.mts +113 -0
- package/dist/packem_shared/types.d-DE1NYxyA.d.ts +113 -0
- package/package.json +4 -3
- package/dist/packem_shared/buildMysqlExec-DBbCjyq3.mjs +0 -23
- package/dist/packem_shared/createHyperdrive-DD8GoDZo.mjs +0 -36
- package/dist/packem_shared/mysqlDialect-oNhZ58s8.mjs +0 -102
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const createHyperdrive = (binding) => {
|
|
2
|
-
const config = {
|
|
3
|
-
database: binding.database,
|
|
4
|
-
host: binding.host,
|
|
5
|
-
password: binding.password,
|
|
6
|
-
port: binding.port,
|
|
7
|
-
user: binding.user
|
|
8
|
-
};
|
|
9
|
-
return { config, connectionString: binding.connectionString };
|
|
10
|
-
};
|
|
11
|
-
const fromPostgresJs = (client) => {
|
|
12
|
-
return {
|
|
13
|
-
query: async (text, params = []) => {
|
|
14
|
-
const rows = await client.unsafe(text, params);
|
|
15
|
-
return rows;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
const fromNodePg = (client) => {
|
|
20
|
-
return {
|
|
21
|
-
query: async (text, params = []) => {
|
|
22
|
-
const result = await client.query(text, params);
|
|
23
|
-
return result.rows;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
const fromMysql2 = (connection) => {
|
|
28
|
-
return {
|
|
29
|
-
query: async (text, params = []) => {
|
|
30
|
-
const [rows] = await connection.execute(text, params);
|
|
31
|
-
return Array.isArray(rows) ? rows : [];
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export { createHyperdrive, fromMysql2, fromNodePg, fromPostgresJs };
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { sqliteEncode, sqliteDecode } from '@lunora/sql-store';
|
|
2
|
-
import { sql } from 'drizzle-orm';
|
|
3
|
-
|
|
4
|
-
const PG_UNIQUE_VIOLATION_RE = /duplicate key value violates unique constraint/iu;
|
|
5
|
-
const mysqlColumnType = (kind) => {
|
|
6
|
-
switch (kind) {
|
|
7
|
-
case "array":
|
|
8
|
-
case "object":
|
|
9
|
-
case "record": {
|
|
10
|
-
return "JSON";
|
|
11
|
-
}
|
|
12
|
-
case "bigint": {
|
|
13
|
-
return "VARCHAR(64)";
|
|
14
|
-
}
|
|
15
|
-
case "boolean": {
|
|
16
|
-
return "TINYINT";
|
|
17
|
-
}
|
|
18
|
-
case "bytes": {
|
|
19
|
-
return "LONGBLOB";
|
|
20
|
-
}
|
|
21
|
-
case "date":
|
|
22
|
-
case "number":
|
|
23
|
-
case "timestamp": {
|
|
24
|
-
return "DOUBLE";
|
|
25
|
-
}
|
|
26
|
-
default: {
|
|
27
|
-
return "LONGTEXT";
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const MYSQL_PREFIX_INDEX_RE = /TEXT|BLOB/u;
|
|
32
|
-
const postgresDialect = {
|
|
33
|
-
companionTypes: {
|
|
34
|
-
autoincrementPrimaryKey: "BIGSERIAL PRIMARY KEY",
|
|
35
|
-
integer: "INTEGER",
|
|
36
|
-
key: "TEXT",
|
|
37
|
-
real: "DOUBLE PRECISION",
|
|
38
|
-
text: "TEXT"
|
|
39
|
-
},
|
|
40
|
-
columnType: (kind) => {
|
|
41
|
-
switch (kind) {
|
|
42
|
-
case "boolean": {
|
|
43
|
-
return "INTEGER";
|
|
44
|
-
}
|
|
45
|
-
case "bytes": {
|
|
46
|
-
return "BYTEA";
|
|
47
|
-
}
|
|
48
|
-
case "date":
|
|
49
|
-
case "number":
|
|
50
|
-
case "timestamp": {
|
|
51
|
-
return "DOUBLE PRECISION";
|
|
52
|
-
}
|
|
53
|
-
default: {
|
|
54
|
-
return "TEXT";
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
decode: (value, kind) => sqliteDecode(value, kind),
|
|
59
|
-
encode: (value) => sqliteEncode(value),
|
|
60
|
-
frameworkColumns: () => [
|
|
61
|
-
{ name: "id", type: "TEXT PRIMARY KEY" },
|
|
62
|
-
{ name: "_creationTime", type: "DOUBLE PRECISION NOT NULL" }
|
|
63
|
-
],
|
|
64
|
-
isUniqueViolation: (error) => {
|
|
65
|
-
const { code } = error;
|
|
66
|
-
return code === "23505" || error instanceof Error && PG_UNIQUE_VIOLATION_RE.test(error.message);
|
|
67
|
-
},
|
|
68
|
-
name: "postgres",
|
|
69
|
-
supportsReturning: true,
|
|
70
|
-
tableExists: (table) => sql`SELECT table_name FROM information_schema.tables WHERE table_name = ${table}`
|
|
71
|
-
};
|
|
72
|
-
const mysqlDialect = {
|
|
73
|
-
affectedRows: (result) => result.rowsAffected,
|
|
74
|
-
companionTypes: {
|
|
75
|
-
autoincrementPrimaryKey: "BIGINT AUTO_INCREMENT PRIMARY KEY",
|
|
76
|
-
integer: "INTEGER",
|
|
77
|
-
// VARCHAR so it can be a PRIMARY KEY and be fully indexed (TEXT cannot,
|
|
78
|
-
// without a prefix length). 768 = InnoDB utf8mb4 single-column index limit.
|
|
79
|
-
key: "VARCHAR(768)",
|
|
80
|
-
real: "DOUBLE",
|
|
81
|
-
// Unbounded post-image storage (CDC `doc`); never an index key, so no bound.
|
|
82
|
-
text: "LONGTEXT"
|
|
83
|
-
},
|
|
84
|
-
columnType: (kind) => mysqlColumnType(kind),
|
|
85
|
-
decode: (value, kind) => sqliteDecode(value, kind),
|
|
86
|
-
encode: (value) => sqliteEncode(value),
|
|
87
|
-
frameworkColumns: () => [
|
|
88
|
-
{ name: "id", type: "VARCHAR(768) PRIMARY KEY" },
|
|
89
|
-
{ name: "_creationTime", type: "DOUBLE NOT NULL" }
|
|
90
|
-
],
|
|
91
|
-
// InnoDB can't index a TEXT/LONGTEXT/BLOB column without a key prefix; bound it to 768 chars.
|
|
92
|
-
indexKeyPrefix: (kind) => MYSQL_PREFIX_INDEX_RE.test(mysqlColumnType(kind)) ? 768 : void 0,
|
|
93
|
-
isUniqueViolation: (error) => {
|
|
94
|
-
const candidate = error;
|
|
95
|
-
return candidate.errno === 1062 || candidate.code === "ER_DUP_ENTRY";
|
|
96
|
-
},
|
|
97
|
-
name: "mysql",
|
|
98
|
-
supportsReturning: false,
|
|
99
|
-
tableExists: (table) => sql`SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ${table}`
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export { mysqlDialect, postgresDialect };
|