@mikro-orm/oracledb 7.3.0-dev.23 → 7.3.0-dev.24
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/OracleConnection.js +5 -2
- package/OraclePlatform.js +2 -1
- package/OracleSchemaGenerator.d.ts +1 -0
- package/OracleSchemaGenerator.js +22 -19
- package/package.json +4 -4
package/OracleConnection.js
CHANGED
|
@@ -114,7 +114,8 @@ export class OracleConnection extends AbstractSqlConnection {
|
|
|
114
114
|
ret.poolMax = pool?.max;
|
|
115
115
|
ret.poolTimeout = pool?.idleTimeoutMillis;
|
|
116
116
|
const user = this.config.get('user', dbName);
|
|
117
|
-
ret.user =
|
|
117
|
+
ret.user =
|
|
118
|
+
user.startsWith('"') || user === 'system' ? user : this.platform.quoteIdentifier(user).replaceAll('\\?', '?');
|
|
118
119
|
ret.connectionString = this.options.clientUrl ?? this.platform.getDefaultClientUrl();
|
|
119
120
|
Reflect.deleteProperty(ret, 'database');
|
|
120
121
|
Reflect.deleteProperty(ret, 'port');
|
|
@@ -123,6 +124,8 @@ export class OracleConnection extends AbstractSqlConnection {
|
|
|
123
124
|
}
|
|
124
125
|
async execute(query, params = [], method = 'all', ctx, loggerContext) {
|
|
125
126
|
await this.ensureConnection();
|
|
127
|
+
// a plain string without params is not a template, so it is sent as is
|
|
128
|
+
const verbatim = typeof query === 'string' && params.length === 0;
|
|
126
129
|
if (query instanceof NativeQueryBuilder) {
|
|
127
130
|
query = query.toRaw();
|
|
128
131
|
}
|
|
@@ -141,7 +144,7 @@ export class OracleConnection extends AbstractSqlConnection {
|
|
|
141
144
|
params = [...params.slice(0, -1), last];
|
|
142
145
|
}
|
|
143
146
|
query = this.config.get('onQuery')(query, params);
|
|
144
|
-
const formatted = this.platform.formatQuery(query, params);
|
|
147
|
+
const formatted = verbatim ? query : this.platform.formatQuery(query, params);
|
|
145
148
|
const sql = this.getSql(rawQuery ?? query, formatted, loggerContext);
|
|
146
149
|
return this.executeQuery(sql, async () => {
|
|
147
150
|
const compiled = CompiledQuery.raw(formatted, last);
|
package/OraclePlatform.js
CHANGED
|
@@ -210,7 +210,8 @@ export class OraclePlatform extends AbstractSqlPlatform {
|
|
|
210
210
|
if (b.length === 0) {
|
|
211
211
|
return raw(`json_equal(${root}, json(?))`, [value]);
|
|
212
212
|
}
|
|
213
|
-
|
|
213
|
+
const jsonPath = this.quoteValue(`$.${b.map(this.quoteJsonKey).join('.')}`).replaceAll('?', '\\?');
|
|
214
|
+
return raw(`json_value(${root}, ${jsonPath})`);
|
|
214
215
|
}
|
|
215
216
|
processJsonCondition(o, value, path, alias) {
|
|
216
217
|
if (Utils.isPlainObject(value) && !Object.keys(value).some(k => Utils.isOperator(k))) {
|
|
@@ -27,6 +27,7 @@ export declare class OracleSchemaGenerator extends SchemaGenerator {
|
|
|
27
27
|
*/
|
|
28
28
|
getDropSchemaSQL(options?: Omit<DropSchemaOptions, 'dropDb'>): Promise<string>;
|
|
29
29
|
ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
|
|
30
|
+
private quote;
|
|
30
31
|
private getOriginalUser;
|
|
31
32
|
/**
|
|
32
33
|
* Connects as the management (system) user if not already connected as admin.
|
package/OracleSchemaGenerator.js
CHANGED
|
@@ -19,7 +19,7 @@ export class OracleSchemaGenerator extends SchemaGenerator {
|
|
|
19
19
|
const tableSpace = this.config.get('schemaGenerator').tableSpace ?? 'mikro_orm';
|
|
20
20
|
const password = this.connection.mapOptions({}).password;
|
|
21
21
|
try {
|
|
22
|
-
await this.execute(`create tablespace ${this.
|
|
22
|
+
await this.execute(`create tablespace ${this.quote(tableSpace)} datafile '${tableSpace.replaceAll(`'`, `''`)}.dbf' size 100M autoextend on`);
|
|
23
23
|
}
|
|
24
24
|
catch (e) {
|
|
25
25
|
if (e.code !== 'ORA-01543') {
|
|
@@ -27,13 +27,13 @@ export class OracleSchemaGenerator extends SchemaGenerator {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
const sql = [
|
|
30
|
-
`create user ${this.
|
|
31
|
-
`identified by ${this.
|
|
32
|
-
`default tablespace ${this.
|
|
33
|
-
`quota unlimited on ${this.
|
|
30
|
+
`create user ${this.quote(name)}`,
|
|
31
|
+
`identified by ${this.quote(password)}`,
|
|
32
|
+
`default tablespace ${this.quote(tableSpace)}`,
|
|
33
|
+
`quota unlimited on ${this.quote(tableSpace)}`,
|
|
34
34
|
].join(' ');
|
|
35
35
|
await this.execute(sql);
|
|
36
|
-
await this.execute(`grant connect, resource to ${this.
|
|
36
|
+
await this.execute(`grant connect, resource to ${this.quote(name)}`);
|
|
37
37
|
this.config.set('user', name);
|
|
38
38
|
await this.driver.reconnect(options);
|
|
39
39
|
}
|
|
@@ -120,6 +120,9 @@ export class OracleSchemaGenerator extends SchemaGenerator {
|
|
|
120
120
|
}
|
|
121
121
|
return false;
|
|
122
122
|
}
|
|
123
|
+
quote(id) {
|
|
124
|
+
return this.platform.quoteIdentifier(id).replaceAll('\\?', '?');
|
|
125
|
+
}
|
|
123
126
|
getOriginalUser() {
|
|
124
127
|
return this.config.get('user') ?? this.config.get('dbName');
|
|
125
128
|
}
|
|
@@ -161,14 +164,14 @@ export class OracleSchemaGenerator extends SchemaGenerator {
|
|
|
161
164
|
return;
|
|
162
165
|
}
|
|
163
166
|
try {
|
|
164
|
-
await this.execute(`grant dba to ${this.
|
|
167
|
+
await this.execute(`grant dba to ${this.quote(originalUser)}`);
|
|
165
168
|
}
|
|
166
169
|
catch {
|
|
167
|
-
await this.execute(`grant create any table to ${this.
|
|
168
|
-
await this.execute(`grant alter any table to ${this.
|
|
169
|
-
await this.execute(`grant drop any table to ${this.
|
|
170
|
-
await this.execute(`grant create any index to ${this.
|
|
171
|
-
await this.execute(`grant drop any index to ${this.
|
|
170
|
+
await this.execute(`grant create any table to ${this.quote(originalUser)}`);
|
|
171
|
+
await this.execute(`grant alter any table to ${this.quote(originalUser)}`);
|
|
172
|
+
await this.execute(`grant drop any table to ${this.quote(originalUser)}`);
|
|
173
|
+
await this.execute(`grant create any index to ${this.quote(originalUser)}`);
|
|
174
|
+
await this.execute(`grant drop any index to ${this.quote(originalUser)}`);
|
|
172
175
|
}
|
|
173
176
|
this.hasDbaGrant = true;
|
|
174
177
|
}
|
|
@@ -184,7 +187,7 @@ export class OracleSchemaGenerator extends SchemaGenerator {
|
|
|
184
187
|
throw e;
|
|
185
188
|
}
|
|
186
189
|
}
|
|
187
|
-
await this.execute(`grant connect, resource to ${this.
|
|
190
|
+
await this.execute(`grant connect, resource to ${this.quote(name)}`);
|
|
188
191
|
await this.ensureDbaGrant(originalUser);
|
|
189
192
|
await this.grantReferencesForSchema(name);
|
|
190
193
|
await this.restoreConnection(reconnectUser);
|
|
@@ -262,7 +265,7 @@ export class OracleSchemaGenerator extends SchemaGenerator {
|
|
|
262
265
|
throw e;
|
|
263
266
|
}
|
|
264
267
|
}
|
|
265
|
-
await this.execute(`grant connect, resource to ${this.
|
|
268
|
+
await this.execute(`grant connect, resource to ${this.quote(ns)}`);
|
|
266
269
|
}
|
|
267
270
|
await this.ensureDbaGrant(originalUser);
|
|
268
271
|
for (const ns of diff.newNamespaces) {
|
|
@@ -319,7 +322,7 @@ export class OracleSchemaGenerator extends SchemaGenerator {
|
|
|
319
322
|
}
|
|
320
323
|
/* v8 ignore start: requires multi-schema Oracle setup */
|
|
321
324
|
try {
|
|
322
|
-
await this.execute(`grant references on ${this.
|
|
325
|
+
await this.execute(`grant references on ${this.quote(tableSchema)}.${this.quote(table.name)} to ${this.quote(schema)}`);
|
|
323
326
|
}
|
|
324
327
|
catch {
|
|
325
328
|
// ignore errors (e.g., table doesn't exist yet in that schema)
|
|
@@ -369,14 +372,14 @@ export class OracleSchemaGenerator extends SchemaGenerator {
|
|
|
369
372
|
const tableName = this.driver.getTableName(meta, { schema }, false);
|
|
370
373
|
const quoted = tableName
|
|
371
374
|
.split('.')
|
|
372
|
-
.map(p => this.
|
|
375
|
+
.map(p => this.quote(p))
|
|
373
376
|
.join('.');
|
|
374
377
|
// Use DELETE instead of TRUNCATE to avoid ORA-02266 (FK constraint check regardless of data)
|
|
375
378
|
stmts.push(`begin execute immediate 'delete from ${quoted}'; exception when others then if sqlcode != -942 then raise; end if; end;`);
|
|
376
379
|
// non-PK identity columns are only reset when they declare `sequence`
|
|
377
380
|
for (const prop of meta.props.filter(p => p.autoincrement && (p.primary || p.sequence))) {
|
|
378
381
|
const startWith = prop.sequence?.startWith ?? 'limit value';
|
|
379
|
-
stmts.push(`begin execute immediate 'alter table ${quoted} modify ${this.
|
|
382
|
+
stmts.push(`begin execute immediate 'alter table ${quoted} modify ${this.quote(prop.fieldNames[0])} generated by default as identity (start with ${startWith})'; exception when others then null; end;`);
|
|
380
383
|
}
|
|
381
384
|
}
|
|
382
385
|
/* v8 ignore next 5: empty stmts branch */
|
|
@@ -398,7 +401,7 @@ export class OracleSchemaGenerator extends SchemaGenerator {
|
|
|
398
401
|
const tables = await this.connection.execute(`select table_name from all_tables where owner = ${this.platform.quoteValue(otherSchema)}`);
|
|
399
402
|
for (const table of tables) {
|
|
400
403
|
try {
|
|
401
|
-
await this.execute(`grant references on ${this.
|
|
404
|
+
await this.execute(`grant references on ${this.quote(otherSchema)}.${this.quote(table.table_name)} to ${this.quote(schemaName)}`);
|
|
402
405
|
}
|
|
403
406
|
catch {
|
|
404
407
|
// ignore errors
|
|
@@ -408,7 +411,7 @@ export class OracleSchemaGenerator extends SchemaGenerator {
|
|
|
408
411
|
const newTables = await this.connection.execute(`select table_name from all_tables where owner = ${this.platform.quoteValue(schemaName)}`);
|
|
409
412
|
for (const table of newTables) {
|
|
410
413
|
try {
|
|
411
|
-
await this.execute(`grant references on ${this.
|
|
414
|
+
await this.execute(`grant references on ${this.quote(schemaName)}.${this.quote(table.table_name)} to ${this.quote(otherSchema)}`);
|
|
412
415
|
}
|
|
413
416
|
catch {
|
|
414
417
|
// ignore errors
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/oracledb",
|
|
3
|
-
"version": "7.3.0-dev.
|
|
3
|
+
"version": "7.3.0-dev.24",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL, SQLite, MSSQL and Oracle databases.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -42,15 +42,15 @@
|
|
|
42
42
|
"copy": "node ../../scripts/copy.mjs"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@mikro-orm/sql": "7.3.0-dev.
|
|
45
|
+
"@mikro-orm/sql": "7.3.0-dev.24",
|
|
46
46
|
"kysely": "0.29.9",
|
|
47
47
|
"oracledb": "26.0.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@mikro-orm/core": "^7.2.
|
|
50
|
+
"@mikro-orm/core": "^7.2.11"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@mikro-orm/core": "7.3.0-dev.
|
|
53
|
+
"@mikro-orm/core": "7.3.0-dev.24"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">= 22.17.0"
|