@spinajs/orm-postgres 2.0.528
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 +64 -0
- package/lib/cjs/compilers.d.ts +122 -0
- package/lib/cjs/compilers.d.ts.map +1 -0
- package/lib/cjs/compilers.js +391 -0
- package/lib/cjs/compilers.js.map +1 -0
- package/lib/cjs/index.d.ts +61 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +380 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/statements.d.ts +17 -0
- package/lib/cjs/statements.d.ts.map +1 -0
- package/lib/cjs/statements.js +36 -0
- package/lib/cjs/statements.js.map +1 -0
- package/lib/cjs/types.d.ts +15 -0
- package/lib/cjs/types.d.ts.map +1 -0
- package/lib/cjs/types.js +3 -0
- package/lib/cjs/types.js.map +1 -0
- package/lib/mjs/compilers.d.ts +122 -0
- package/lib/mjs/compilers.d.ts.map +1 -0
- package/lib/mjs/compilers.js +385 -0
- package/lib/mjs/compilers.js.map +1 -0
- package/lib/mjs/index.d.ts +61 -0
- package/lib/mjs/index.d.ts.map +1 -0
- package/lib/mjs/index.js +358 -0
- package/lib/mjs/index.js.map +1 -0
- package/lib/mjs/package.json +1 -0
- package/lib/mjs/statements.d.ts +17 -0
- package/lib/mjs/statements.d.ts.map +1 -0
- package/lib/mjs/statements.js +32 -0
- package/lib/mjs/statements.js.map +1 -0
- package/lib/mjs/types.d.ts +15 -0
- package/lib/mjs/types.d.ts.map +1 -0
- package/lib/mjs/types.js +2 -0
- package/lib/mjs/types.js.map +1 -0
- package/lib/tsconfig.cjs.tsbuildinfo +1 -0
- package/lib/tsconfig.mjs.tsbuildinfo +1 -0
- package/package.json +72 -0
package/lib/mjs/index.js
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
import { Injectable, NewInstance } from '@spinajs/di';
|
|
9
|
+
import { QueryContext, TableExistsCompiler, OrmException, ServerResponseMapper, ConnectionState, IdentifierQuoter, OnDuplicateQueryCompiler, ColumnQueryCompiler, AlterColumnQueryCompiler, AlterTableQueryCompiler, LimitQueryCompiler, TruncateTableQueryCompiler, RecursiveQueryCompiler, DefaultValueBuilder, InsertQueryCompiler, CreateDatabaseCompiler, DropDatabaseCompiler } from '@spinajs/orm';
|
|
10
|
+
import { SqlDriver, SqlTruncateTableQueryCompiler, SqlWithRecursiveCompiler, SqlAlterTableQueryCompiler, SqlDropDatabaseQueryCompiler } from '@spinajs/orm-sql';
|
|
11
|
+
import pg from 'pg';
|
|
12
|
+
import { PostgresTableExistsCompiler, PostgresLimitQueryCompiler, PostgresOnDuplicateQueryCompiler, PostgresInsertQueryCompiler, PostgresColumnQueryCompiler, PostgresAlterColumnQueryCompiler, PostgresCreateDatabaseQueryCompiler, PostgresDefaultValueBuilder } from './compilers.js';
|
|
13
|
+
import { DoubleQuoteIdentifierQuoter, pgEscapeIdentifier } from './statements.js';
|
|
14
|
+
export * from './compilers.js';
|
|
15
|
+
export * from './statements.js';
|
|
16
|
+
/**
|
|
17
|
+
* SQLSTATE classes that mean the transport died rather than the statement being wrong.
|
|
18
|
+
* 08xxx is the connection-exception class; 57P01–57P03 are the server telling us it is
|
|
19
|
+
* going away ( admin shutdown, crash shutdown, cannot connect now ).
|
|
20
|
+
*/
|
|
21
|
+
const PG_RETRYABLE_CODES = new Set(['08000', '08001', '08003', '08004', '08006', '08007', '57P01', '57P02', '57P03']);
|
|
22
|
+
/**
|
|
23
|
+
* Rewrites the `?` placeholders every compiler emits into the `$1..$n` positional
|
|
24
|
+
* parameters the pg protocol requires. Same brute-force walk the MSSQL driver does for
|
|
25
|
+
* its `@p` parameters — the compilers bind every user value, so a literal `?` does not
|
|
26
|
+
* appear in generated SQL outside of a placeholder position.
|
|
27
|
+
*/
|
|
28
|
+
export function toPositionalParameters(stmt) {
|
|
29
|
+
let i = 0;
|
|
30
|
+
return stmt.replace(/\?/g, () => `$${++i}`);
|
|
31
|
+
}
|
|
32
|
+
export class PostgresServerResponseMapper extends ServerResponseMapper {
|
|
33
|
+
read(data, pkNames) {
|
|
34
|
+
// Upserts resolve with their RETURNING rows directly.
|
|
35
|
+
if (Array.isArray(data)) {
|
|
36
|
+
const last = data.length !== 0 ? data[data.length - 1] : undefined;
|
|
37
|
+
const key = pkNames && pkNames.length === 1 && last ? last[pkNames[0]] : 0;
|
|
38
|
+
return {
|
|
39
|
+
RowsAffected: data.length,
|
|
40
|
+
// A uuid / assigned key is not a number and has no identity semantics.
|
|
41
|
+
LastInsertId: typeof key === 'number' ? key : 0,
|
|
42
|
+
Returning: data,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// A RETURNING insert arrives normalized by executeOnDb, carrying its rows; a plain
|
|
46
|
+
// run carries none. Passing the rows through is what lets the caller read generated keys.
|
|
47
|
+
return {
|
|
48
|
+
RowsAffected: data?.RowsAffected ?? 0,
|
|
49
|
+
LastInsertId: data?.LastInsertId ?? 0,
|
|
50
|
+
Returning: Array.isArray(data?.Returning) ? data.Returning : [],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
let PostgresOrmDriver = class PostgresOrmDriver extends SqlDriver {
|
|
55
|
+
constructor() {
|
|
56
|
+
super(...arguments);
|
|
57
|
+
/**
|
|
58
|
+
* Postgres parses all four standard levels; READ UNCOMMITTED is accepted and behaves as
|
|
59
|
+
* READ COMMITTED, which is the standard-permitted upgrade, so it is not refused here.
|
|
60
|
+
*/
|
|
61
|
+
this.SupportedIsolationLevels = ['READ UNCOMMITTED', 'READ COMMITTED', 'REPEATABLE READ', 'SERIALIZABLE'];
|
|
62
|
+
/**
|
|
63
|
+
* pg hands NUMERIC/DECIMAL and BIGINT back as STRINGS: both can exceed 2^53, where a
|
|
64
|
+
* float loses exactly the precision those types exist to keep, so node-postgres refuses
|
|
65
|
+
* to guess. No converter along the way changes that, so the RESPONSE schema has to say
|
|
66
|
+
* the same thing as the runtime. Reads only — on the request side these stay numbers.
|
|
67
|
+
*/
|
|
68
|
+
this.ResponseSchemaTypes = {
|
|
69
|
+
decimal: { type: 'string' },
|
|
70
|
+
numeric: { type: 'string' },
|
|
71
|
+
bigint: { type: 'string' },
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
executeOnDb(stmt, params, context) {
|
|
75
|
+
// Reads and writes are both retried: `withReconnect` only re-runs on transport
|
|
76
|
+
// failures, where the statement provably never reached the server.
|
|
77
|
+
return this.withReconnect(() => this._executeOnDbOnce(stmt, params, context));
|
|
78
|
+
}
|
|
79
|
+
isRetryableError(err) {
|
|
80
|
+
// Inside a transaction the connection carried uncommitted state. Reconnecting and
|
|
81
|
+
// replaying one statement would silently apply it OUTSIDE the transaction.
|
|
82
|
+
if (this.TransactionStorage.getStore()) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
if (super.isRetryableError(err)) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
let current = err;
|
|
89
|
+
let depth = 0;
|
|
90
|
+
while (current && depth < 5) {
|
|
91
|
+
if (typeof current.code === 'string' && PG_RETRYABLE_CODES.has(current.code)) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
current = current.inner ?? current.cause;
|
|
95
|
+
depth++;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
async _executeOnDbOnce(stmt, params, context) {
|
|
100
|
+
const finalQuery = toPositionalParameters(stmt);
|
|
101
|
+
// The context comes from the base driver; only this driver's `_begin` ever populates
|
|
102
|
+
// it, and it always puts a PoolClient in.
|
|
103
|
+
const txContext = this.TransactionStorage.getStore();
|
|
104
|
+
try {
|
|
105
|
+
let result;
|
|
106
|
+
if (txContext?.connection) {
|
|
107
|
+
// A transaction owns its client for its whole lifetime — statements must never
|
|
108
|
+
// land on another pooled connection.
|
|
109
|
+
result = await txContext.connection.query(finalQuery, params);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// Taking the client explicitly, instead of letting `Pool.query` do it out of
|
|
113
|
+
// sight, is what makes `orm_pool_acquire_seconds` a real number instead of zero.
|
|
114
|
+
const acquireStart = process.hrtime.bigint();
|
|
115
|
+
const client = await this.Pool.connect();
|
|
116
|
+
this.observeAcquireSeconds(Number(process.hrtime.bigint() - acquireStart) / 1e9);
|
|
117
|
+
try {
|
|
118
|
+
result = await client.query(finalQuery, params);
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
client.release();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
switch (context) {
|
|
125
|
+
case QueryContext.Update:
|
|
126
|
+
case QueryContext.Delete:
|
|
127
|
+
return {
|
|
128
|
+
RowsAffected: result.rowCount ?? 0,
|
|
129
|
+
};
|
|
130
|
+
case QueryContext.Insert:
|
|
131
|
+
case QueryContext.Upsert:
|
|
132
|
+
case QueryContext.InsertReturning:
|
|
133
|
+
// Postgres has no LAST_INSERT_ID counter at all — generated keys travel in the
|
|
134
|
+
// RETURNING rows, which insertReturning: true makes the ORM ask for.
|
|
135
|
+
return {
|
|
136
|
+
RowsAffected: result.rowCount ?? result.rows.length,
|
|
137
|
+
LastInsertId: 0,
|
|
138
|
+
Returning: result.rows ?? [],
|
|
139
|
+
};
|
|
140
|
+
default:
|
|
141
|
+
return result.rows;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
throw new OrmException(`Error executing orm command `, {
|
|
146
|
+
Host: this.Options.Host,
|
|
147
|
+
User: this.Options.User,
|
|
148
|
+
Name: this.Options.Name,
|
|
149
|
+
}, stmt, params, err);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
supportedFeatures() {
|
|
153
|
+
return {
|
|
154
|
+
// No CREATE EVENT and no shared trigger dialect: scheduling on postgres is
|
|
155
|
+
// pg_cron / external, and claiming support would only move the failure further
|
|
156
|
+
// from its cause.
|
|
157
|
+
events: false,
|
|
158
|
+
insertReturning: true,
|
|
159
|
+
// With RETURNING every key comes back per row; the LAST_INSERT_ID batch walk is
|
|
160
|
+
// MySQL's workaround for not having it.
|
|
161
|
+
insertIdIsFirstOfBatch: false,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
resolve() {
|
|
165
|
+
super.resolve();
|
|
166
|
+
this.Container.register(PostgresTableExistsCompiler).as(TableExistsCompiler);
|
|
167
|
+
this.Container.register(PostgresServerResponseMapper).as(ServerResponseMapper);
|
|
168
|
+
/**
|
|
169
|
+
* The postgres dialect. Every class that would otherwise arrive from the shared
|
|
170
|
+
* `orm-sql` layer speaking MySQL is either replaced with the postgres spelling or —
|
|
171
|
+
* when the shared SQL happens to be valid postgres — claimed explicitly, so nothing
|
|
172
|
+
* dialect-specific is inherited by accident.
|
|
173
|
+
*/
|
|
174
|
+
this.Container.register(DoubleQuoteIdentifierQuoter).as(IdentifierQuoter);
|
|
175
|
+
this.Container.register(PostgresOnDuplicateQueryCompiler).as(OnDuplicateQueryCompiler);
|
|
176
|
+
this.Container.register(PostgresInsertQueryCompiler).as(InsertQueryCompiler);
|
|
177
|
+
this.Container.register(PostgresColumnQueryCompiler).as(ColumnQueryCompiler);
|
|
178
|
+
this.Container.register(PostgresAlterColumnQueryCompiler).as(AlterColumnQueryCompiler);
|
|
179
|
+
this.Container.register(PostgresLimitQueryCompiler).as(LimitQueryCompiler);
|
|
180
|
+
this.Container.register(PostgresCreateDatabaseQueryCompiler).as(CreateDatabaseCompiler);
|
|
181
|
+
this.Container.register(PostgresDefaultValueBuilder).as(DefaultValueBuilder);
|
|
182
|
+
// Shared implementations that happen to be valid postgres, claimed explicitly.
|
|
183
|
+
// DROP DATABASE IF EXISTS is among them: with this driver's quoter injected the
|
|
184
|
+
// shared compiler already emits exactly the postgres statement.
|
|
185
|
+
// `CREATE TABLE ... LIKE`, `CREATE EVENT`, MySQL trigger syntax and `CHANGE COLUMN`
|
|
186
|
+
// are NOT among them and stay unregistered: those features fail with a DI error
|
|
187
|
+
// naming the abstraction instead of reaching postgres as MySQL syntax.
|
|
188
|
+
this.Container.register(SqlDropDatabaseQueryCompiler).as(DropDatabaseCompiler);
|
|
189
|
+
this.Container.register(SqlTruncateTableQueryCompiler).as(TruncateTableQueryCompiler);
|
|
190
|
+
this.Container.register(SqlWithRecursiveCompiler).as(RecursiveQueryCompiler);
|
|
191
|
+
this.Container.register(SqlAlterTableQueryCompiler).as(AlterTableQueryCompiler);
|
|
192
|
+
}
|
|
193
|
+
/** pg.Pool publishes its bookkeeping — no private-field spelunking needed here. */
|
|
194
|
+
poolMetrics() {
|
|
195
|
+
return {
|
|
196
|
+
Size: this.Pool?.totalCount ?? 0,
|
|
197
|
+
InUse: Math.max((this.Pool?.totalCount ?? 0) - (this.Pool?.idleCount ?? 0), 0),
|
|
198
|
+
Waiting: this.Pool?.waitingCount ?? 0,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
async ping() {
|
|
202
|
+
try {
|
|
203
|
+
// deliberately bypasses `withReconnect` — a health probe that reconnects on its own
|
|
204
|
+
// would turn one dead connection into a reconnect storm on every tick.
|
|
205
|
+
await this._executeOnDbOnce('SELECT 1', [], QueryContext.Select);
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async connect() {
|
|
213
|
+
const pool = this.resolvedPoolOptions();
|
|
214
|
+
this.Pool = new pg.Pool({
|
|
215
|
+
host: this.Options.Host,
|
|
216
|
+
user: this.Options.User,
|
|
217
|
+
password: this.Options.Password,
|
|
218
|
+
port: this.Options.Port,
|
|
219
|
+
database: this.Options.Database,
|
|
220
|
+
max: pool.Max,
|
|
221
|
+
min: pool.Min,
|
|
222
|
+
idleTimeoutMillis: pool.IdleTimeout,
|
|
223
|
+
connectionTimeoutMillis: pool.AcquireTimeout,
|
|
224
|
+
});
|
|
225
|
+
// An idle client's connection can die between checkouts; without a listener pg emits
|
|
226
|
+
// 'error' on the pool and an unhandled 'error' event kills the process.
|
|
227
|
+
this.Pool.on('error', (err) => {
|
|
228
|
+
this.Log?.warn(`postgres pool connection error for ${this.Options.Name}: ${err.message}`);
|
|
229
|
+
});
|
|
230
|
+
try {
|
|
231
|
+
// Test the pool, and pin the schema when one is configured: search_path is a
|
|
232
|
+
// session setting, so it has to be set per connection as the pool opens them.
|
|
233
|
+
const client = await this.Pool.connect();
|
|
234
|
+
client.release();
|
|
235
|
+
const schema = this.Options.Options?.Schema;
|
|
236
|
+
if (schema) {
|
|
237
|
+
this.Pool.on('connect', (c) => {
|
|
238
|
+
c.query(`SET search_path TO ${pgEscapeIdentifier(schema)}`).catch((err) => {
|
|
239
|
+
this.Log?.warn(`could not set search_path to ${schema} for ${this.Options.Name}: ${err.message}`);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
// the test client above predates the listener
|
|
243
|
+
await this.executeOnDb(`SET search_path TO ${pgEscapeIdentifier(schema)}`, [], QueryContext.Schema);
|
|
244
|
+
}
|
|
245
|
+
this.setState(ConnectionState.Connected);
|
|
246
|
+
return this;
|
|
247
|
+
}
|
|
248
|
+
catch (err) {
|
|
249
|
+
await this.Pool.end().catch(() => undefined);
|
|
250
|
+
this.Pool = null;
|
|
251
|
+
throw err;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
async disconnect() {
|
|
255
|
+
this.stopHealthCheck();
|
|
256
|
+
this.setState(ConnectionState.Disconnected);
|
|
257
|
+
if (this.Pool) {
|
|
258
|
+
await this.Pool.end();
|
|
259
|
+
this.Pool = null;
|
|
260
|
+
}
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
async tableInfo(name, schema) {
|
|
264
|
+
const dbSchema = schema ?? this.Options.Options?.Schema ?? 'public';
|
|
265
|
+
// ORDER BY ordinal_position is not decoration: column order is part of what a table
|
|
266
|
+
// descriptor means, and without it postgres is free to return rows in any order.
|
|
267
|
+
const tblInfo = (await this.executeOnDb(`SELECT column_name, data_type, udt_name, is_nullable, column_default, is_identity
|
|
268
|
+
FROM information_schema.columns
|
|
269
|
+
WHERE table_name = ? AND table_schema = ?
|
|
270
|
+
ORDER BY ordinal_position`, [name, dbSchema], QueryContext.Select));
|
|
271
|
+
if (!tblInfo || !Array.isArray(tblInfo) || tblInfo.length === 0) {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
const constraints = (await this.executeOnDb(`SELECT kcu.column_name, tc.constraint_type
|
|
275
|
+
FROM information_schema.table_constraints tc
|
|
276
|
+
JOIN information_schema.key_column_usage kcu
|
|
277
|
+
ON kcu.constraint_name = tc.constraint_name AND kcu.table_schema = tc.table_schema
|
|
278
|
+
WHERE tc.table_name = ? AND tc.table_schema = ?`, [name, dbSchema], QueryContext.Select));
|
|
279
|
+
return tblInfo.map((r) => {
|
|
280
|
+
const isPrimary = constraints.find((c) => c.constraint_type === 'PRIMARY KEY' && c.column_name === r.column_name) !== undefined;
|
|
281
|
+
const isUnique = constraints.find((c) => c.constraint_type === 'UNIQUE' && c.column_name === r.column_name) !== undefined;
|
|
282
|
+
return {
|
|
283
|
+
// udt_name is the concrete type ( int4, varchar, numeric ); data_type spells the
|
|
284
|
+
// standard name ( "character varying" ) that nothing downstream recognises.
|
|
285
|
+
Type: r.udt_name,
|
|
286
|
+
MaxLength: -1,
|
|
287
|
+
Comment: '',
|
|
288
|
+
DefaultValue: r.column_default,
|
|
289
|
+
NativeType: r.udt_name,
|
|
290
|
+
Unsigned: false,
|
|
291
|
+
Nullable: r.is_nullable === 'YES',
|
|
292
|
+
PrimaryKey: isPrimary,
|
|
293
|
+
Uuid: false,
|
|
294
|
+
Ignore: false,
|
|
295
|
+
IsForeignKey: false,
|
|
296
|
+
Virtual: false,
|
|
297
|
+
ForeignKeyDescription: null,
|
|
298
|
+
// identity is postgres 10+; nextval() in the default is the legacy SERIAL spelling
|
|
299
|
+
AutoIncrement: r.is_identity === 'YES' || (r.column_default ?? '').startsWith('nextval('),
|
|
300
|
+
Name: r.column_name,
|
|
301
|
+
Aggregate: false,
|
|
302
|
+
Converter: null,
|
|
303
|
+
Schema: dbSchema,
|
|
304
|
+
Unique: isUnique,
|
|
305
|
+
};
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Pulls the pooled client out of a transaction context. The base class only ever hands
|
|
310
|
+
* us contexts this driver's own `_begin` produced.
|
|
311
|
+
*/
|
|
312
|
+
txConnection(ctx) {
|
|
313
|
+
return ctx.connection;
|
|
314
|
+
}
|
|
315
|
+
async _begin(options) {
|
|
316
|
+
const connection = await this.Pool.connect();
|
|
317
|
+
try {
|
|
318
|
+
await connection.query('BEGIN');
|
|
319
|
+
if (options?.isolation) {
|
|
320
|
+
// Unlike MySQL, postgres sets the level INSIDE the transaction. The level is a
|
|
321
|
+
// fixed, validated enum — never caller-supplied free text.
|
|
322
|
+
await connection.query(`SET TRANSACTION ISOLATION LEVEL ${options.isolation}`);
|
|
323
|
+
}
|
|
324
|
+
return { connection, depth: 0 };
|
|
325
|
+
}
|
|
326
|
+
catch (err) {
|
|
327
|
+
connection.release();
|
|
328
|
+
throw err;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
async _commit(ctx) {
|
|
332
|
+
await this.txConnection(ctx).query('COMMIT');
|
|
333
|
+
}
|
|
334
|
+
async _rollback(ctx) {
|
|
335
|
+
await this.txConnection(ctx).query('ROLLBACK');
|
|
336
|
+
}
|
|
337
|
+
// savepoint names cannot be bound parameters, so they are inlined through this driver's
|
|
338
|
+
// own identifier escaper rather than passed as `?`
|
|
339
|
+
async _savepoint(ctx, name) {
|
|
340
|
+
await this.txConnection(ctx).query(`SAVEPOINT ${pgEscapeIdentifier(name)}`);
|
|
341
|
+
}
|
|
342
|
+
async _releaseSavepoint(ctx, name) {
|
|
343
|
+
await this.txConnection(ctx).query(`RELEASE SAVEPOINT ${pgEscapeIdentifier(name)}`);
|
|
344
|
+
}
|
|
345
|
+
async _rollbackToSavepoint(ctx, name) {
|
|
346
|
+
await this.txConnection(ctx).query(`ROLLBACK TO SAVEPOINT ${pgEscapeIdentifier(name)}`);
|
|
347
|
+
}
|
|
348
|
+
_dispose(ctx) {
|
|
349
|
+
this.txConnection(ctx).release();
|
|
350
|
+
return Promise.resolve();
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
PostgresOrmDriver = __decorate([
|
|
354
|
+
Injectable('orm-driver-postgres'),
|
|
355
|
+
NewInstance()
|
|
356
|
+
], PostgresOrmDriver);
|
|
357
|
+
export { PostgresOrmDriver };
|
|
358
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAuD;AACvD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAgC,mBAAmB,EAAE,YAAY,EAAE,oBAAoB,EAA+E,eAAe,EAAgB,gBAAgB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACngB,OAAO,EAAE,S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CAAC;IAC9E,CAAC;IAES,KAAK,CAAC,iBAAiB,CAAC,GAAwB,EAAE,IAAY;QACtE,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,qBAAqB,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACtF,CAAC;IAES,KAAK,CAAC,oBAAoB,CAAC,GAAwB,EAAE,IAAY;QACzE,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,yBAAyB,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1F,CAAC;IAES,QAAQ,CAAC,GAAwB;QACzC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;QACjC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF,CAAA;AA9VY,iBAAiB;IAF7B,UAAU,CAAC,qBAAqB,CAAC;IACjC,WAAW,EAAE;GACD,iBAAiB,CA8V7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IdentifierQuoter } from '@spinajs/orm';
|
|
2
|
+
/**
|
|
3
|
+
* PostgreSQL quotes identifiers with the ANSI double quote and escapes an embedded `"` by
|
|
4
|
+
* doubling it. The shared `orm-sql` helper emits backticks, which PostgreSQL reads as an
|
|
5
|
+
* operator error, so the driver carries its own escaper for its internal SQL ( savepoint
|
|
6
|
+
* names, schema probes ) the same way MSSQL does.
|
|
7
|
+
*/
|
|
8
|
+
export declare function pgEscapeIdentifier(name: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* The ANSI double quote — PostgreSQL's identifier quoting. Registered by the postgres
|
|
11
|
+
* driver as its {@link IdentifierQuoter}, never inherited: MySQL rejects `"` as an
|
|
12
|
+
* identifier quote unless ANSI_QUOTES is on, so nothing here is portable either way.
|
|
13
|
+
*/
|
|
14
|
+
export declare class DoubleQuoteIdentifierQuoter extends IdentifierQuoter {
|
|
15
|
+
quote(name: string): string;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=statements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../src/statements.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;GAIG;AACH,qBACa,2BAA4B,SAAQ,gBAAgB;IACxD,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { NewInstance } from '@spinajs/di';
|
|
8
|
+
import { IdentifierQuoter } from '@spinajs/orm';
|
|
9
|
+
/**
|
|
10
|
+
* PostgreSQL quotes identifiers with the ANSI double quote and escapes an embedded `"` by
|
|
11
|
+
* doubling it. The shared `orm-sql` helper emits backticks, which PostgreSQL reads as an
|
|
12
|
+
* operator error, so the driver carries its own escaper for its internal SQL ( savepoint
|
|
13
|
+
* names, schema probes ) the same way MSSQL does.
|
|
14
|
+
*/
|
|
15
|
+
export function pgEscapeIdentifier(name) {
|
|
16
|
+
return '"' + String(name).replace(/"/g, '""') + '"';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The ANSI double quote — PostgreSQL's identifier quoting. Registered by the postgres
|
|
20
|
+
* driver as its {@link IdentifierQuoter}, never inherited: MySQL rejects `"` as an
|
|
21
|
+
* identifier quote unless ANSI_QUOTES is on, so nothing here is portable either way.
|
|
22
|
+
*/
|
|
23
|
+
let DoubleQuoteIdentifierQuoter = class DoubleQuoteIdentifierQuoter extends IdentifierQuoter {
|
|
24
|
+
quote(name) {
|
|
25
|
+
return pgEscapeIdentifier(name);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
DoubleQuoteIdentifierQuoter = __decorate([
|
|
29
|
+
NewInstance()
|
|
30
|
+
], DoubleQuoteIdentifierQuoter);
|
|
31
|
+
export { DoubleQuoteIdentifierQuoter };
|
|
32
|
+
//# sourceMappingURL=statements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statements.js","sourceRoot":"","sources":["../../src/statements.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,GAAG,CAAC;AACtD,CAAC;AAED;;;;GAIG;AAEI,IAAM,2BAA2B,GAAjC,MAAM,2BAA4B,SAAQ,gBAAgB;IACxD,KAAK,CAAC,IAAY;QACvB,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACF,CAAA;AAJY,2BAA2B;IADvC,WAAW,EAAE;GACD,2BAA2B,CAIvC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** One row of `information_schema.columns` — only the fields tableInfo() reads. */
|
|
2
|
+
export interface ITableColumnInfo {
|
|
3
|
+
column_name: string;
|
|
4
|
+
data_type: string;
|
|
5
|
+
udt_name: string;
|
|
6
|
+
is_nullable: 'YES' | 'NO';
|
|
7
|
+
column_default: string | null;
|
|
8
|
+
is_identity: 'YES' | 'NO';
|
|
9
|
+
}
|
|
10
|
+
/** One row of the constraint probe joining table_constraints and key_column_usage. */
|
|
11
|
+
export interface IConstraintInfo {
|
|
12
|
+
column_name: string;
|
|
13
|
+
constraint_type: 'PRIMARY KEY' | 'UNIQUE' | 'FOREIGN KEY' | 'CHECK';
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,KAAK,GAAG,IAAI,CAAC;IAC1B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,WAAW,EAAE,KAAK,GAAG,IAAI,CAAC;CAC3B;AAED,sFAAsF;AACtF,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,aAAa,GAAG,QAAQ,GAAG,aAAa,GAAG,OAAO,CAAC;CACrE"}
|
package/lib/mjs/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|