@bdkinc/knex-ibmi 0.3.22 → 0.4.3
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 +290 -139
- package/dist/cli.cjs +531 -0
- package/dist/index.d.mts +156 -0
- package/dist/index.d.ts +55 -53
- package/dist/index.js +969 -158
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1359 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +29 -20
package/dist/index.d.ts
CHANGED
|
@@ -1,52 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import knex, { Knex } from 'knex';
|
|
2
2
|
import odbc, { Connection } from 'odbc';
|
|
3
|
-
import SchemaCompiler from 'knex/lib/schema/compiler';
|
|
4
|
-
import TableCompiler from 'knex/lib/schema/tablecompiler';
|
|
5
|
-
import ColumnCompiler from 'knex/lib/schema/columncompiler';
|
|
6
|
-
import QueryCompiler from 'knex/lib/query/querycompiler';
|
|
7
3
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
interface IBMiMigrationConfig {
|
|
5
|
+
directory: string;
|
|
6
|
+
tableName: string;
|
|
7
|
+
schemaName?: string;
|
|
8
|
+
extension?: string;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
commit(connection: Connection): Promise<void>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
declare class IBMiColumnCompiler extends ColumnCompiler {
|
|
28
|
-
increments(options?: {
|
|
29
|
-
primaryKey: boolean;
|
|
30
|
-
}): string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
declare class IBMiQueryCompiler extends QueryCompiler {
|
|
34
|
-
insert(): "" | {
|
|
35
|
-
sql: string;
|
|
36
|
-
returning: any;
|
|
37
|
-
};
|
|
38
|
-
_buildInsertData(insertValues: string | any[], returningSql: string): string;
|
|
39
|
-
_prepInsert(data: any): {
|
|
40
|
-
columns: any;
|
|
41
|
-
values: any;
|
|
42
|
-
};
|
|
43
|
-
update(): {
|
|
44
|
-
sql: string;
|
|
45
|
-
returning: any;
|
|
46
|
-
};
|
|
47
|
-
_returning(method: string, value: any, withTrigger: undefined): string | undefined;
|
|
48
|
-
columnizeWithPrefix(prefix: string, target: any): string;
|
|
10
|
+
declare class IBMiMigrationRunner {
|
|
11
|
+
private knex;
|
|
12
|
+
private config;
|
|
13
|
+
constructor(knex: Knex, config?: Partial<IBMiMigrationConfig>);
|
|
14
|
+
private getFullTableName;
|
|
15
|
+
latest(): Promise<void>;
|
|
16
|
+
rollback(steps?: number): Promise<void>;
|
|
17
|
+
currentVersion(): Promise<string | null>;
|
|
18
|
+
listExecuted(): Promise<string[]>;
|
|
19
|
+
listPending(): Promise<string[]>;
|
|
20
|
+
private getMigrationFiles;
|
|
21
|
+
private getMigrationPath;
|
|
49
22
|
}
|
|
23
|
+
declare function createIBMiMigrationRunner(knex: Knex, config?: Partial<IBMiMigrationConfig>): IBMiMigrationRunner;
|
|
50
24
|
|
|
51
25
|
interface QueryObject {
|
|
52
26
|
response?: {
|
|
@@ -70,20 +44,35 @@ declare enum SqlMethod {
|
|
|
70
44
|
}
|
|
71
45
|
declare class DB2Client extends knex.Client {
|
|
72
46
|
constructor(config: Knex.Config<DB2Config>);
|
|
47
|
+
private safeStringify;
|
|
73
48
|
_driver(): typeof odbc;
|
|
74
|
-
wrapIdentifierImpl(value:
|
|
49
|
+
wrapIdentifierImpl(value: string): string;
|
|
75
50
|
printDebug(message: string): void;
|
|
76
51
|
printError(message: string): void;
|
|
77
52
|
printWarn(message: string): void;
|
|
78
|
-
acquireRawConnection(): Promise<
|
|
53
|
+
acquireRawConnection(): Promise<void | odbc.Connection>;
|
|
79
54
|
destroyRawConnection(connection: any): Promise<any>;
|
|
80
55
|
_getConnectionString(connectionConfig: DB2ConnectionConfig): string;
|
|
81
56
|
_query(connection: Connection, obj: any): Promise<any>;
|
|
57
|
+
/**
|
|
58
|
+
* Execute UPDATE with returning clause using transaction + SELECT approach
|
|
59
|
+
* Since IBM i DB2 doesn't support FINAL TABLE with UPDATE, we:
|
|
60
|
+
* 1. Execute the UPDATE statement
|
|
61
|
+
* 2. Execute a SELECT to get the updated values using the same WHERE clause
|
|
62
|
+
*/
|
|
63
|
+
private executeUpdateReturning;
|
|
64
|
+
private executeSequentialInsert;
|
|
65
|
+
private executeDeleteReturning;
|
|
82
66
|
private normalizeQueryObject;
|
|
83
67
|
private determineQueryMethod;
|
|
84
68
|
private isSelectMethod;
|
|
85
69
|
private executeSelectQuery;
|
|
86
70
|
private executeStatementQuery;
|
|
71
|
+
private isNoDataError;
|
|
72
|
+
/**
|
|
73
|
+
* Format statement response from ODBC driver
|
|
74
|
+
* Handles special case for IDENTITY_VAL_LOCAL() function
|
|
75
|
+
*/
|
|
87
76
|
private formatStatementResponse;
|
|
88
77
|
_stream(connection: Connection, obj: {
|
|
89
78
|
sql: string;
|
|
@@ -91,14 +80,22 @@ declare class DB2Client extends knex.Client {
|
|
|
91
80
|
}, stream: any, options: {
|
|
92
81
|
fetchSize?: number;
|
|
93
82
|
}): Promise<unknown>;
|
|
83
|
+
private calculateOptimalFetchSize;
|
|
94
84
|
private _createCursorStream;
|
|
95
85
|
transaction(container: any, config: any, outerTx: any): Knex.Transaction;
|
|
96
|
-
schemaCompiler(tableBuilder: any):
|
|
97
|
-
tableCompiler(tableBuilder: any):
|
|
98
|
-
columnCompiler(tableCompiler: any, columnCompiler: any):
|
|
99
|
-
queryCompiler(builder: Knex.QueryBuilder, bindings?: any[]):
|
|
86
|
+
schemaCompiler(tableBuilder: any): any;
|
|
87
|
+
tableCompiler(tableBuilder: any): any;
|
|
88
|
+
columnCompiler(tableCompiler: any, columnCompiler: any): any;
|
|
89
|
+
queryCompiler(builder: Knex.QueryBuilder, bindings?: any[]): any;
|
|
90
|
+
createMigrationRunner(config?: Partial<IBMiMigrationConfig>): IBMiMigrationRunner;
|
|
100
91
|
processResponse(obj: QueryObject | null, runner: any): any;
|
|
101
92
|
private validateResponse;
|
|
93
|
+
private wrapError;
|
|
94
|
+
private shouldRetryQuery;
|
|
95
|
+
private retryQuery;
|
|
96
|
+
private isConnectionError;
|
|
97
|
+
private isTimeoutError;
|
|
98
|
+
private isSQLError;
|
|
102
99
|
private processSqlMethod;
|
|
103
100
|
}
|
|
104
101
|
interface DB2PoolConfig {
|
|
@@ -134,11 +131,12 @@ interface DB2ConnectionParams {
|
|
|
134
131
|
CONCURRENCY?: 0 | 1;
|
|
135
132
|
CURSORSENSITIVITY?: 0 | 1 | 2;
|
|
136
133
|
EXTCOLINFO?: "SQL_DESC_AUTO_UNIQUE_VALUE" | "SQL_DESC_BASE_COLUMN_NAME" | "SQL_DESC_BASE_TABLE_NAME and SQL_DESC_TABLE_NAME" | "SQL_DESC_LABEL" | "SQL_DESC_SCHEMA_NAME" | "SQL_DESC_SEARCHABLE" | "SQL_DESC_UNNAMED" | "SQL_DESC_UPDATABLE";
|
|
134
|
+
TRUEAUTOCOMMIT?: 0 | 1;
|
|
137
135
|
}
|
|
138
136
|
interface DB2ConnectionConfig {
|
|
139
137
|
database: string;
|
|
140
138
|
host: string;
|
|
141
|
-
port:
|
|
139
|
+
port: 8471 | 9471 | number;
|
|
142
140
|
user: string;
|
|
143
141
|
password: string;
|
|
144
142
|
driver: "IBM i Access ODBC Driver" | string;
|
|
@@ -148,7 +146,11 @@ interface DB2Config extends Knex.Config {
|
|
|
148
146
|
client: any;
|
|
149
147
|
connection: DB2ConnectionConfig;
|
|
150
148
|
pool?: DB2PoolConfig;
|
|
149
|
+
ibmi?: {
|
|
150
|
+
multiRowInsert?: "auto" | "sequential" | "disabled";
|
|
151
|
+
sequentialInsertTransactional?: boolean;
|
|
152
|
+
};
|
|
151
153
|
}
|
|
152
154
|
declare const DB2Dialect: typeof DB2Client;
|
|
153
155
|
|
|
154
|
-
export { type DB2Config, DB2Dialect, DB2Client as default };
|
|
156
|
+
export { type DB2Config, DB2Dialect, IBMiMigrationRunner, createIBMiMigrationRunner, DB2Client as default };
|