@bdkinc/knex-ibmi 0.3.21 → 0.4.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/dist/index.d.ts CHANGED
@@ -1,76 +1,87 @@
1
- import { knex, Knex } from 'knex';
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
- declare class IBMiSchemaCompiler extends SchemaCompiler {
9
- hasTable(tableName: any): void;
10
- toSQL(): any[];
4
+ interface IBMiMigrationConfig {
5
+ directory: string;
6
+ tableName: string;
7
+ schemaName?: string;
8
+ extension?: string;
11
9
  }
12
-
13
- declare class IBMiTableCompiler extends TableCompiler {
14
- createQuery(columns: {
15
- sql: any[];
16
- }, ifNot: any, like: any): void;
17
- dropUnique(columns: string[], indexName: any): void;
18
- unique(columns: string[], indexName: {
19
- indexName: any;
20
- deferrable: any;
21
- predicate: any;
22
- }): void;
23
- addColumns(columns: any, prefix: any): void;
24
- commit(connection: Connection): Promise<void>;
25
- }
26
-
27
- declare class IBMiColumnCompiler extends ColumnCompiler {
28
- increments(options?: {
29
- primaryKey: boolean;
30
- }): 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;
31
22
  }
23
+ declare function createIBMiMigrationRunner(knex: Knex, config?: Partial<IBMiMigrationConfig>): IBMiMigrationRunner;
32
24
 
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;
25
+ interface QueryObject {
26
+ response?: {
27
+ rows: any[];
28
+ rowCount: number;
42
29
  };
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;
30
+ sqlMethod: SqlMethod;
31
+ output?: (runner: any, response: any) => any;
32
+ pluck?: (row: any) => any;
33
+ select?: boolean;
34
+ }
35
+ declare enum SqlMethod {
36
+ SELECT = "select",
37
+ PLUCK = "pluck",
38
+ FIRST = "first",
39
+ INSERT = "insert",
40
+ DELETE = "del",
41
+ DELETE_ALT = "delete",
42
+ UPDATE = "update",
43
+ COUNTER = "counter"
49
44
  }
50
-
51
45
  declare class DB2Client extends knex.Client {
52
46
  constructor(config: Knex.Config<DB2Config>);
47
+ private safeStringify;
53
48
  _driver(): typeof odbc;
54
- wrapIdentifierImpl(value: any): any;
49
+ wrapIdentifierImpl(value: string): string;
55
50
  printDebug(message: string): void;
56
51
  printError(message: string): void;
57
52
  printWarn(message: string): void;
58
- acquireRawConnection(): Promise<any>;
53
+ acquireRawConnection(): Promise<void | odbc.Connection>;
59
54
  destroyRawConnection(connection: any): Promise<any>;
60
55
  _getConnectionString(connectionConfig: DB2ConnectionConfig): string;
61
- _query(connection: any, obj: any): Promise<any>;
56
+ _query(connection: Connection, obj: any): Promise<any>;
57
+ private normalizeQueryObject;
58
+ private determineQueryMethod;
59
+ private isSelectMethod;
60
+ private executeSelectQuery;
61
+ private executeStatementQuery;
62
+ private isNoDataError;
63
+ /**
64
+ * Format statement response from ODBC driver
65
+ * Handles special case for IDENTITY_VAL_LOCAL() function
66
+ */
67
+ private formatStatementResponse;
62
68
  _stream(connection: Connection, obj: {
63
69
  sql: string;
64
70
  bindings: any[];
65
71
  }, stream: any, options: {
66
72
  fetchSize?: number;
67
73
  }): Promise<unknown>;
74
+ private _createCursorStream;
68
75
  transaction(container: any, config: any, outerTx: any): Knex.Transaction;
69
- schemaCompiler(tableBuilder: any): IBMiSchemaCompiler;
70
- tableCompiler(tableBuilder: any): IBMiTableCompiler;
71
- columnCompiler(tableCompiler: any, columnCompiler: any): IBMiColumnCompiler;
72
- queryCompiler(builder: Knex.QueryBuilder, bindings?: any[]): IBMiQueryCompiler;
73
- processResponse(obj: any, runner: any): any;
76
+ schemaCompiler(tableBuilder: any): any;
77
+ tableCompiler(tableBuilder: any): any;
78
+ columnCompiler(tableCompiler: any, columnCompiler: any): any;
79
+ queryCompiler(builder: Knex.QueryBuilder, bindings?: any[]): any;
80
+ createMigrationRunner(config?: Partial<IBMiMigrationConfig>): IBMiMigrationRunner;
81
+ processResponse(obj: QueryObject | null, runner: any): any;
82
+ private validateResponse;
83
+ private isConnectionError;
84
+ private processSqlMethod;
74
85
  }
75
86
  interface DB2PoolConfig {
76
87
  min?: number;
@@ -91,13 +102,26 @@ interface DB2ConnectionParams {
91
102
  DECFLOATERROROPTION?: 0 | 1;
92
103
  DECFLOATROUNDMODE?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
93
104
  MAPDECIMALFLOATDESCRIBE?: 1 | 3;
105
+ TFT?: 0 | 1 | 2 | 3 | 4;
106
+ TSP?: 0 | 1 | 2 | 3;
107
+ TSFT?: 0 | 1;
108
+ XMLCURIMPPARSE?: 0 | 1;
109
+ XMLDECLARATION?: 1 | 2 | 3 | 4;
94
110
  ALLOWPROCCALLS?: 0 | 1;
95
111
  XDYNAMIC?: 0 | 1;
112
+ DFTPKGLIB?: string;
113
+ PKG?: 0 | 1 | 2;
114
+ BLOCKFETCH?: 0 | 1;
115
+ COMPRESSION?: 0 | 1;
116
+ CONCURRENCY?: 0 | 1;
117
+ CURSORSENSITIVITY?: 0 | 1 | 2;
118
+ 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";
119
+ TRUEAUTOCOMMIT?: 0 | 1;
96
120
  }
97
121
  interface DB2ConnectionConfig {
98
122
  database: string;
99
123
  host: string;
100
- port: 50000 | number;
124
+ port: 8471 | 9471 | number;
101
125
  user: string;
102
126
  password: string;
103
127
  driver: "IBM i Access ODBC Driver" | string;
@@ -110,4 +134,4 @@ interface DB2Config extends Knex.Config {
110
134
  }
111
135
  declare const DB2Dialect: typeof DB2Client;
112
136
 
113
- export { type DB2Config, DB2Dialect, DB2Client as default };
137
+ export { type DB2Config, DB2Dialect, IBMiMigrationRunner, createIBMiMigrationRunner, DB2Client as default };