arkormx 2.0.0-next.23 → 2.0.0-next.24

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.cjs CHANGED
@@ -7593,12 +7593,14 @@ var QueryBuilder = class QueryBuilder {
7593
7593
  * @returns
7594
7594
  */
7595
7595
  async updateOrInsert(attributes, values = {}) {
7596
- if (typeof values !== "function" && this.adapter?.capabilities?.upsert && typeof this.requireAdapter().upsert === "function") {
7596
+ if (typeof values !== "function" && this.adapter?.capabilities?.upsert && typeof this.requireAdapter().upsert === "function") try {
7597
7597
  await this.executeUpsertRows([{
7598
7598
  ...attributes,
7599
7599
  ...values
7600
7600
  }], Object.keys(attributes), Object.keys(values));
7601
7601
  return true;
7602
+ } catch (error) {
7603
+ if (!this.shouldFallbackUpdateOrInsertUpsert(error)) throw error;
7602
7604
  }
7603
7605
  const exists = await this.clone().where(attributes).first() != null;
7604
7606
  const resolvedValues = typeof values === "function" ? await values(exists) : values;
@@ -7611,6 +7613,13 @@ var QueryBuilder = class QueryBuilder {
7611
7613
  }
7612
7614
  return await this.clone().where(attributes).update(resolvedValues) != null;
7613
7615
  }
7616
+ shouldFallbackUpdateOrInsertUpsert(error) {
7617
+ if (!(error instanceof QueryExecutionException)) return false;
7618
+ const cause = error.cause;
7619
+ const code = typeof cause?.code === "string" ? cause.code : void 0;
7620
+ const message = typeof cause?.message === "string" ? cause.message : error.message;
7621
+ return code === "42P10" || message.includes("there is no unique or exclusion constraint matching the ON CONFLICT specification");
7622
+ }
7614
7623
  /**
7615
7624
  * Insert new records or update existing records by one or more unique keys.
7616
7625
  *
package/dist/index.d.cts CHANGED
@@ -2687,6 +2687,7 @@ declare class QueryBuilder<TModel, TDelegate extends PrismaDelegateLike = Prisma
2687
2687
  * @returns
2688
2688
  */
2689
2689
  updateOrInsert(attributes: Record<string, unknown>, values?: Record<string, unknown> | ((exists: boolean) => Record<string, unknown> | Promise<Record<string, unknown>>)): Promise<boolean>;
2690
+ private shouldFallbackUpdateOrInsertUpsert;
2690
2691
  /**
2691
2692
  * Insert new records or update existing records by one or more unique keys.
2692
2693
  *
package/dist/index.d.mts CHANGED
@@ -2687,6 +2687,7 @@ declare class QueryBuilder<TModel, TDelegate extends PrismaDelegateLike = Prisma
2687
2687
  * @returns
2688
2688
  */
2689
2689
  updateOrInsert(attributes: Record<string, unknown>, values?: Record<string, unknown> | ((exists: boolean) => Record<string, unknown> | Promise<Record<string, unknown>>)): Promise<boolean>;
2690
+ private shouldFallbackUpdateOrInsertUpsert;
2690
2691
  /**
2691
2692
  * Insert new records or update existing records by one or more unique keys.
2692
2693
  *
package/dist/index.mjs CHANGED
@@ -7564,12 +7564,14 @@ var QueryBuilder = class QueryBuilder {
7564
7564
  * @returns
7565
7565
  */
7566
7566
  async updateOrInsert(attributes, values = {}) {
7567
- if (typeof values !== "function" && this.adapter?.capabilities?.upsert && typeof this.requireAdapter().upsert === "function") {
7567
+ if (typeof values !== "function" && this.adapter?.capabilities?.upsert && typeof this.requireAdapter().upsert === "function") try {
7568
7568
  await this.executeUpsertRows([{
7569
7569
  ...attributes,
7570
7570
  ...values
7571
7571
  }], Object.keys(attributes), Object.keys(values));
7572
7572
  return true;
7573
+ } catch (error) {
7574
+ if (!this.shouldFallbackUpdateOrInsertUpsert(error)) throw error;
7573
7575
  }
7574
7576
  const exists = await this.clone().where(attributes).first() != null;
7575
7577
  const resolvedValues = typeof values === "function" ? await values(exists) : values;
@@ -7582,6 +7584,13 @@ var QueryBuilder = class QueryBuilder {
7582
7584
  }
7583
7585
  return await this.clone().where(attributes).update(resolvedValues) != null;
7584
7586
  }
7587
+ shouldFallbackUpdateOrInsertUpsert(error) {
7588
+ if (!(error instanceof QueryExecutionException)) return false;
7589
+ const cause = error.cause;
7590
+ const code = typeof cause?.code === "string" ? cause.code : void 0;
7591
+ const message = typeof cause?.message === "string" ? cause.message : error.message;
7592
+ return code === "42P10" || message.includes("there is no unique or exclusion constraint matching the ON CONFLICT specification");
7593
+ }
7585
7594
  /**
7586
7595
  * Insert new records or update existing records by one or more unique keys.
7587
7596
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkormx",
3
- "version": "2.0.0-next.23",
3
+ "version": "2.0.0-next.24",
4
4
  "description": "Modern TypeScript-first ORM for Node.js.",
5
5
  "keywords": [
6
6
  "orm",