@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.
package/dist/SqlBuilder.d.ts
CHANGED
package/dist/SqlBuilder.js
CHANGED
|
@@ -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
|
-
*
|
|
92
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
134
|
-
*
|
|
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
|
|
137
|
-
|
|
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.
|
|
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": "
|
|
58
|
+
"gitHead": "8df23352a8be4a868d1ce60e6309cb062066267b"
|
|
59
59
|
}
|