@bdkinc/knex-ibmi 0.2.5 → 0.2.7

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 CHANGED
@@ -37,6 +37,8 @@ Requires Node v16 or higher.
37
37
 
38
38
  This library can be used as commonjs, esm or TypeScript.
39
39
 
40
+ ### CommonJs
41
+
40
42
  ```javascript
41
43
  const knex = require("knex");
42
44
  const { DB2Dialect } = require("@bdkinc/knex-ibmi");
@@ -70,13 +72,16 @@ query
70
72
  .finally(() => process.exit());
71
73
  ```
72
74
 
73
- or as ESM
75
+ ### ESM
74
76
 
75
77
  ```javascript
76
78
  import knex from "knex";
77
79
  import { DB2Dialect } from "@bdkinc/knex-ibmi";
78
80
 
79
- const db = knex({
81
+ /**
82
+ * @type {import("@bdkinc/knex-ibmi").DB2Config}
83
+ */
84
+ const config = {
80
85
  client: DB2Dialect,
81
86
  connection: {
82
87
  host: "localhost", // hostname or ip address of server
@@ -95,7 +100,9 @@ const db = knex({
95
100
  min: 2,
96
101
  max: 10,
97
102
  },
98
- });
103
+ }
104
+
105
+ const db = knex(config);
99
106
 
100
107
  try {
101
108
  const data = await db.select("*").from("table").where({ foo: "bar" });
@@ -107,7 +114,7 @@ try {
107
114
  }
108
115
  ```
109
116
 
110
- or as Typescript
117
+ ### TypeScript
111
118
 
112
119
  ```typescript
113
120
  import { knex } from "knex";
package/dist/index.d.ts CHANGED
@@ -36,7 +36,10 @@ declare class IBMiQueryCompiler extends QueryCompiler {
36
36
  returning: any;
37
37
  };
38
38
  _buildInsertData(insertValues: string | any[], returningSql: string): string;
39
- _prepInsert(data: any): any;
39
+ _prepInsert(data: any): {
40
+ columns: any;
41
+ values: any;
42
+ };
40
43
  update(): {
41
44
  sql: string;
42
45
  returning: any;
@@ -60,7 +63,7 @@ declare class DB2Client extends knex.Client {
60
63
  schemaCompiler(tableBuilder: any): IBMiSchemaCompiler;
61
64
  tableCompiler(tableBuilder: any): IBMiTableCompiler;
62
65
  columnCompiler(tableCompiler: any, columnCompiler: any): IBMiColumnCompiler;
63
- queryCompiler(builder: Knex.QueryBuilder): IBMiQueryCompiler;
66
+ queryCompiler(builder: Knex.QueryBuilder, bindings?: any[]): IBMiQueryCompiler;
64
67
  processResponse(obj: any, runner: any): any;
65
68
  }
66
69
  interface DB2PoolConfig {
package/dist/index.js CHANGED
@@ -4,6 +4,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
7
10
  var __export = (target, all) => {
8
11
  for (var name in all)
9
12
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -26,6 +29,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
29
  ));
27
30
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
31
 
32
+ // node_modules/lodash/isObject.js
33
+ var require_isObject = __commonJS({
34
+ "node_modules/lodash/isObject.js"(exports2, module2) {
35
+ function isObject2(value) {
36
+ var type = typeof value;
37
+ return value != null && (type == "object" || type == "function");
38
+ }
39
+ module2.exports = isObject2;
40
+ }
41
+ });
42
+
29
43
  // src/index.ts
30
44
  var src_exports = {};
31
45
  __export(src_exports, {
@@ -76,7 +90,7 @@ var ibmi_compiler_default = IBMiSchemaCompiler;
76
90
 
77
91
  // src/schema/ibmi-tablecompiler.ts
78
92
  var import_tablecompiler = __toESM(require("knex/lib/schema/tablecompiler"));
79
- var import_isObject = __toESM(require("lodash/isObject"));
93
+ var import_isObject = __toESM(require_isObject());
80
94
  var IBMiTableCompiler = class extends import_tablecompiler.default {
81
95
  createQuery(columns, ifNot, like) {
82
96
  let createStatement = ifNot ? `if object_id('${this.tableName()}', 'U') is null ` : "";
@@ -165,10 +179,8 @@ var ibmi_transaction_default = IBMiTransaction;
165
179
 
166
180
  // src/query/ibmi-querycompiler.ts
167
181
  var import_querycompiler = __toESM(require("knex/lib/query/querycompiler"));
168
- var import_isObject2 = __toESM(require("lodash/isObject"));
169
182
  var import_wrappingFormatter = require("knex/lib/formatter/wrappingFormatter");
170
183
  var import_date_fns = require("date-fns");
171
- var import_isEmpty = __toESM(require("lodash/isEmpty"));
172
184
  var IBMiQueryCompiler = class extends import_querycompiler.default {
173
185
  insert() {
174
186
  const insertValues = this.single.insert || [];
@@ -180,7 +192,7 @@ var IBMiQueryCompiler = class extends import_querycompiler.default {
180
192
  if (insertValues.length === 0) {
181
193
  return "";
182
194
  }
183
- } else if (typeof insertValues === "object" && (0, import_isEmpty.default)(insertValues)) {
195
+ } else if (typeof insertValues === "object" && Object.keys(insertValues).length === 0) {
184
196
  return {
185
197
  sql: sql + returningSql + this._emptyInsertValue,
186
198
  returning
@@ -211,11 +223,9 @@ var IBMiQueryCompiler = class extends import_querycompiler.default {
211
223
  return sql;
212
224
  }
213
225
  _prepInsert(data) {
214
- if ((0, import_isObject2.default)(data)) {
215
- if (data.hasOwnProperty("migration_time")) {
216
- const parsed = new Date(data.migration_time);
217
- data.migration_time = (0, import_date_fns.format)(parsed, "yyyy-MM-dd HH:mm:ss");
218
- }
226
+ if (typeof data === "object" && data.migration_time) {
227
+ const parsed = new Date(data.migration_time);
228
+ data.migration_time = (0, import_date_fns.format)(parsed, "yyyy-MM-dd HH:mm:ss");
219
229
  }
220
230
  const isRaw = (0, import_wrappingFormatter.rawOrFn)(
221
231
  data,
@@ -321,6 +331,9 @@ var DB2Client = class extends import_knex.knex.Client {
321
331
  `knex: Required configuration option 'client' is missing.`
322
332
  );
323
333
  }
334
+ if (config.version) {
335
+ this.version = config.version;
336
+ }
324
337
  if (this.driverName && config.connection) {
325
338
  this.initializeDriver();
326
339
  if (!config.pool || config.pool && config.pool.max !== 0) {
@@ -428,19 +441,6 @@ var DB2Client = class extends import_knex.knex.Client {
428
441
  ),
429
442
  rowCount: result.count
430
443
  };
431
- } else if (method === "update") {
432
- if (obj.selectReturning) {
433
- const returningSelect = await connection.query(obj.selectReturning);
434
- obj.response = {
435
- rows: returningSelect,
436
- rowCount: result.count
437
- };
438
- } else {
439
- obj.response = {
440
- rows: result,
441
- rowCount: result.count
442
- };
443
- }
444
444
  } else {
445
445
  obj.response = { rows: result, rowCount: result.count };
446
446
  }
@@ -463,8 +463,8 @@ var DB2Client = class extends import_knex.knex.Client {
463
463
  columnCompiler(tableCompiler, columnCompiler) {
464
464
  return new ibmi_columncompiler_default(this, tableCompiler, columnCompiler);
465
465
  }
466
- queryCompiler(builder) {
467
- return new ibmi_querycompiler_default(this, builder);
466
+ queryCompiler(builder, bindings) {
467
+ return new ibmi_querycompiler_default(this, builder, bindings);
468
468
  }
469
469
  processResponse(obj, runner) {
470
470
  if (obj === null) return null;
@@ -487,7 +487,7 @@ var DB2Client = class extends import_knex.knex.Client {
487
487
  case "del":
488
488
  case "delete":
489
489
  case "update":
490
- if (obj.selectReturning) {
490
+ if (obj.select) {
491
491
  return rows;
492
492
  }
493
493
  return rowCount;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bdkinc/knex-ibmi",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Knex dialect for IBMi",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -56,7 +56,6 @@
56
56
  "dependencies": {
57
57
  "date-fns": "^3.6.0",
58
58
  "knex": "^3",
59
- "lodash": "^4.17.21",
60
59
  "odbc": "^2.4.8"
61
60
  }
62
61
  }