delete.cjs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var delete_exports = {};
  20. __export(delete_exports, {
  21. GelDeleteBase: () => GelDeleteBase
  22. });
  23. module.exports = __toCommonJS(delete_exports);
  24. var import_entity = require("../../entity.cjs");
  25. var import_query_promise = require("../../query-promise.cjs");
  26. var import_table = require("../../table.cjs");
  27. var import_tracing = require("../../tracing.cjs");
  28. var import_utils = require("../../utils.cjs");
  29. var import_utils2 = require("../utils.cjs");
  30. class GelDeleteBase extends import_query_promise.QueryPromise {
  31. constructor(table, session, dialect, withList) {
  32. super();
  33. this.session = session;
  34. this.dialect = dialect;
  35. this.config = { table, withList };
  36. }
  37. static [import_entity.entityKind] = "GelDelete";
  38. config;
  39. /**
  40. * Adds a `where` clause to the query.
  41. *
  42. * Calling this method will delete only those rows that fulfill a specified condition.
  43. *
  44. * See docs: {@link https://orm.drizzle.team/docs/delete}
  45. *
  46. * @param where the `where` clause.
  47. *
  48. * @example
  49. * You can use conditional operators and `sql function` to filter the rows to be deleted.
  50. *
  51. * ```ts
  52. * // Delete all cars with green color
  53. * await db.delete(cars).where(eq(cars.color, 'green'));
  54. * // or
  55. * await db.delete(cars).where(sql`${cars.color} = 'green'`)
  56. * ```
  57. *
  58. * You can logically combine conditional operators with `and()` and `or()` operators:
  59. *
  60. * ```ts
  61. * // Delete all BMW cars with a green color
  62. * await db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
  63. *
  64. * // Delete all cars with the green or blue color
  65. * await db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
  66. * ```
  67. */
  68. where(where) {
  69. this.config.where = where;
  70. return this;
  71. }
  72. returning(fields = this.config.table[import_table.Table.Symbol.Columns]) {
  73. this.config.returning = (0, import_utils.orderSelectedFields)(fields);
  74. return this;
  75. }
  76. /** @internal */
  77. getSQL() {
  78. return this.dialect.buildDeleteQuery(this.config);
  79. }
  80. toSQL() {
  81. const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
  82. return rest;
  83. }
  84. /** @internal */
  85. _prepare(name) {
  86. return import_tracing.tracer.startActiveSpan("drizzle.prepareQuery", () => {
  87. return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name, true, void 0, {
  88. type: "delete",
  89. tables: (0, import_utils2.extractUsedTable)(this.config.table)
  90. });
  91. });
  92. }
  93. prepare(name) {
  94. return this._prepare(name);
  95. }
  96. execute = (placeholderValues) => {
  97. return import_tracing.tracer.startActiveSpan("drizzle.operation", () => {
  98. return this._prepare().execute(placeholderValues);
  99. });
  100. };
  101. $dynamic() {
  102. return this;
  103. }
  104. }
  105. // Annotate the CommonJS export names for ESM import in node:
  106. 0 && (module.exports = {
  107. GelDeleteBase
  108. });
  109. //# sourceMappingURL=delete.cjs.map