@mikro-orm/oracledb 7.0.8-dev.7 → 7.0.8

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.
@@ -1,86 +1,93 @@
1
- import { isRaw, raw, Utils, } from '@mikro-orm/core';
1
+ import { isRaw, raw, Utils } from '@mikro-orm/core';
2
2
  import { QueryBuilder, QueryType } from '@mikro-orm/sql';
3
3
  /** Query builder with Oracle-specific behavior such as RETURNING clause handling and lock table conversion. */
4
4
  export class OracleQueryBuilder extends QueryBuilder {
5
- insert(data) {
6
- for (const row of Utils.asArray(data)) {
7
- if (this.mainAlias.meta && Object.keys(row).length === 0) {
8
- // ensure that we insert at least one column, otherwise Oracle will throw an error
9
- row[this.mainAlias.meta.primaryKeys[0]] = raw('default');
10
- }
11
- }
12
- return this.init(QueryType.INSERT, data);
5
+ insert(data) {
6
+ for (const row of Utils.asArray(data)) {
7
+ if (this.mainAlias.meta && Object.keys(row).length === 0) {
8
+ // ensure that we insert at least one column, otherwise Oracle will throw an error
9
+ row[this.mainAlias.meta.primaryKeys[0]] = raw('default');
10
+ }
13
11
  }
14
- setLockMode(mode, tables) {
15
- if (tables) {
16
- this.convertLockTablesToColumnRefs(tables);
17
- }
18
- return super.setLockMode(mode, tables);
12
+ return this.init(QueryType.INSERT, data);
13
+ }
14
+ setLockMode(mode, tables) {
15
+ if (tables) {
16
+ this.convertLockTablesToColumnRefs(tables);
19
17
  }
20
- getNativeQuery(processVirtualEntity = true) {
21
- const qb = super.getNativeQuery(processVirtualEntity);
22
- // Convert lockTables from table aliases to column references for Oracle
23
- // This handles the case where lockTables are auto-computed from joins
24
- const lockTables = qb.options?.lockTables;
25
- if (lockTables?.length) {
26
- this.convertLockTablesToColumnRefs(lockTables);
27
- }
28
- return qb;
18
+ return super.setLockMode(mode, tables);
19
+ }
20
+ getNativeQuery(processVirtualEntity = true) {
21
+ const qb = super.getNativeQuery(processVirtualEntity);
22
+ // Convert lockTables from table aliases to column references for Oracle
23
+ // This handles the case where lockTables are auto-computed from joins
24
+ const lockTables = qb.options?.lockTables;
25
+ if (lockTables?.length) {
26
+ this.convertLockTablesToColumnRefs(lockTables);
29
27
  }
30
- convertLockTablesToColumnRefs(tables) {
31
- for (let i = 0; i < tables.length; i++) {
32
- if (!tables[i].includes('.')) {
33
- const aliasInfo = this.state.aliases[tables[i]];
34
- /* v8 ignore next 3: defensive — alias always has meta when called from ORM */
35
- if (aliasInfo?.meta) {
36
- tables[i] += '.' + aliasInfo.meta.getPrimaryProp().fieldNames[0];
37
- }
38
- }
28
+ return qb;
29
+ }
30
+ convertLockTablesToColumnRefs(tables) {
31
+ for (let i = 0; i < tables.length; i++) {
32
+ if (!tables[i].includes('.')) {
33
+ const aliasInfo = this.state.aliases[tables[i]];
34
+ /* v8 ignore next 3: defensive — alias always has meta when called from ORM */
35
+ if (aliasInfo?.meta) {
36
+ tables[i] += '.' + aliasInfo.meta.getPrimaryProp().fieldNames[0];
39
37
  }
38
+ }
40
39
  }
41
- processReturningStatement(qb, meta, data, returning) {
42
- if (!meta || !data) {
43
- return;
44
- }
45
- const arr = Utils.asArray(data);
46
- // always respect explicit returning hint
47
- if (returning && returning.length > 0) {
48
- qb.returning(
49
- /* v8 ignore next 8: non-string field branch */
50
- returning.map(field => {
51
- if (typeof field === 'string') {
52
- const prop = this.helper.getProperty(field);
53
- return [prop?.fieldNames[0] ?? field, prop?.runtimeType ?? 'string'];
54
- }
55
- return this.helper.mapper(field, this.type);
56
- }));
57
- return;
58
- }
59
- if (this.type === QueryType.INSERT) {
60
- const returningProps = meta.hydrateProps
61
- .filter(prop => prop.returning || (prop.persist !== false && ((prop.primary && prop.autoincrement) || prop.defaultRaw)))
62
- .filter(prop => !(prop.fieldNames[0] in arr[0]) || isRaw(arr[0][prop.fieldNames[0]]));
63
- if (returningProps.length > 0) {
64
- qb.returning(returningProps.map(prop => [prop.fieldNames[0], prop.runtimeType]));
65
- }
66
- return;
67
- }
68
- /* v8 ignore next: implicit fallthrough for non-INSERT/UPDATE types */
69
- if (this.type === QueryType.UPDATE) {
70
- const returningProps = meta.hydrateProps.filter(prop => prop.fieldNames && isRaw(arr[0][prop.fieldNames[0]]));
71
- if (returningProps.length > 0) {
72
- qb.returning(returningProps.map(prop => {
73
- /* v8 ignore next 7: NativeQueryBuilder does not support raw fragments in returning yet */
74
- if (prop.hasConvertToJSValueSQL) {
75
- const aliased = this.platform.quoteIdentifier(prop.fieldNames[0]);
76
- const sql = prop.customType.convertToJSValueSQL(aliased, this.platform) +
77
- ' as ' +
78
- this.platform.quoteIdentifier(prop.fieldNames[0]);
79
- return raw(sql);
80
- }
81
- return [prop.fieldNames[0], prop.runtimeType];
82
- }));
40
+ }
41
+ processReturningStatement(qb, meta, data, returning) {
42
+ if (!meta || !data) {
43
+ return;
44
+ }
45
+ const arr = Utils.asArray(data);
46
+ // always respect explicit returning hint
47
+ if (returning && returning.length > 0) {
48
+ qb.returning(
49
+ /* v8 ignore next 8: non-string field branch */
50
+ returning.map(field => {
51
+ if (typeof field === 'string') {
52
+ const prop = this.helper.getProperty(field);
53
+ return [prop?.fieldNames[0] ?? field, prop?.runtimeType ?? 'string'];
54
+ }
55
+ return this.helper.mapper(field, this.type);
56
+ }),
57
+ );
58
+ return;
59
+ }
60
+ if (this.type === QueryType.INSERT) {
61
+ const returningProps = meta.hydrateProps
62
+ .filter(
63
+ prop =>
64
+ prop.returning || (prop.persist !== false && ((prop.primary && prop.autoincrement) || prop.defaultRaw)),
65
+ )
66
+ .filter(prop => !(prop.fieldNames[0] in arr[0]) || isRaw(arr[0][prop.fieldNames[0]]));
67
+ if (returningProps.length > 0) {
68
+ qb.returning(returningProps.map(prop => [prop.fieldNames[0], prop.runtimeType]));
69
+ }
70
+ return;
71
+ }
72
+ /* v8 ignore next: implicit fallthrough for non-INSERT/UPDATE types */
73
+ if (this.type === QueryType.UPDATE) {
74
+ const returningProps = meta.hydrateProps.filter(prop => prop.fieldNames && isRaw(arr[0][prop.fieldNames[0]]));
75
+ if (returningProps.length > 0) {
76
+ qb.returning(
77
+ returningProps.map(prop => {
78
+ /* v8 ignore next 7: NativeQueryBuilder does not support raw fragments in returning yet */
79
+ if (prop.hasConvertToJSValueSQL) {
80
+ const aliased = this.platform.quoteIdentifier(prop.fieldNames[0]);
81
+ const sql =
82
+ prop.customType.convertToJSValueSQL(aliased, this.platform) +
83
+ ' as ' +
84
+ this.platform.quoteIdentifier(prop.fieldNames[0]);
85
+ return raw(sql);
83
86
  }
84
- }
87
+ return [prop.fieldNames[0], prop.runtimeType];
88
+ }),
89
+ );
90
+ }
85
91
  }
92
+ }
86
93
  }
@@ -1,42 +1,50 @@
1
- import { type DropSchemaOptions, type MikroORM, type UpdateSchemaOptions, SchemaGenerator, DatabaseSchema, type EnsureDatabaseOptions, type ClearDatabaseOptions } from '@mikro-orm/sql';
1
+ import {
2
+ type DropSchemaOptions,
3
+ type MikroORM,
4
+ type UpdateSchemaOptions,
5
+ SchemaGenerator,
6
+ DatabaseSchema,
7
+ type EnsureDatabaseOptions,
8
+ type ClearDatabaseOptions,
9
+ } from '@mikro-orm/sql';
2
10
  import type { OracleSchemaHelper } from './OracleSchemaHelper.js';
3
11
  import type { OracleConnection } from './OracleConnection.js';
4
12
  /** Schema generator with Oracle-specific behavior for multi-schema support and privilege management. */
5
13
  export declare class OracleSchemaGenerator extends SchemaGenerator {
6
- protected helper: OracleSchemaHelper;
7
- protected connection: OracleConnection;
8
- /** Tracks whether the main user has been granted DBA (or equivalent) privileges. */
9
- private hasDbaGrant;
10
- static register(orm: MikroORM): void;
11
- /**
12
- * creates new database and connects to it
13
- */
14
- createDatabase(name?: string): Promise<void>;
15
- dropDatabase(name?: string): Promise<void>;
16
- /**
17
- * Oracle uses CASCADE CONSTRAINT in DROP TABLE and has no native enums,
18
- * so we can generate drop SQL from metadata alone — no DB introspection needed.
19
- */
20
- getDropSchemaSQL(options?: Omit<DropSchemaOptions, 'dropDb'>): Promise<string>;
21
- ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
22
- private getOriginalUser;
23
- /**
24
- * Connects as the management (system) user if not already connected as admin.
25
- * Returns the original user to restore later, or undefined if no reconnect was needed.
26
- */
27
- private connectAsAdmin;
28
- /**
29
- * Restores the connection to the original user after admin operations.
30
- */
31
- private restoreConnection;
32
- /**
33
- * Grants DBA (or fallback individual privileges) to the main user.
34
- * Only executed once — subsequent calls are no-ops.
35
- */
36
- private ensureDbaGrant;
37
- createNamespace(name: string): Promise<void>;
38
- dropNamespace(name: string): Promise<void>;
39
- update(options?: UpdateSchemaOptions<DatabaseSchema>): Promise<void>;
40
- clear(options?: ClearDatabaseOptions): Promise<void>;
41
- private grantReferencesForSchema;
14
+ protected helper: OracleSchemaHelper;
15
+ protected connection: OracleConnection;
16
+ /** Tracks whether the main user has been granted DBA (or equivalent) privileges. */
17
+ private hasDbaGrant;
18
+ static register(orm: MikroORM): void;
19
+ /**
20
+ * creates new database and connects to it
21
+ */
22
+ createDatabase(name?: string): Promise<void>;
23
+ dropDatabase(name?: string): Promise<void>;
24
+ /**
25
+ * Oracle uses CASCADE CONSTRAINT in DROP TABLE and has no native enums,
26
+ * so we can generate drop SQL from metadata alone — no DB introspection needed.
27
+ */
28
+ getDropSchemaSQL(options?: Omit<DropSchemaOptions, 'dropDb'>): Promise<string>;
29
+ ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
30
+ private getOriginalUser;
31
+ /**
32
+ * Connects as the management (system) user if not already connected as admin.
33
+ * Returns the original user to restore later, or undefined if no reconnect was needed.
34
+ */
35
+ private connectAsAdmin;
36
+ /**
37
+ * Restores the connection to the original user after admin operations.
38
+ */
39
+ private restoreConnection;
40
+ /**
41
+ * Grants DBA (or fallback individual privileges) to the main user.
42
+ * Only executed once — subsequent calls are no-ops.
43
+ */
44
+ private ensureDbaGrant;
45
+ createNamespace(name: string): Promise<void>;
46
+ dropNamespace(name: string): Promise<void>;
47
+ update(options?: UpdateSchemaOptions<DatabaseSchema>): Promise<void>;
48
+ clear(options?: ClearDatabaseOptions): Promise<void>;
49
+ private grantReferencesForSchema;
42
50
  }