sonamu 0.2.42 → 0.2.44

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.
@@ -4215,44 +4215,6 @@ var DB = new DBClass();
4215
4215
  // src/database/base-model.ts
4216
4216
  import { DateTime } from "luxon";
4217
4217
  import _9 from "lodash";
4218
-
4219
- // src/database/knex-plugins/knex-on-duplicate-update.ts
4220
- import knex2 from "knex";
4221
- function attachOnDuplicateUpdate() {
4222
- knex2.QueryBuilder.extend("onDuplicateUpdate", function(...columns) {
4223
- if (columns.length === 0) {
4224
- const { sql: originalSQL2, bindings: originalBindings2 } = this.toSQL();
4225
- return this.client.raw(originalSQL2, originalBindings2);
4226
- }
4227
- const { placeholders, bindings } = columns.reduce(
4228
- (result, column) => {
4229
- if (typeof column === "string") {
4230
- result.placeholders.push(`?? = Values(??)`);
4231
- result.bindings.push(column, column);
4232
- } else if (column && typeof column === "object") {
4233
- Object.keys(column).forEach((key) => {
4234
- result.placeholders.push(`?? = ?`);
4235
- result.bindings.push(key, column[key]);
4236
- });
4237
- } else {
4238
- throw new Error(
4239
- "onDuplicateUpdate error: expected column name to be string or object."
4240
- );
4241
- }
4242
- return result;
4243
- },
4244
- { placeholders: [], bindings: [] }
4245
- );
4246
- const { sql: originalSQL, bindings: originalBindings } = this.toSQL();
4247
- const newBindings = [...originalBindings, ...bindings];
4248
- return this.client.raw(
4249
- `${originalSQL} ON DUPLICATE KEY UPDATE ${placeholders.join(", ")}`,
4250
- newBindings
4251
- );
4252
- });
4253
- }
4254
-
4255
- // src/database/base-model.ts
4256
4218
  import inflection8 from "inflection";
4257
4219
  import chalk2 from "chalk";
4258
4220
 
@@ -4545,7 +4507,6 @@ function getTableNamesFromWhere(ast) {
4545
4507
  }
4546
4508
 
4547
4509
  // src/database/base-model.ts
4548
- _9.once(() => attachOnDuplicateUpdate());
4549
4510
  var BaseModelClass = class {
4550
4511
  constructor() {
4551
4512
  this.modelName = "Unknown";
@@ -4795,6 +4756,48 @@ var BaseModel = new BaseModelClass();
4795
4756
  // src/api/sonamu.ts
4796
4757
  import path4 from "path";
4797
4758
  import fs3 from "fs-extra";
4759
+
4760
+ // src/database/knex-plugins/knex-on-duplicate-update.ts
4761
+ import knex2 from "knex";
4762
+ function attachOnDuplicateUpdate() {
4763
+ try {
4764
+ knex2.QueryBuilder.extend("onDuplicateUpdate", function(...columns) {
4765
+ if (columns.length === 0) {
4766
+ const { sql: originalSQL2, bindings: originalBindings2 } = this.toSQL();
4767
+ return this.client.raw(originalSQL2, originalBindings2);
4768
+ }
4769
+ const { placeholders, bindings } = columns.reduce(
4770
+ (result, column) => {
4771
+ if (typeof column === "string") {
4772
+ result.placeholders.push(`?? = Values(??)`);
4773
+ result.bindings.push(column, column);
4774
+ } else if (column && typeof column === "object") {
4775
+ Object.keys(column).forEach((key) => {
4776
+ result.placeholders.push(`?? = ?`);
4777
+ result.bindings.push(key, column[key]);
4778
+ });
4779
+ } else {
4780
+ throw new Error(
4781
+ "onDuplicateUpdate error: expected column name to be string or object."
4782
+ );
4783
+ }
4784
+ return result;
4785
+ },
4786
+ { placeholders: [], bindings: [] }
4787
+ );
4788
+ const { sql: originalSQL, bindings: originalBindings } = this.toSQL();
4789
+ const newBindings = [...originalBindings, ...bindings];
4790
+ return this.client.raw(
4791
+ `${originalSQL} ON DUPLICATE KEY UPDATE ${placeholders.join(", ")}`,
4792
+ newBindings
4793
+ );
4794
+ });
4795
+ } catch {
4796
+ console.log("already attached");
4797
+ }
4798
+ }
4799
+
4800
+ // src/api/sonamu.ts
4798
4801
  var SonamuClass = class {
4799
4802
  constructor() {
4800
4803
  this.isInitialized = false;
@@ -4857,6 +4860,7 @@ var SonamuClass = class {
4857
4860
  );
4858
4861
  this.dbConfig = await DB.readKnexfile();
4859
4862
  !doSilent && console.log(chalk3.green("DB Config Loaded!"));
4863
+ attachOnDuplicateUpdate();
4860
4864
  await EntityManager.autoload(doSilent);
4861
4865
  this.syncer = new Syncer();
4862
4866
  await this.syncer.autoloadModels();
@@ -7440,4 +7444,4 @@ export {
7440
7444
  FixtureManagerClass,
7441
7445
  FixtureManager
7442
7446
  };
7443
- //# sourceMappingURL=chunk-34NT3NGL.mjs.map
7447
+ //# sourceMappingURL=chunk-FOD6BJQJ.mjs.map