@cheetah.js/orm 0.1.73 → 0.1.74

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.
@@ -23,6 +23,7 @@ export declare class SqlBuilder<T> {
23
23
  update(values: Partial<{
24
24
  [K in keyof T]: ValueOrInstance<T[K]>;
25
25
  }>): SqlBuilder<T>;
26
+ delete(): SqlBuilder<T>;
26
27
  where(where: FilterQuery<T>): SqlBuilder<T>;
27
28
  orderBy(orderBy: (QueryOrderMap<T> & {
28
29
  0?: never;
@@ -67,6 +67,13 @@ class SqlBuilder {
67
67
  this.statements.instance = value_processor_1.ValueProcessor.createInstance(processedValues, this.model, 'update');
68
68
  return this;
69
69
  }
70
+ delete() {
71
+ const { tableName, schema } = this.getTableName();
72
+ this.statements.statement = 'delete';
73
+ this.statements.alias = this.getAlias(tableName);
74
+ this.statements.table = `${schema}.${tableName}`;
75
+ return this;
76
+ }
70
77
  where(where) {
71
78
  if (!where || Object.keys(where).length === 0) {
72
79
  return this;
@@ -43,6 +43,7 @@ export declare abstract class BunDriverBase implements Partial<DriverInterface>
43
43
  protected buildBaseSql(statement: Statement<any>): string;
44
44
  protected buildInsertSql(table: string, values: any, columns: string[] | undefined, alias: string): string;
45
45
  protected buildUpdateSql(table: string, values: any, alias: string): string;
46
+ protected buildDeleteSql(table: string, alias: string): string;
46
47
  protected buildJoinClause(statement: Statement<any>): string;
47
48
  protected buildWhereAndOrderClauses(statement: Statement<any>): string;
48
49
  protected buildLimitAndOffsetClause(statement: Statement<any>): string;
@@ -145,6 +145,8 @@ class BunDriverBase {
145
145
  return this.buildInsertSql(table, values, columns, alias);
146
146
  case 'update':
147
147
  return this.buildUpdateSql(table, values, alias);
148
+ case 'delete':
149
+ return this.buildDeleteSql(table, alias);
148
150
  case 'count':
149
151
  return `SELECT COUNT(*) as count FROM ${table} ${alias}`;
150
152
  default:
@@ -167,6 +169,9 @@ class BunDriverBase {
167
169
  .join(', ');
168
170
  return `UPDATE ${table} as ${alias} SET ${sets}`;
169
171
  }
172
+ buildDeleteSql(table, alias) {
173
+ return `DELETE FROM ${table} AS ${alias}`;
174
+ }
170
175
  buildJoinClause(statement) {
171
176
  if (!statement.join)
172
177
  return '';
@@ -88,10 +88,18 @@ export declare abstract class Repository<T extends BaseEntity> {
88
88
  [K in keyof T]: ValueOrInstance<T[K]>;
89
89
  }>): Promise<void>;
90
90
  /**
91
- * Finds entities for deletion (use with caution).
92
- * To delete, call .remove() on returned entities or use SQL directly.
91
+ * Deletes entities matching the criteria.
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * await repository.delete({ isActive: false });
96
+ * ```
97
+ */
98
+ delete(where: FilterQuery<T>): Promise<void>;
99
+ /**
100
+ * Deletes an entity by its primary key.
93
101
  */
94
- findForDeletion(where: FilterQuery<T>): Promise<T[]>;
102
+ deleteById(id: number | string): Promise<void>;
95
103
  /**
96
104
  * Counts entities matching the criteria.
97
105
  */
@@ -130,11 +130,24 @@ class Repository {
130
130
  await this.update({ id }, data);
131
131
  }
132
132
  /**
133
- * Finds entities for deletion (use with caution).
134
- * To delete, call .remove() on returned entities or use SQL directly.
133
+ * Deletes entities matching the criteria.
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * await repository.delete({ isActive: false });
138
+ * ```
139
+ */
140
+ async delete(where) {
141
+ await this.createQueryBuilder()
142
+ .delete()
143
+ .where(where)
144
+ .execute();
145
+ }
146
+ /**
147
+ * Deletes an entity by its primary key.
135
148
  */
136
- async findForDeletion(where) {
137
- return this.find({ where });
149
+ async deleteById(id) {
150
+ await this.delete({ id });
138
151
  }
139
152
  /**
140
153
  * Counts entities matching the criteria.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cheetah.js/orm",
3
- "version": "0.1.73",
3
+ "version": "0.1.74",
4
4
  "description": "A simple ORM for Cheetah.js",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -55,5 +55,5 @@
55
55
  "bun",
56
56
  "value-object"
57
57
  ],
58
- "gitHead": "43be7716d957377ee1559f3c835e5e5dda46523a"
58
+ "gitHead": "8df23352a8be4a868d1ce60e6309cb062066267b"
59
59
  }