@b9g/zen 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.
- package/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +1044 -0
- package/chunk-2IEEEMRN.js +38 -0
- package/chunk-56M5Z3A6.js +1346 -0
- package/chunk-QXGEP5PB.js +310 -0
- package/ddl-NAJM37GQ.js +9 -0
- package/package.json +102 -0
- package/src/bun.d.ts +50 -0
- package/src/bun.js +906 -0
- package/src/mysql.d.ts +62 -0
- package/src/mysql.js +573 -0
- package/src/postgres.d.ts +62 -0
- package/src/postgres.js +555 -0
- package/src/sqlite.d.ts +43 -0
- package/src/sqlite.js +447 -0
- package/src/zen.d.ts +14 -0
- package/src/zen.js +2143 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isSQLIdentifier
|
|
3
|
+
} from "./chunk-56M5Z3A6.js";
|
|
4
|
+
|
|
5
|
+
// src/impl/sql.ts
|
|
6
|
+
function quoteIdent(name, dialect) {
|
|
7
|
+
if (dialect === "mysql") {
|
|
8
|
+
return `\`${name.replace(/`/g, "``")}\``;
|
|
9
|
+
}
|
|
10
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
11
|
+
}
|
|
12
|
+
function placeholder(index, dialect) {
|
|
13
|
+
if (dialect === "postgresql") {
|
|
14
|
+
return `$${index}`;
|
|
15
|
+
}
|
|
16
|
+
return "?";
|
|
17
|
+
}
|
|
18
|
+
function renderDDL(strings, values, dialect) {
|
|
19
|
+
let sql = "";
|
|
20
|
+
for (let i = 0; i < strings.length; i++) {
|
|
21
|
+
sql += strings[i];
|
|
22
|
+
if (i < values.length) {
|
|
23
|
+
const value = values[i];
|
|
24
|
+
if (isSQLIdentifier(value)) {
|
|
25
|
+
sql += quoteIdent(value.name, dialect);
|
|
26
|
+
} else {
|
|
27
|
+
throw new Error(`Unexpected value in DDL template: ${value}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return sql;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
quoteIdent,
|
|
36
|
+
placeholder,
|
|
37
|
+
renderDDL
|
|
38
|
+
};
|