drizzle-sybase 1.1.0 → 1.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.
- package/README.md +57 -0
- package/binding.gyp +22 -0
- package/dist/introspect/__tests__/introspect.test.d.ts +2 -0
- package/dist/introspect/__tests__/introspect.test.d.ts.map +1 -0
- package/dist/introspect/__tests__/introspect.test.js +411 -0
- package/dist/introspect/__tests__/introspect.test.js.map +1 -0
- package/dist/introspect/cli.d.ts +3 -0
- package/dist/introspect/cli.d.ts.map +1 -0
- package/dist/introspect/cli.js +13 -0
- package/dist/introspect/cli.js.map +1 -0
- package/dist/introspect/codegen.d.ts +24 -0
- package/dist/introspect/codegen.d.ts.map +1 -0
- package/dist/introspect/codegen.js +342 -0
- package/dist/introspect/codegen.js.map +1 -0
- package/dist/introspect/fetch.d.ts +28 -0
- package/dist/introspect/fetch.d.ts.map +1 -0
- package/dist/introspect/fetch.js +154 -0
- package/dist/introspect/fetch.js.map +1 -0
- package/dist/introspect/index.d.ts +50 -0
- package/dist/introspect/index.d.ts.map +1 -0
- package/dist/introspect/index.js +133 -0
- package/dist/introspect/index.js.map +1 -0
- package/dist/introspect/type-map.d.ts +60 -0
- package/dist/introspect/type-map.d.ts.map +1 -0
- package/dist/introspect/type-map.js +72 -0
- package/dist/introspect/type-map.js.map +1 -0
- package/dist/introspect/types.d.ts +62 -0
- package/dist/introspect/types.d.ts.map +1 -0
- package/dist/introspect/types.js +9 -0
- package/dist/introspect/types.js.map +1 -0
- package/dist/native/sybase_native.darwin-arm64.node +0 -0
- package/dist/native/sybase_native.darwin-x64.node +0 -0
- package/dist/native/sybase_native.win32-x64.node +0 -0
- package/package.json +15 -8
- package/scripts/build-win.ps1 +5 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sybase ASE schema introspection — public entry point.
|
|
3
|
+
*
|
|
4
|
+
* Connects to a Sybase database, reads the system catalogs, and returns
|
|
5
|
+
* generated drizzle-sybase source code (table definitions, index metadata and
|
|
6
|
+
* Zod select/insert schemas).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { introspectSybase } from "drizzle-sybase/introspect";
|
|
11
|
+
*
|
|
12
|
+
* const { code, warnings } = await introspectSybase({
|
|
13
|
+
* host: "sybase-host",
|
|
14
|
+
* port: 5000,
|
|
15
|
+
* database: "mydb",
|
|
16
|
+
* username: "sa",
|
|
17
|
+
* password: "secret",
|
|
18
|
+
* tables: ["users", "orders"]
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import { writeFileSync } from "node:fs";
|
|
23
|
+
import { createSybaseDrizzle } from "../db.js";
|
|
24
|
+
import { generateSchemaCode } from "./codegen.js";
|
|
25
|
+
import { fetchColumns, fetchIndexes, fetchTables } from "./fetch.js";
|
|
26
|
+
export { SYBASE_TYPE_MAP } from "./type-map.js";
|
|
27
|
+
/**
|
|
28
|
+
* Introspect a Sybase database using an already-connected db handle.
|
|
29
|
+
*
|
|
30
|
+
* Useful when the caller owns connection lifecycle / credentials (e.g. fetched
|
|
31
|
+
* from a secrets manager) and wants to reuse an existing pool. The handle is
|
|
32
|
+
* not closed by this function.
|
|
33
|
+
*/
|
|
34
|
+
export async function introspectWith(db, options) {
|
|
35
|
+
const tables = await fetchTables(db, options.database, options.tables, options.owner);
|
|
36
|
+
const tableMetas = [];
|
|
37
|
+
for (const { name, owner } of tables) {
|
|
38
|
+
const [columns, indexes] = await Promise.all([
|
|
39
|
+
fetchColumns(db, options.database, name),
|
|
40
|
+
fetchIndexes(db, options.database, name)
|
|
41
|
+
]);
|
|
42
|
+
tableMetas.push({ name, owner, columns, indexes });
|
|
43
|
+
}
|
|
44
|
+
return generateSchemaCode(tableMetas, options.database);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Introspect a Sybase database and return generated code as a string.
|
|
48
|
+
*
|
|
49
|
+
* Opens a short-lived pool, introspects, and always closes the pool.
|
|
50
|
+
*/
|
|
51
|
+
export async function introspectSybase(config) {
|
|
52
|
+
const db = createSybaseDrizzle({
|
|
53
|
+
host: config.host,
|
|
54
|
+
port: config.port,
|
|
55
|
+
database: config.database,
|
|
56
|
+
username: config.username,
|
|
57
|
+
password: config.password,
|
|
58
|
+
max: 2,
|
|
59
|
+
timeout: config.timeout ?? 30
|
|
60
|
+
});
|
|
61
|
+
try {
|
|
62
|
+
return await introspectWith(db, {
|
|
63
|
+
database: config.database,
|
|
64
|
+
tables: config.tables,
|
|
65
|
+
owner: config.owner
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
await db.close();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// CLI
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
const USAGE = `Usage:
|
|
76
|
+
drizzle-sybase-introspect --host=<host> --port=5000 --database=<db> \\
|
|
77
|
+
--username=<user> --password=<pass> \\
|
|
78
|
+
[--tables=TABLE1,TABLE2] [--owner=dbo] [--out=path/to/output.ts]
|
|
79
|
+
|
|
80
|
+
Or set env vars: SYBASE_HOST, SYBASE_PORT, SYBASE_DATABASE, SYBASE_USERNAME, SYBASE_PASSWORD, SYBASE_TABLES`;
|
|
81
|
+
/**
|
|
82
|
+
* CLI entry point. Parses `process.argv` and runs introspection, printing to
|
|
83
|
+
* stdout or writing to `--out`.
|
|
84
|
+
*/
|
|
85
|
+
export async function runCli(argv = process.argv.slice(2)) {
|
|
86
|
+
const parseArg = (name) => {
|
|
87
|
+
const arg = argv.find(a => a.startsWith(`--${name}=`));
|
|
88
|
+
return arg?.split("=").slice(1).join("=");
|
|
89
|
+
};
|
|
90
|
+
const host = parseArg("host") ?? process.env.SYBASE_HOST;
|
|
91
|
+
const portRaw = parseArg("port") ?? process.env.SYBASE_PORT ?? "5000";
|
|
92
|
+
const port = Number(portRaw);
|
|
93
|
+
const database = parseArg("database") ?? process.env.SYBASE_DATABASE;
|
|
94
|
+
const username = parseArg("username") ?? process.env.SYBASE_USERNAME;
|
|
95
|
+
const password = parseArg("password") ?? process.env.SYBASE_PASSWORD;
|
|
96
|
+
const tables = (parseArg("tables") ?? process.env.SYBASE_TABLES)
|
|
97
|
+
?.split(",")
|
|
98
|
+
.map(t => t.trim())
|
|
99
|
+
.filter(Boolean);
|
|
100
|
+
const owner = parseArg("owner");
|
|
101
|
+
const out = parseArg("out");
|
|
102
|
+
if (!host || !database || !username || !password) {
|
|
103
|
+
console.error(USAGE);
|
|
104
|
+
process.exitCode = 1;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (!Number.isInteger(port) || port <= 0 || port > 65535) {
|
|
108
|
+
console.error(`Invalid port: "${portRaw}". Expected an integer in 1-65535.`);
|
|
109
|
+
process.exitCode = 1;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
console.log(`Connecting to ${host}:${port}/${database}...`);
|
|
113
|
+
const { code, warnings } = await introspectSybase({
|
|
114
|
+
host,
|
|
115
|
+
port,
|
|
116
|
+
database,
|
|
117
|
+
username,
|
|
118
|
+
password,
|
|
119
|
+
tables,
|
|
120
|
+
owner
|
|
121
|
+
});
|
|
122
|
+
for (const warning of warnings) {
|
|
123
|
+
console.warn(`warning: ${warning}`);
|
|
124
|
+
}
|
|
125
|
+
if (out) {
|
|
126
|
+
writeFileSync(out, code, "utf-8");
|
|
127
|
+
console.log(`Schema written to ${out}`);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
console.log("\n" + code);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/introspect/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAA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AAQ;QACR,MAAM;QACN,KAAK;KACN,CAAC,CAAC;IAEH,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,OAAO,CAAC,IAAI,CAAC,YAAY,OAAO,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,GAAG,EAAE,CAAC;QACR,aAAa,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAClC,OAAO,CAAC,GAAG,CAAC,qBAAqB,GAAG,EAAE,CAAC,CAAC;IAC1C,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth mapping Sybase ASE system type names to:
|
|
3
|
+
* - the drizzle-sybase column factory (`int`, `varchar`, ...),
|
|
4
|
+
* - the corresponding Zod validator,
|
|
5
|
+
* - the TypeScript value type.
|
|
6
|
+
*
|
|
7
|
+
* Every code generator (column builders, Zod schemas, import collection) reads
|
|
8
|
+
* from this one registry, so adding a type — or fixing a mapping — happens in
|
|
9
|
+
* exactly one place and can never drift between generators.
|
|
10
|
+
*
|
|
11
|
+
* The set of factory names here is kept in lock-step with the exports of
|
|
12
|
+
* `../columns/index.ts`.
|
|
13
|
+
*/
|
|
14
|
+
import type { ColumnMeta } from "./types.js";
|
|
15
|
+
/** How a Sybase type renders its size modifier in a column builder call. */
|
|
16
|
+
export type SizeKind =
|
|
17
|
+
/** No size argument, e.g. `int("c")`. */
|
|
18
|
+
"none"
|
|
19
|
+
/** `{ length: n }`, e.g. `varchar("c", { length: 10 })`. */
|
|
20
|
+
| "length"
|
|
21
|
+
/** `{ precision: p, scale: s }`, e.g. `numeric("c", { precision: 10, scale: 2 })`. */
|
|
22
|
+
| "precision";
|
|
23
|
+
/** The JS value category a column maps to (drives the Zod validator). */
|
|
24
|
+
export type ValueKind = "number" | "boolean" | "date" | "buffer" | "string";
|
|
25
|
+
export interface TypeMapping {
|
|
26
|
+
/** drizzle-sybase column factory name (also the import identifier). */
|
|
27
|
+
factory: string;
|
|
28
|
+
size: SizeKind;
|
|
29
|
+
value: ValueKind;
|
|
30
|
+
/**
|
|
31
|
+
* National (Unicode) char types store byte length in the catalog but the
|
|
32
|
+
* builder/zod expect character length, so the byte length is halved.
|
|
33
|
+
*/
|
|
34
|
+
nationalChar?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Sybase base system type name (lower-cased) -> mapping.
|
|
38
|
+
*
|
|
39
|
+
* Keys are the canonical system type names returned after UDT resolution.
|
|
40
|
+
*/
|
|
41
|
+
export declare const SYBASE_TYPE_MAP: Readonly<Record<string, TypeMapping>>;
|
|
42
|
+
/**
|
|
43
|
+
* Fallback used when a Sybase type is not in the registry. We render it as a
|
|
44
|
+
* variable-length string so the generated schema still compiles, but emit a
|
|
45
|
+
* warning so unmapped types are not silently misrepresented.
|
|
46
|
+
*/
|
|
47
|
+
export declare const FALLBACK_MAPPING: TypeMapping;
|
|
48
|
+
/** Resolve a column's type mapping, falling back to `varchar` for unknown types. */
|
|
49
|
+
export declare function resolveMapping(typeName: string): {
|
|
50
|
+
mapping: TypeMapping;
|
|
51
|
+
isFallback: boolean;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Effective character length for a column, halving the catalog byte length for
|
|
55
|
+
* national (Unicode) char types. Never returns less than 1 — a zero/negative
|
|
56
|
+
* catalog length would otherwise emit `{ length: 0 }`, which is not a valid
|
|
57
|
+
* column width.
|
|
58
|
+
*/
|
|
59
|
+
export declare function effectiveLength(col: ColumnMeta, mapping: TypeMapping): number;
|
|
60
|
+
//# sourceMappingURL=type-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-map.d.ts","sourceRoot":"","sources":["../../src/introspect/type-map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,4EAA4E;AAC5E,MAAM,MAAM,QAAQ;AAClB,yCAAyC;AACvC,MAAM;AACR,4DAA4D;GAC1D,QAAQ;AACV,sFAAsF;GACpF,WAAW,CAAC;AAEhB,yEAAyE;AACzE,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE5E,MAAM,WAAW,WAAW;IAC1B,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,SAAS,CAAC;IACjB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CA6BxD,CAAC;AAEX;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,WAI9B,CAAC;AAEF,oFAAoF;AACpF,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG;IAChD,OAAO,EAAE,WAAW,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;CACrB,CAOA;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAG7E"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth mapping Sybase ASE system type names to:
|
|
3
|
+
* - the drizzle-sybase column factory (`int`, `varchar`, ...),
|
|
4
|
+
* - the corresponding Zod validator,
|
|
5
|
+
* - the TypeScript value type.
|
|
6
|
+
*
|
|
7
|
+
* Every code generator (column builders, Zod schemas, import collection) reads
|
|
8
|
+
* from this one registry, so adding a type — or fixing a mapping — happens in
|
|
9
|
+
* exactly one place and can never drift between generators.
|
|
10
|
+
*
|
|
11
|
+
* The set of factory names here is kept in lock-step with the exports of
|
|
12
|
+
* `../columns/index.ts`.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Sybase base system type name (lower-cased) -> mapping.
|
|
16
|
+
*
|
|
17
|
+
* Keys are the canonical system type names returned after UDT resolution.
|
|
18
|
+
*/
|
|
19
|
+
export const SYBASE_TYPE_MAP = {
|
|
20
|
+
int: { factory: "int", size: "none", value: "number" },
|
|
21
|
+
bigint: { factory: "bigint", size: "none", value: "number" },
|
|
22
|
+
smallint: { factory: "smallint", size: "none", value: "number" },
|
|
23
|
+
tinyint: { factory: "tinyint", size: "none", value: "number" },
|
|
24
|
+
varchar: { factory: "varchar", size: "length", value: "string" },
|
|
25
|
+
nvarchar: { factory: "nvarchar", size: "length", value: "string", nationalChar: true },
|
|
26
|
+
char: { factory: "char", size: "length", value: "string" },
|
|
27
|
+
nchar: { factory: "nchar", size: "length", value: "string", nationalChar: true },
|
|
28
|
+
text: { factory: "text", size: "none", value: "string" },
|
|
29
|
+
ntext: { factory: "ntext", size: "none", value: "string" },
|
|
30
|
+
datetime: { factory: "datetime", size: "none", value: "date" },
|
|
31
|
+
smalldatetime: { factory: "smalldatetime", size: "none", value: "date" },
|
|
32
|
+
numeric: { factory: "numeric", size: "precision", value: "number" },
|
|
33
|
+
decimal: { factory: "numeric", size: "precision", value: "number" },
|
|
34
|
+
float: { factory: "float", size: "none", value: "number" },
|
|
35
|
+
real: { factory: "real", size: "none", value: "number" },
|
|
36
|
+
money: { factory: "money", size: "none", value: "number" },
|
|
37
|
+
smallmoney: { factory: "smallmoney", size: "none", value: "number" },
|
|
38
|
+
bit: { factory: "bit", size: "none", value: "boolean" },
|
|
39
|
+
binary: { factory: "binary", size: "length", value: "buffer" },
|
|
40
|
+
varbinary: { factory: "varbinary", size: "length", value: "buffer" },
|
|
41
|
+
image: { factory: "image", size: "none", value: "buffer" }
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Fallback used when a Sybase type is not in the registry. We render it as a
|
|
45
|
+
* variable-length string so the generated schema still compiles, but emit a
|
|
46
|
+
* warning so unmapped types are not silently misrepresented.
|
|
47
|
+
*/
|
|
48
|
+
export const FALLBACK_MAPPING = {
|
|
49
|
+
factory: "varchar",
|
|
50
|
+
size: "length",
|
|
51
|
+
value: "string"
|
|
52
|
+
};
|
|
53
|
+
/** Resolve a column's type mapping, falling back to `varchar` for unknown types. */
|
|
54
|
+
export function resolveMapping(typeName) {
|
|
55
|
+
// Use Object.hasOwn so prototype keys (e.g. "constructor", "toString") that
|
|
56
|
+
// could appear as a (malformed) type name never resolve to inherited members.
|
|
57
|
+
if (Object.hasOwn(SYBASE_TYPE_MAP, typeName)) {
|
|
58
|
+
return { mapping: SYBASE_TYPE_MAP[typeName], isFallback: false };
|
|
59
|
+
}
|
|
60
|
+
return { mapping: FALLBACK_MAPPING, isFallback: true };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Effective character length for a column, halving the catalog byte length for
|
|
64
|
+
* national (Unicode) char types. Never returns less than 1 — a zero/negative
|
|
65
|
+
* catalog length would otherwise emit `{ length: 0 }`, which is not a valid
|
|
66
|
+
* column width.
|
|
67
|
+
*/
|
|
68
|
+
export function effectiveLength(col, mapping) {
|
|
69
|
+
const raw = mapping.nationalChar ? Math.floor(col.length / 2) : col.length;
|
|
70
|
+
return raw > 0 ? raw : 1;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=type-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-map.js","sourceRoot":"","sources":["../../src/introspect/type-map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA4BH;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAA0C;IACpE,GAAG,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE;IACtD,MAAM,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM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C;IACD,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,GAAe,EAAE,OAAoB;IACnE,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC;IAC3E,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Sybase ASE schema introspection.
|
|
3
|
+
*
|
|
4
|
+
* These describe the metadata extracted from the system catalogs
|
|
5
|
+
* (sysobjects / syscolumns / systypes / sysindexes) and the configuration
|
|
6
|
+
* accepted by {@link introspectSybase}.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Minimal database surface required by the introspection layer.
|
|
10
|
+
*
|
|
11
|
+
* Intentionally narrower than {@link SybaseDrizzle} so the fetch functions can
|
|
12
|
+
* be unit-tested with a lightweight mock that only implements `executeRaw`.
|
|
13
|
+
*/
|
|
14
|
+
export interface IntrospectDb {
|
|
15
|
+
executeRaw<T extends Record<string, unknown> = Record<string, unknown>>(rawSql: string): Promise<{
|
|
16
|
+
rows: T[];
|
|
17
|
+
rowCount: number;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
/** Configuration for {@link introspectSybase}. */
|
|
21
|
+
export interface IntrospectConfig {
|
|
22
|
+
host: string;
|
|
23
|
+
port: number;
|
|
24
|
+
database: string;
|
|
25
|
+
username: string;
|
|
26
|
+
password: string;
|
|
27
|
+
/** Restrict introspection to these tables. When omitted, all user tables are introspected. */
|
|
28
|
+
tables?: string[];
|
|
29
|
+
/** Restrict introspection to tables owned by this user (e.g. `dbo`). */
|
|
30
|
+
owner?: string;
|
|
31
|
+
/** Per-query timeout in seconds. Default: 30. */
|
|
32
|
+
timeout?: number;
|
|
33
|
+
}
|
|
34
|
+
/** A single column as described by the Sybase system catalogs. */
|
|
35
|
+
export interface ColumnMeta {
|
|
36
|
+
name: string;
|
|
37
|
+
colid: number;
|
|
38
|
+
/** Resolved base system type name, lower-cased (UDTs already resolved). */
|
|
39
|
+
typeName: string;
|
|
40
|
+
length: number;
|
|
41
|
+
precision: number | null;
|
|
42
|
+
scale: number | null;
|
|
43
|
+
isNullable: boolean;
|
|
44
|
+
isIdentity: boolean;
|
|
45
|
+
defaultValue: string | null;
|
|
46
|
+
}
|
|
47
|
+
/** A single index as described by `sysindexes`. */
|
|
48
|
+
export interface IndexMeta {
|
|
49
|
+
indexName: string;
|
|
50
|
+
isPrimary: boolean;
|
|
51
|
+
isUnique: boolean;
|
|
52
|
+
/** Key column names, in key order. */
|
|
53
|
+
columns: string[];
|
|
54
|
+
}
|
|
55
|
+
/** A user table together with its columns and indexes. */
|
|
56
|
+
export interface TableMeta {
|
|
57
|
+
name: string;
|
|
58
|
+
owner: string;
|
|
59
|
+
columns: ColumnMeta[];
|
|
60
|
+
indexes: IndexMeta[];
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/introspect/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpE,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC7C;AAED,kDAAkD;AAClD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,8FAA8F;IAC9F,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,kEAAkE;AAClE,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,mDAAmD;AACnD,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,sCAAsC;IACtC,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,0DAA0D;AAC1D,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,OAAO,EAAE,SAAS,EAAE,CAAC;CACtB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Sybase ASE schema introspection.
|
|
3
|
+
*
|
|
4
|
+
* These describe the metadata extracted from the system catalogs
|
|
5
|
+
* (sysobjects / syscolumns / systypes / sysindexes) and the configuration
|
|
6
|
+
* accepted by {@link introspectSybase}.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/introspect/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-sybase",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Drizzle ORM driver for Sybase ASE with built-in FreeTDS native bindings",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ase",
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
"type": "git",
|
|
23
23
|
"url": "git+https://github.com/cjnoname/drizzle-sybase.git"
|
|
24
24
|
},
|
|
25
|
+
"bin": {
|
|
26
|
+
"drizzle-sybase-introspect": "./dist/introspect/cli.js"
|
|
27
|
+
},
|
|
25
28
|
"files": [
|
|
26
29
|
"dist",
|
|
27
30
|
"src/native/binding.c",
|
|
@@ -35,21 +38,25 @@
|
|
|
35
38
|
".": {
|
|
36
39
|
"types": "./dist/index.d.ts",
|
|
37
40
|
"import": "./dist/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./introspect": {
|
|
43
|
+
"types": "./dist/introspect/index.d.ts",
|
|
44
|
+
"import": "./dist/introspect/index.js"
|
|
38
45
|
}
|
|
39
46
|
},
|
|
40
47
|
"devDependencies": {
|
|
41
|
-
"@types/node": "^25.
|
|
42
|
-
"concurrently": "^
|
|
48
|
+
"@types/node": "^25.9.2",
|
|
49
|
+
"concurrently": "^10.0.3",
|
|
43
50
|
"husky": "^9.1.7",
|
|
44
|
-
"node-gyp": "^12.
|
|
45
|
-
"oxfmt": "^0.
|
|
46
|
-
"oxlint": "^1.
|
|
51
|
+
"node-gyp": "^12.4.0",
|
|
52
|
+
"oxfmt": "^0.54.0",
|
|
53
|
+
"oxlint": "^1.69.0",
|
|
47
54
|
"oxlint-tsgolint": "latest",
|
|
48
55
|
"typescript": "^6.0.3",
|
|
49
|
-
"vitest": "^4.1.
|
|
56
|
+
"vitest": "^4.1.8"
|
|
50
57
|
},
|
|
51
58
|
"peerDependencies": {
|
|
52
|
-
"drizzle-orm": "^1.0.0-rc.
|
|
59
|
+
"drizzle-orm": "^1.0.0-rc.3"
|
|
53
60
|
},
|
|
54
61
|
"engines": {
|
|
55
62
|
"node": ">=24"
|
package/scripts/build-win.ps1
CHANGED
|
@@ -88,7 +88,11 @@ if (Test-Path $ImportLib) {
|
|
|
88
88
|
|
|
89
89
|
Write-Host "==> Building native addon..."
|
|
90
90
|
Set-Location $RootDir
|
|
91
|
-
|
|
91
|
+
# Some Node 26 Windows builds enable thin-LTO, so node-gyp inherits Clang LTO
|
|
92
|
+
# flags (-flto=thin and /opt:lldltojobs=N) that MSVC's link.exe rejects
|
|
93
|
+
# (LNK1117). binding.gyp strips those flags on Windows; the -D flags are a
|
|
94
|
+
# secondary lever for config.gypi files that use the %-default form.
|
|
95
|
+
npx node-gyp rebuild -Denable_lto=false -Denable_thin_lto=false
|
|
92
96
|
if ($LASTEXITCODE -ne 0) { throw "node-gyp rebuild failed" }
|
|
93
97
|
|
|
94
98
|
# ---------------------------------------------------------------------------
|