drizzle-sybase 2.0.1 → 3.0.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 +72 -6
- package/dist/columns/index.d.ts +186 -36
- package/dist/columns/index.d.ts.map +1 -1
- package/dist/columns/index.js +113 -23
- package/dist/columns/index.js.map +1 -1
- package/dist/connection.d.ts +77 -157
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +244 -506
- package/dist/connection.js.map +1 -1
- package/dist/datetime.d.ts +15 -0
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.js +25 -0
- package/dist/datetime.js.map +1 -1
- package/dist/db.d.ts +36 -10
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +15 -25
- package/dist/db.js.map +1 -1
- package/dist/dialect.d.ts +24 -0
- package/dist/dialect.d.ts.map +1 -1
- package/dist/dialect.js +63 -9
- package/dist/dialect.js.map +1 -1
- package/dist/index.d.ts +11 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/introspect/codegen.d.ts +8 -1
- package/dist/introspect/codegen.d.ts.map +1 -1
- package/dist/introspect/codegen.js +117 -29
- package/dist/introspect/codegen.js.map +1 -1
- package/dist/introspect/fetch.d.ts +9 -2
- package/dist/introspect/fetch.d.ts.map +1 -1
- package/dist/introspect/fetch.js +37 -8
- package/dist/introspect/fetch.js.map +1 -1
- package/dist/introspect/index.d.ts +1 -0
- package/dist/introspect/index.d.ts.map +1 -1
- package/dist/introspect/index.js +8 -5
- package/dist/introspect/index.js.map +1 -1
- package/dist/introspect/type-map.d.ts +17 -8
- package/dist/introspect/type-map.d.ts.map +1 -1
- package/dist/introspect/type-map.js +28 -9
- package/dist/introspect/type-map.js.map +1 -1
- package/dist/native/index.d.ts +4 -1
- package/dist/native/index.d.ts.map +1 -1
- package/dist/native/index.js.map +1 -1
- 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.linux-arm64.node +0 -0
- package/dist/native/sybase_native.linux-x64.node +0 -0
- package/dist/native/sybase_native.win32-x64.node +0 -0
- package/dist/pool.d.ts +197 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/pool.js +638 -0
- package/dist/pool.js.map +1 -0
- package/dist/query-builders/delete.d.ts +6 -4
- package/dist/query-builders/delete.d.ts.map +1 -1
- package/dist/query-builders/delete.js +4 -4
- package/dist/query-builders/delete.js.map +1 -1
- package/dist/query-builders/index.d.ts +1 -1
- package/dist/query-builders/index.d.ts.map +1 -1
- package/dist/query-builders/index.js.map +1 -1
- package/dist/query-builders/insert.d.ts +28 -4
- package/dist/query-builders/insert.d.ts.map +1 -1
- package/dist/query-builders/insert.js +8 -5
- package/dist/query-builders/insert.js.map +1 -1
- package/dist/query-builders/select-types.d.ts +132 -0
- package/dist/query-builders/select-types.d.ts.map +1 -0
- package/dist/query-builders/select-types.js +2 -0
- package/dist/query-builders/select-types.js.map +1 -0
- package/dist/query-builders/select.d.ts +54 -34
- package/dist/query-builders/select.d.ts.map +1 -1
- package/dist/query-builders/select.js +99 -92
- package/dist/query-builders/select.js.map +1 -1
- package/dist/query-builders/update.d.ts +7 -5
- package/dist/query-builders/update.d.ts.map +1 -1
- package/dist/query-builders/update.js +4 -4
- package/dist/query-builders/update.js.map +1 -1
- package/dist/session.d.ts +141 -14
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +456 -40
- package/dist/session.js.map +1 -1
- package/dist/sql-classify.d.ts +70 -0
- package/dist/sql-classify.d.ts.map +1 -0
- package/dist/sql-classify.js +189 -0
- package/dist/sql-classify.js.map +1 -0
- package/dist/table.d.ts +85 -3
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +8 -2
- package/dist/table.js.map +1 -1
- package/package.json +9 -8
- package/scripts/clean.ts +4 -3
- package/src/native/binding.c +463 -62
|
@@ -1,48 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { escapeName, escapeTableName } from "../dialect.js";
|
|
2
|
+
const ColumnsSymbol = Symbol.for("drizzle:Columns");
|
|
3
3
|
// ---------------------------------------------------------------------------
|
|
4
4
|
// Builder
|
|
5
5
|
// ---------------------------------------------------------------------------
|
|
6
|
+
/** Largest value `TOP` takes (a 32-bit int). */
|
|
7
|
+
const MAX_ROWCOUNT = 2147483647;
|
|
8
|
+
/**
|
|
9
|
+
* Validate a limit/offset. They are inlined into `TOP`, so anything
|
|
10
|
+
* that is not a plain integer would be a syntax error at best and injected SQL
|
|
11
|
+
* at worst (for callers outside TypeScript).
|
|
12
|
+
*/
|
|
13
|
+
const assertRowCount = (name, count) => {
|
|
14
|
+
if (!Number.isInteger(count) || count < 0 || count > MAX_ROWCOUNT) {
|
|
15
|
+
throw new RangeError(`${name}() expects an integer between 0 and ${MAX_ROWCOUNT}, got ${String(count)}`);
|
|
16
|
+
}
|
|
17
|
+
return count;
|
|
18
|
+
};
|
|
6
19
|
export class SybaseSelectBuilder {
|
|
7
20
|
dialect;
|
|
8
21
|
session;
|
|
9
22
|
config;
|
|
23
|
+
/** No fields were given: select every column of the source tables. */
|
|
24
|
+
implicitFields;
|
|
25
|
+
/** Table objects in FROM / JOIN order, used to expand implicit fields. */
|
|
26
|
+
sources = [];
|
|
27
|
+
/** A source was given by name, so its columns are unknown. */
|
|
28
|
+
hasNamedSource = false;
|
|
10
29
|
constructor(dialect, session, fields) {
|
|
11
30
|
this.dialect = dialect;
|
|
12
31
|
this.session = session;
|
|
32
|
+
this.implicitFields = fields === undefined;
|
|
13
33
|
this.config = {
|
|
14
34
|
fields: fields ?? [{ expression: "*" }]
|
|
15
35
|
};
|
|
16
36
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Add a Common Table Expression (CTE) to the query.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* const result = await db.select()
|
|
23
|
-
* .with("active_users", sql`select * from [users] where active = 1`)
|
|
24
|
-
* .from("active_users");
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
with(alias, query) {
|
|
28
|
-
if (!this.config.withList) {
|
|
29
|
-
this.config.withList = [];
|
|
30
|
-
}
|
|
31
|
-
const sqlStr = typeof query === "string" ? query : this.dialect.sqlToQuery(query);
|
|
32
|
-
this.config.withList.push({ alias, sql: sqlStr });
|
|
33
|
-
return this;
|
|
34
|
-
}
|
|
35
37
|
from(table) {
|
|
36
|
-
|
|
37
|
-
this.config.table = escapeName(table);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
this.config.table = escapeName(getTableName(table));
|
|
41
|
-
}
|
|
38
|
+
this.config.table = this.addSource(table);
|
|
42
39
|
return this;
|
|
43
40
|
}
|
|
41
|
+
/** `undefined` (as `and()` of no conditions returns) means no condition, as in drizzle. */
|
|
44
42
|
where(condition) {
|
|
45
|
-
this.config.where = this.dialect.sqlToQuery(condition);
|
|
43
|
+
this.config.where = condition ? this.dialect.sqlToQuery(condition) : undefined;
|
|
46
44
|
return this;
|
|
47
45
|
}
|
|
48
46
|
orderBy(...columns) {
|
|
@@ -54,7 +52,7 @@ export class SybaseSelectBuilder {
|
|
|
54
52
|
return this;
|
|
55
53
|
}
|
|
56
54
|
having(condition) {
|
|
57
|
-
this.config.having = this.dialect.sqlToQuery(condition);
|
|
55
|
+
this.config.having = condition ? this.dialect.sqlToQuery(condition) : undefined;
|
|
58
56
|
return this;
|
|
59
57
|
}
|
|
60
58
|
innerJoin(table, on) {
|
|
@@ -66,31 +64,26 @@ export class SybaseSelectBuilder {
|
|
|
66
64
|
rightJoin(table, on) {
|
|
67
65
|
return this.addJoin("right", table, on);
|
|
68
66
|
}
|
|
69
|
-
fullJoin(table, on) {
|
|
70
|
-
return this.addJoin("full", table, on);
|
|
71
|
-
}
|
|
72
67
|
distinct() {
|
|
73
68
|
this.config.distinct = true;
|
|
74
69
|
return this;
|
|
75
70
|
}
|
|
76
71
|
/**
|
|
77
|
-
* Set max rows to return
|
|
72
|
+
* Set max rows to return, as `SELECT TOP n` (ASE has no LIMIT).
|
|
78
73
|
*
|
|
79
|
-
* - `limit(0)` returns zero rows
|
|
80
|
-
* -
|
|
74
|
+
* - `limit(0)` returns zero rows
|
|
75
|
+
* - Anything but a non-negative integer throws: the value is inlined into
|
|
76
|
+
* the batch
|
|
81
77
|
*/
|
|
82
78
|
limit(count) {
|
|
83
|
-
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
|
-
this.config.limit = count;
|
|
79
|
+
this.config.limit = assertRowCount("limit", count);
|
|
87
80
|
return this;
|
|
88
81
|
}
|
|
89
82
|
/**
|
|
90
83
|
* Set offset for pagination.
|
|
91
84
|
*
|
|
92
85
|
* **Implementation:** Sybase ASE does not support OFFSET natively.
|
|
93
|
-
* This is implemented by fetching `offset + limit` rows
|
|
86
|
+
* This is implemented by fetching `offset + limit` rows with `TOP`,
|
|
94
87
|
* then slicing off the first `offset` rows in application code.
|
|
95
88
|
*
|
|
96
89
|
* For best performance with large offsets, consider cursor-based pagination
|
|
@@ -99,10 +92,7 @@ export class SybaseSelectBuilder {
|
|
|
99
92
|
* ORDER BY is required for deterministic results with offset.
|
|
100
93
|
*/
|
|
101
94
|
offset(count) {
|
|
102
|
-
|
|
103
|
-
return this;
|
|
104
|
-
}
|
|
105
|
-
this.config.offset = count;
|
|
95
|
+
this.config.offset = assertRowCount("offset", count);
|
|
106
96
|
return this;
|
|
107
97
|
}
|
|
108
98
|
/**
|
|
@@ -123,15 +113,24 @@ export class SybaseSelectBuilder {
|
|
|
123
113
|
"Without a limit, the entire table would be fetched into memory before slicing. " +
|
|
124
114
|
"Use cursor-based pagination (WHERE id > ?) for large offsets.");
|
|
125
115
|
}
|
|
116
|
+
// limit(0) means no rows. Not left to the generated `where 1=0`: an
|
|
117
|
+
// aggregate without GROUP BY still returns one row over an empty input
|
|
118
|
+
// (`count(*)` gives `[{ n: 0 }]`).
|
|
119
|
+
if (this.config.limit === 0) {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
126
122
|
const rawSql = this.buildSql();
|
|
127
123
|
const maxRows = this.getMaxRowsHint();
|
|
128
124
|
const result = await this.session.execute(rawSql, maxRows ? { maxRows } : undefined);
|
|
125
|
+
// The rows are shaped by the field list this builder generated, which is
|
|
126
|
+
// what the result type describes.
|
|
127
|
+
const rows = result.rows;
|
|
129
128
|
// If offset is set, skip the first N rows in application code
|
|
130
129
|
// (Sybase ASE has no native OFFSET support)
|
|
131
130
|
if (this.config.offset !== undefined && this.config.offset > 0) {
|
|
132
|
-
return
|
|
131
|
+
return rows.slice(this.config.offset);
|
|
133
132
|
}
|
|
134
|
-
return
|
|
133
|
+
return rows;
|
|
135
134
|
}
|
|
136
135
|
/**
|
|
137
136
|
* Alias for execute() — enables `await db.select()...` pattern.
|
|
@@ -143,64 +142,72 @@ export class SybaseSelectBuilder {
|
|
|
143
142
|
// Private
|
|
144
143
|
// ---------------------------------------------------------------------------
|
|
145
144
|
resolveColumns(columns) {
|
|
146
|
-
return columns.map(col =>
|
|
147
|
-
if (typeof col === "string") {
|
|
148
|
-
return col;
|
|
149
|
-
}
|
|
150
|
-
// Check for SybaseColumn (has name + table) before getSQL to avoid
|
|
151
|
-
// calling getSQL() on column objects that don't return a proper SQL instance
|
|
152
|
-
if (col && col.name && col.table) {
|
|
153
|
-
return `${escapeName(getTableName(col.table))}.${escapeName(col.name)}`;
|
|
154
|
-
}
|
|
155
|
-
if (col && typeof col.getSQL === "function") {
|
|
156
|
-
return this.dialect.sqlToQuery(col.getSQL());
|
|
157
|
-
}
|
|
158
|
-
if (col && typeof col.toQuery === "function") {
|
|
159
|
-
return this.dialect.sqlToQuery(col);
|
|
160
|
-
}
|
|
161
|
-
if (col && col.name) {
|
|
162
|
-
return escapeName(col.name);
|
|
163
|
-
}
|
|
164
|
-
return String(col);
|
|
165
|
-
});
|
|
145
|
+
return columns.map(col => this.dialect.renderExpression(col, "reference"));
|
|
166
146
|
}
|
|
167
147
|
addJoin(type, table, on) {
|
|
168
148
|
if (!this.config.joins) {
|
|
169
149
|
this.config.joins = [];
|
|
170
150
|
}
|
|
171
|
-
|
|
172
|
-
if (typeof table === "string") {
|
|
173
|
-
tableName = escapeName(table);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
tableName = escapeName(getTableName(table));
|
|
177
|
-
}
|
|
151
|
+
const tableName = this.addSource(table);
|
|
178
152
|
const onStr = this.dialect.sqlToQuery(on);
|
|
179
153
|
this.config.joins.push({ type, table: tableName, on: onStr });
|
|
180
154
|
return this;
|
|
181
155
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
...this.config,
|
|
188
|
-
where: this.config.where ? `1=0 and (${this.config.where})` : "1=0"
|
|
189
|
-
};
|
|
190
|
-
return this.dialect.buildSelectQuery(configWithFalseWhere);
|
|
191
|
-
}
|
|
192
|
-
const paginationParts = [];
|
|
193
|
-
if (this.config.limit !== undefined && this.config.offset !== undefined) {
|
|
194
|
-
paginationParts.push(`SET ROWCOUNT ${this.config.offset + this.config.limit}`);
|
|
195
|
-
}
|
|
196
|
-
else if (this.config.limit !== undefined) {
|
|
197
|
-
paginationParts.push(`SET ROWCOUNT ${this.config.limit}`);
|
|
156
|
+
/** Record a FROM / JOIN source and return its escaped reference. */
|
|
157
|
+
addSource(table) {
|
|
158
|
+
if (typeof table === "string") {
|
|
159
|
+
this.hasNamedSource = true;
|
|
160
|
+
return escapeName(table);
|
|
198
161
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
162
|
+
this.sources.push(table);
|
|
163
|
+
return escapeTableName(table);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Fields for a select with none given: every column of every source table,
|
|
167
|
+
* aliased to its property name — the keys the table definition and the
|
|
168
|
+
* generated schemas use, rather than the database column names `select *`
|
|
169
|
+
* would return.
|
|
170
|
+
*
|
|
171
|
+
* Falls back to `*` when a source was given by name, since its columns are
|
|
172
|
+
* unknown. Throws when two sources share a property name: a flat row cannot
|
|
173
|
+
* hold both, and keeping one silently would lose data.
|
|
174
|
+
*/
|
|
175
|
+
implicitFieldList() {
|
|
176
|
+
if (this.hasNamedSource || this.sources.length === 0) {
|
|
177
|
+
return [{ expression: "*" }];
|
|
178
|
+
}
|
|
179
|
+
const fields = [];
|
|
180
|
+
const owners = new Map();
|
|
181
|
+
for (const table of this.sources) {
|
|
182
|
+
const tableRef = escapeTableName(table);
|
|
183
|
+
for (const [property, col] of Object.entries(table[ColumnsSymbol] ?? {})) {
|
|
184
|
+
const previous = owners.get(property);
|
|
185
|
+
if (previous !== undefined) {
|
|
186
|
+
throw new Error(`Cannot select every column: property "${property}" exists in both ${previous} and ` +
|
|
187
|
+
`${tableRef}. Pass the fields explicitly, e.g. db.select({ ... }).`);
|
|
188
|
+
}
|
|
189
|
+
owners.set(property, tableRef);
|
|
190
|
+
fields.push({ expression: `${tableRef}.${escapeName(col.name)}`, alias: property });
|
|
191
|
+
}
|
|
202
192
|
}
|
|
203
|
-
return
|
|
193
|
+
return fields;
|
|
194
|
+
}
|
|
195
|
+
buildSql() {
|
|
196
|
+
const config = this.implicitFields
|
|
197
|
+
? { ...this.config, fields: this.implicitFieldList() }
|
|
198
|
+
: this.config;
|
|
199
|
+
// `SELECT TOP n` rather than `SET ROWCOUNT n`: TOP is part of the
|
|
200
|
+
// statement, so it changes no session state that could outlive it (a
|
|
201
|
+
// ROWCOUNT left set by a batch that stopped early would truncate the next
|
|
202
|
+
// pool user's queries). `TOP 0` returns no rows, as limit(0) means.
|
|
203
|
+
if (config.limit === undefined) {
|
|
204
|
+
return this.dialect.buildSelectQuery(config);
|
|
205
|
+
}
|
|
206
|
+
const top = (config.offset ?? 0) + config.limit;
|
|
207
|
+
if (top > MAX_ROWCOUNT) {
|
|
208
|
+
throw new RangeError(`offset() + limit() must not exceed ${MAX_ROWCOUNT}, got ${top}`);
|
|
209
|
+
}
|
|
210
|
+
return this.dialect.buildSelectQuery({ ...config, top });
|
|
204
211
|
}
|
|
205
212
|
/**
|
|
206
213
|
* Get a hint for the native maxRows parameter to limit memory usage.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/query-builders/select.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/query-builders/select.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAsB,MAAM,eAAe,CAAC;AAkBhF,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAiCpD,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,gDAAgD;AAChD,MAAM,YAAY,GAAG,UAAa,CAAC;AAEnC;;;;GAIG;AACH,MAAM,cAAc,GAAG,CAAC,IAAwB,EAAE,KAAa,EAAU,EAAE;IACzE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,YAAY,EAAE,CAAC;QAClE,MAAM,IAAI,UAAU,CAClB,GAAG,IAAI,uCAAuC,YAAY,SAAS,MAAM,CAAC,KAAK,CAAC,EAAE,CACnF,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,OAAO,mBAAmB;IAYX,OAAO;IACP,OAAO;IAVlB,MAAM,CAAqB;IACnC,sEAAsE;IACrD,cAAc,CAAU;IACzC,0EAA0E;IACzD,OAAO,GAAU,EAAE,CAAC;IACrC,8DAA8D;IACtD,cAAc,GAAG,KAAK,CAAC;IAE/B,YACmB,OAAsB,EACtB,OAA2E,EAC5F,MAA4B;uBAFX,OAAO;uBACP,OAAO;QAGxB,IAAI,CAAC,cAAc,GAAG,MAAM,KAAK,SAAS,CAAC;QAC3C,IAAI,CAAC,MAAM,GAAG;YACZ,MAAM,EAAE,MAAM,IAAI,CAAC,EAAE,UAAU,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AAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -13,20 +13,22 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { SQL } from "drizzle-orm";
|
|
15
15
|
import { type SybaseDialect } from "../dialect.js";
|
|
16
|
-
import type { SybaseSession, SybaseTransactionSession } from "../session.js";
|
|
16
|
+
import type { SybaseConnectionSession, SybaseSession, SybaseTransactionSession } from "../session.js";
|
|
17
|
+
import type { AnySybaseTable, SybaseUpdateValues } from "../table.js";
|
|
17
18
|
export interface SybaseUpdateResult {
|
|
18
19
|
rowCount: number;
|
|
19
20
|
affectedRows: number;
|
|
20
21
|
}
|
|
21
|
-
export declare class SybaseUpdateBuilder {
|
|
22
|
+
export declare class SybaseUpdateBuilder<TTable extends AnySybaseTable = AnySybaseTable> {
|
|
22
23
|
private readonly table;
|
|
23
24
|
private readonly dialect;
|
|
24
25
|
private readonly session;
|
|
25
26
|
private setValues;
|
|
26
27
|
private whereCondition?;
|
|
27
|
-
constructor(table:
|
|
28
|
-
set(values:
|
|
29
|
-
|
|
28
|
+
constructor(table: TTable, dialect: SybaseDialect, session: SybaseSession | SybaseTransactionSession | SybaseConnectionSession);
|
|
29
|
+
set(values: SybaseUpdateValues<TTable>): this;
|
|
30
|
+
/** `undefined` (as `and()` of no conditions returns) means no condition, as in drizzle. */
|
|
31
|
+
where(condition: SQL | undefined): this;
|
|
30
32
|
toSQL(): string;
|
|
31
33
|
execute(): Promise<SybaseUpdateResult>;
|
|
32
34
|
then<TResult1 = SybaseUpdateResult, TResult2 = never>(onfulfilled?: ((value: SybaseUpdateResult) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../src/query-builders/update.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,GAAG,EA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CAAC,CAAC,GAAG,IAAI,EACtF,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,GACtE,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAE9B;IAMD,OAAO,CAAC,QAAQ;CAqCjB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { escapeName } from "../dialect.js";
|
|
1
|
+
import { escapeName, escapeTableName } from "../dialect.js";
|
|
3
2
|
/** @internal */
|
|
4
3
|
const ColumnsSymbol = Symbol.for("drizzle:Columns");
|
|
5
4
|
// ---------------------------------------------------------------------------
|
|
@@ -20,8 +19,9 @@ export class SybaseUpdateBuilder {
|
|
|
20
19
|
this.setValues = values;
|
|
21
20
|
return this;
|
|
22
21
|
}
|
|
22
|
+
/** `undefined` (as `and()` of no conditions returns) means no condition, as in drizzle. */
|
|
23
23
|
where(condition) {
|
|
24
|
-
this.whereCondition = this.dialect.sqlToQuery(condition);
|
|
24
|
+
this.whereCondition = condition ? this.dialect.sqlToQuery(condition) : undefined;
|
|
25
25
|
return this;
|
|
26
26
|
}
|
|
27
27
|
toSQL() {
|
|
@@ -40,7 +40,7 @@ export class SybaseUpdateBuilder {
|
|
|
40
40
|
// ---------------------------------------------------------------------------
|
|
41
41
|
buildSql() {
|
|
42
42
|
const columns = this.table[ColumnsSymbol];
|
|
43
|
-
const tableName =
|
|
43
|
+
const tableName = escapeTableName(this.table);
|
|
44
44
|
const setClauses = [];
|
|
45
45
|
for (const [fieldName, value] of Object.entries(this.setValues)) {
|
|
46
46
|
if (value === undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/query-builders/update.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/query-builders/update.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE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AAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/D,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,KAAK,IAAI,UAAU,IAAI,CAAC,cAAc,EAAE,CAAC;QAC3C,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
package/dist/session.d.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* with proper BEGIN/COMMIT/ROLLBACK semantics.
|
|
6
6
|
* Supports transaction isolation levels.
|
|
7
7
|
*/
|
|
8
|
-
import type { SybaseConnection,
|
|
8
|
+
import type { SybaseConnection, QueryResult, SybaseLogger, SybaseQueryOptions } from "./connection.js";
|
|
9
|
+
import type { SybasePool } from "./pool.js";
|
|
9
10
|
/**
|
|
10
11
|
* Sybase ASE transaction isolation levels.
|
|
11
12
|
*
|
|
@@ -34,15 +35,20 @@ export declare class SybaseSession {
|
|
|
34
35
|
/**
|
|
35
36
|
* Execute raw SQL and return results.
|
|
36
37
|
*/
|
|
37
|
-
execute<T extends Record<string, unknown> = Record<string, unknown>>(rawSql: string, options?:
|
|
38
|
-
maxRows?: number;
|
|
39
|
-
}): Promise<SybaseSessionQueryResult<T>>;
|
|
38
|
+
execute<T extends Record<string, unknown> = Record<string, unknown>>(rawSql: string, options?: SybaseQueryOptions): Promise<SybaseSessionQueryResult<T>>;
|
|
40
39
|
/**
|
|
41
40
|
* Execute raw SQL and return the full result (including columns).
|
|
42
41
|
*/
|
|
43
|
-
executeRaw(rawSql: string, options?:
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
executeRaw(rawSql: string, options?: SybaseQueryOptions): Promise<QueryResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Execute a multi-statement batch all-or-nothing.
|
|
45
|
+
*
|
|
46
|
+
* ASE commits each statement of a batch as it runs and carries on past
|
|
47
|
+
* statement-level errors, so a batch that fails partway would leave the
|
|
48
|
+
* statements before (and possibly after) the failure applied. Running it in
|
|
49
|
+
* a transaction makes it atomic.
|
|
50
|
+
*/
|
|
51
|
+
executeAtomic<T extends Record<string, unknown> = Record<string, unknown>>(rawSql: string): Promise<SybaseSessionQueryResult<T>>;
|
|
46
52
|
/**
|
|
47
53
|
* Run a transaction on a single connection.
|
|
48
54
|
*
|
|
@@ -57,21 +63,142 @@ export declare class SybaseSession {
|
|
|
57
63
|
* ```
|
|
58
64
|
*/
|
|
59
65
|
transaction<T>(fn: (tx: SybaseTransactionSession) => Promise<T>, options?: SybaseTransactionOptions): Promise<T>;
|
|
66
|
+
/**
|
|
67
|
+
* Run `fn` with one connection to itself, outside any transaction.
|
|
68
|
+
*
|
|
69
|
+
* For work that spans several statements on the same session without being
|
|
70
|
+
* one transaction — typically `#temp` tables, which ASE only lets a
|
|
71
|
+
* transaction create when `ddl in tran` is enabled, and which a pool query
|
|
72
|
+
* drops when it finishes. Each statement autocommits as usual.
|
|
73
|
+
*
|
|
74
|
+
* When `fn` settles the connection goes back to the pool in its baseline
|
|
75
|
+
* state: `#temp` tables are dropped, session options reset, and a
|
|
76
|
+
* transaction left open is rolled back and reported as an error.
|
|
77
|
+
*/
|
|
78
|
+
withConnection<T>(fn: (session: SybaseConnectionSession) => Promise<T>): Promise<T>;
|
|
79
|
+
/**
|
|
80
|
+
* Return a {@link withConnection} connection to the pool in its baseline
|
|
81
|
+
* state. Resolves to whether a transaction was left open; a connection whose
|
|
82
|
+
* state cannot be established is discarded.
|
|
83
|
+
*/
|
|
84
|
+
private releasePinned;
|
|
85
|
+
}
|
|
86
|
+
/** The session {@link SybaseSession.withConnection} hands its callback. */
|
|
87
|
+
export declare class SybaseConnectionSession {
|
|
88
|
+
private readonly conn;
|
|
89
|
+
private readonly logger;
|
|
90
|
+
private readonly timeZone;
|
|
91
|
+
private ended;
|
|
92
|
+
/** Operations run one at a time, as in {@link SybaseTransactionSession}. */
|
|
93
|
+
private queue;
|
|
94
|
+
private _discardConnection;
|
|
95
|
+
private _mayHaveCreatedTempTables;
|
|
96
|
+
constructor(conn: SybaseConnection, logger: SybaseLogger | undefined, timeZone: string);
|
|
97
|
+
/** @internal Refuse further statements; settles once the current one has finished. */
|
|
98
|
+
end(): Promise<void>;
|
|
99
|
+
/** @internal See {@link SybaseTransactionSession.discardConnection}. */
|
|
100
|
+
get discardConnection(): boolean;
|
|
101
|
+
/** @internal See {@link SybaseTransactionSession.mayHaveCreatedTempTables}. */
|
|
102
|
+
get mayHaveCreatedTempTables(): boolean;
|
|
103
|
+
execute<T extends Record<string, unknown> = Record<string, unknown>>(rawSql: string, options?: SybaseQueryOptions): Promise<SybaseSessionQueryResult<T>>;
|
|
104
|
+
executeRaw(rawSql: string, options?: SybaseQueryOptions): Promise<QueryResult>;
|
|
105
|
+
/**
|
|
106
|
+
* Execute a multi-statement batch all-or-nothing: in a transaction of its
|
|
107
|
+
* own, or under a savepoint if the caller has opened one with raw SQL.
|
|
108
|
+
*/
|
|
109
|
+
executeAtomic<T extends Record<string, unknown> = Record<string, unknown>>(rawSql: string): Promise<SybaseSessionQueryResult<T>>;
|
|
110
|
+
/** Run `op` after every operation queued before it has settled. */
|
|
111
|
+
private serialize;
|
|
112
|
+
/** One statement, with logging. Callers must hold the queue. */
|
|
113
|
+
private run;
|
|
60
114
|
}
|
|
61
115
|
export declare class SybaseTransactionSession {
|
|
62
116
|
private readonly conn;
|
|
63
117
|
private readonly logger?;
|
|
64
118
|
private readonly timeZone;
|
|
119
|
+
private ended;
|
|
120
|
+
/** Why the transaction can no longer be used, once it cannot. */
|
|
121
|
+
private _abortReason;
|
|
122
|
+
/**
|
|
123
|
+
* Tail of the operations run on this transaction, one at a time.
|
|
124
|
+
*
|
|
125
|
+
* The connection already serializes single queries, but an operation here is
|
|
126
|
+
* several: the statement, then the reset that finds out whether the server
|
|
127
|
+
* rolled the transaction back (and, for {@link executeAtomic}, a savepoint
|
|
128
|
+
* around both). Interleaved with another operation's queries, a statement
|
|
129
|
+
* queued behind a failure would run after the rollback — in autocommit — and
|
|
130
|
+
* a savepoint rollback could undo another caller's work.
|
|
131
|
+
*/
|
|
132
|
+
private queue;
|
|
133
|
+
private savepoints;
|
|
134
|
+
private _touchedSessionState;
|
|
135
|
+
private _discardConnection;
|
|
136
|
+
private _mayHaveCreatedTempTables;
|
|
65
137
|
constructor(conn: SybaseConnection, logger?: SybaseLogger | undefined, timeZone?: string);
|
|
138
|
+
/**
|
|
139
|
+
* @internal Called by {@link SybaseSession.transaction} when the callback
|
|
140
|
+
* settles. Operations already queued are refused; the returned promise
|
|
141
|
+
* settles once the one in progress (if any) has finished, so nothing runs on
|
|
142
|
+
* the connection after COMMIT/ROLLBACK.
|
|
143
|
+
*/
|
|
144
|
+
end(): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Whether the transaction has ended underneath the callback — rolled back by
|
|
147
|
+
* the server after a failed statement, or ended by a statement in it.
|
|
148
|
+
* Further statements are refused: they would run in autocommit mode.
|
|
149
|
+
*/
|
|
150
|
+
get aborted(): boolean;
|
|
151
|
+
/** @internal Why {@link aborted} is set. */
|
|
152
|
+
get abortReason(): string | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* @internal Whether a statement may have changed session state that outlives
|
|
155
|
+
* the transaction (see `mayLeaveSessionState`), so the connection needs a
|
|
156
|
+
* reset before it goes back to the pool.
|
|
157
|
+
*/
|
|
158
|
+
get touchedSessionState(): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* @internal A statement may have switched the session's identity
|
|
161
|
+
* (`setuser`), which cannot be restored, so the connection must be discarded
|
|
162
|
+
* when the transaction ends.
|
|
163
|
+
*/
|
|
164
|
+
get discardConnection(): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* @internal A statement may have created a `#temp` table, which must not
|
|
167
|
+
* outlive the transaction on a pooled connection.
|
|
168
|
+
*/
|
|
169
|
+
get mayHaveCreatedTempTables(): boolean;
|
|
66
170
|
/**
|
|
67
171
|
* Execute raw SQL within the transaction.
|
|
68
172
|
*/
|
|
69
|
-
execute<T extends Record<string, unknown> = Record<string, unknown>>(rawSql: string, options?:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
173
|
+
execute<T extends Record<string, unknown> = Record<string, unknown>>(rawSql: string, options?: SybaseQueryOptions): Promise<SybaseSessionQueryResult<T>>;
|
|
174
|
+
executeRaw(rawSql: string, options?: SybaseQueryOptions): Promise<QueryResult>;
|
|
175
|
+
/**
|
|
176
|
+
* Execute a multi-statement batch all-or-nothing, without ending the
|
|
177
|
+
* enclosing transaction.
|
|
178
|
+
*
|
|
179
|
+
* ASE carries on with the rest of a batch after a statement-level error such
|
|
180
|
+
* as a duplicate key, so a caller that catches the error would otherwise
|
|
181
|
+
* commit the statements around the failed one. A savepoint taken first (in
|
|
182
|
+
* its own round-trip: a batch that fails to compile never runs it) lets just
|
|
183
|
+
* this batch be undone. Each call gets its own savepoint name.
|
|
184
|
+
*/
|
|
185
|
+
executeAtomic<T extends Record<string, unknown> = Record<string, unknown>>(rawSql: string): Promise<SybaseSessionQueryResult<T>>;
|
|
186
|
+
/** Run `op` after every operation queued before it has settled. */
|
|
187
|
+
private serialize;
|
|
188
|
+
/** One statement, with logging and failure cleanup. Callers must hold the queue. */
|
|
189
|
+
private run;
|
|
190
|
+
/** See {@link run}: refuse to continue once the transaction has ended. */
|
|
191
|
+
private confirmStillOpen;
|
|
192
|
+
/**
|
|
193
|
+
* Restore a usable, known session state after a failed statement.
|
|
194
|
+
*
|
|
195
|
+
* A failed raw batch can skip its trailing `SET ROWCOUNT 0`, and the
|
|
196
|
+
* caller may catch the error and keep using the transaction — every later
|
|
197
|
+
* statement would then be silently truncated. The same round-trip reads
|
|
198
|
+
* `@@trancount` to learn whether the server rolled the transaction back. If
|
|
199
|
+
* either cannot be established the state is unknown, so the connection is
|
|
200
|
+
* closed (aborting the transaction) rather than used further.
|
|
201
|
+
*/
|
|
202
|
+
private afterFailure;
|
|
76
203
|
}
|
|
77
204
|
//# sourceMappingURL=session.d.ts.map
|
package/dist/session.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAY5C;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAC5B,kBAAkB,GAClB,gBAAgB,GAChB,iBAAiB,GACjB,cAAc,CAAC;AAcnB;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,kFAAkF;IAClF,cAAc,CAAC,EAAE,oBAAoB,CAAC;CACvC;AAMD,MAAM,WAAW,wBAAwB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACnE,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AA8DD,qBAAa,aAAa;IAItB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC,YACmB,IAAI,EAAE,UAAU,EACjC,QAAQ,CAAC,EAAE,MAAM,EAGlB;IAED;;OAEG;IACG,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvE,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAEtC;IAED;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAA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