@zuzjs/orm 0.1.6 → 0.1.8
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/drivers/queryBuilder.d.ts +6 -2
- package/dist/drivers/queryBuilder.js +20 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/types.d.ts +2 -1
- package/dist/types.js +5 -5
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Repository, ObjectLiteral } from "typeorm";
|
|
2
|
-
import { QueryAction } from "../types";
|
|
3
1
|
import { QueryResult } from "mysql2";
|
|
2
|
+
import { ObjectLiteral, Repository } from "typeorm";
|
|
4
3
|
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
|
|
4
|
+
import { QueryAction } from "../types";
|
|
5
5
|
declare class ZormQueryBuilder<T extends ObjectLiteral, R = QueryResult> extends Promise<R> {
|
|
6
6
|
private repository;
|
|
7
7
|
private queryBuilder;
|
|
@@ -10,12 +10,16 @@ declare class ZormQueryBuilder<T extends ObjectLiteral, R = QueryResult> extends
|
|
|
10
10
|
private queryValues;
|
|
11
11
|
private usePromise;
|
|
12
12
|
private whereCount;
|
|
13
|
+
private isActiveRecord;
|
|
14
|
+
private activeRecord;
|
|
13
15
|
constructor(repository: Repository<T>, _action: QueryAction, _usePromise?: boolean);
|
|
14
16
|
_create(): this;
|
|
15
17
|
upsert(): this;
|
|
16
18
|
_update(): this;
|
|
17
19
|
_delete(): this;
|
|
18
20
|
_getRawQuery(): [string, any[]];
|
|
21
|
+
active(): this;
|
|
22
|
+
_saveActiveRecord(activeRecord: T): Promise<T | null>;
|
|
19
23
|
/**
|
|
20
24
|
* Sets the values for an insert or update query.
|
|
21
25
|
* @param data - The data to be inserted or updated.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_js_1 = require("./mysql/index.js");
|
|
4
3
|
const core_1 = require("../core");
|
|
4
|
+
const index_js_1 = require("./mysql/index.js");
|
|
5
5
|
class ZormQueryBuilder extends Promise {
|
|
6
6
|
repository;
|
|
7
7
|
queryBuilder;
|
|
@@ -10,6 +10,8 @@ class ZormQueryBuilder extends Promise {
|
|
|
10
10
|
queryValues = null;
|
|
11
11
|
usePromise;
|
|
12
12
|
whereCount = 0;
|
|
13
|
+
isActiveRecord = false;
|
|
14
|
+
activeRecord;
|
|
13
15
|
constructor(repository, _action, _usePromise) {
|
|
14
16
|
super(() => { }); // Required for extending Promise
|
|
15
17
|
this.repository = repository;
|
|
@@ -17,6 +19,7 @@ class ZormQueryBuilder extends Promise {
|
|
|
17
19
|
this.queryBuilder = repository.createQueryBuilder(this.entityAlias);
|
|
18
20
|
this.action = _action;
|
|
19
21
|
this.usePromise = _usePromise || false;
|
|
22
|
+
this.activeRecord = null;
|
|
20
23
|
}
|
|
21
24
|
_create() {
|
|
22
25
|
if (this.queryValues) {
|
|
@@ -68,6 +71,15 @@ class ZormQueryBuilder extends Promise {
|
|
|
68
71
|
_getRawQuery() {
|
|
69
72
|
return this.queryBuilder.getQueryAndParameters();
|
|
70
73
|
}
|
|
74
|
+
active() {
|
|
75
|
+
this.isActiveRecord = true;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
async _saveActiveRecord(activeRecord) {
|
|
79
|
+
// if (!this.activeRecord) throw new Error("No active record found. Use `findOne` first.");
|
|
80
|
+
return this.repository.save(activeRecord);
|
|
81
|
+
// return this
|
|
82
|
+
}
|
|
71
83
|
/**
|
|
72
84
|
* Sets the values for an insert or update query.
|
|
73
85
|
* @param data - The data to be inserted or updated.
|
|
@@ -229,6 +241,7 @@ class ZormQueryBuilder extends Promise {
|
|
|
229
241
|
*/
|
|
230
242
|
in(field, values) {
|
|
231
243
|
this.queryBuilder.andWhere(`${this.entityAlias}.${String(field)} IN (:...values)`, { values });
|
|
244
|
+
this.whereCount++;
|
|
232
245
|
return this;
|
|
233
246
|
}
|
|
234
247
|
/**
|
|
@@ -315,12 +328,16 @@ class ZormQueryBuilder extends Promise {
|
|
|
315
328
|
case "select":
|
|
316
329
|
default:
|
|
317
330
|
const _select = await this.queryBuilder.getMany();
|
|
318
|
-
|
|
331
|
+
const _result = {
|
|
319
332
|
hasRows: _select.length > 0,
|
|
320
333
|
count: _select.length,
|
|
321
334
|
row: _select.length > 0 ? _select[0] : null,
|
|
322
|
-
rows: _select.length > 1 ? _select : []
|
|
335
|
+
rows: _select.length > 1 ? _select : [],
|
|
323
336
|
};
|
|
337
|
+
if (this.isActiveRecord) {
|
|
338
|
+
_result.save = () => this._saveActiveRecord(_select[0]);
|
|
339
|
+
}
|
|
340
|
+
return _result;
|
|
324
341
|
}
|
|
325
342
|
}
|
|
326
343
|
catch (err) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
1
2
|
import { EntitySchema, EntityTarget, MixedList, ObjectLiteral, Repository } from "typeorm";
|
|
2
3
|
import ZormQueryBuilder from "./drivers/queryBuilder.js";
|
|
3
4
|
import { DeleteQueryResult, InsertQueryResult, SelectQueryResult, UpdateQueryResult } from "./types.js";
|
|
4
|
-
import "reflect-metadata";
|
|
5
5
|
/**
|
|
6
6
|
* Zorm is a lightweight ORM wrapper around TypeORM with support for MySQL.
|
|
7
7
|
*/
|
package/dist/index.js
CHANGED
|
@@ -18,12 +18,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
const path_1 = __importDefault(require("path"));
|
|
21
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
22
|
+
require("reflect-metadata");
|
|
21
23
|
const typeorm_1 = require("typeorm");
|
|
22
24
|
const index_js_1 = require("./core/index.js");
|
|
23
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
24
25
|
const index_js_2 = require("./drivers/mysql/index.js");
|
|
25
26
|
const queryBuilder_js_1 = __importDefault(require("./drivers/queryBuilder.js"));
|
|
26
|
-
require("reflect-metadata");
|
|
27
27
|
/**
|
|
28
28
|
* Zorm is a lightweight ORM wrapper around TypeORM with support for MySQL.
|
|
29
29
|
*/
|
package/dist/types.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export type SelectQueryResult = {
|
|
|
36
36
|
row?: any;
|
|
37
37
|
rows?: any[];
|
|
38
38
|
error?: QueryError;
|
|
39
|
+
save?: () => void;
|
|
39
40
|
};
|
|
40
41
|
export type UpdateQueryResult = {
|
|
41
42
|
updated: boolean;
|
|
@@ -48,4 +49,4 @@ export type DeleteQueryResult = {
|
|
|
48
49
|
count: number;
|
|
49
50
|
error?: QueryError;
|
|
50
51
|
};
|
|
51
|
-
export {
|
|
52
|
+
export { BaseEntity, Column, Entity, JoinColumn, OneToOne, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm";
|
package/dist/types.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PrimaryGeneratedColumn = exports.PrimaryColumn = exports.OneToOne = exports.JoinColumn = exports.Entity = exports.Column = exports.BaseEntity = void 0;
|
|
4
4
|
var typeorm_1 = require("typeorm");
|
|
5
|
+
Object.defineProperty(exports, "BaseEntity", { enumerable: true, get: function () { return typeorm_1.BaseEntity; } });
|
|
6
|
+
Object.defineProperty(exports, "Column", { enumerable: true, get: function () { return typeorm_1.Column; } });
|
|
5
7
|
Object.defineProperty(exports, "Entity", { enumerable: true, get: function () { return typeorm_1.Entity; } });
|
|
8
|
+
Object.defineProperty(exports, "JoinColumn", { enumerable: true, get: function () { return typeorm_1.JoinColumn; } });
|
|
9
|
+
Object.defineProperty(exports, "OneToOne", { enumerable: true, get: function () { return typeorm_1.OneToOne; } });
|
|
6
10
|
Object.defineProperty(exports, "PrimaryColumn", { enumerable: true, get: function () { return typeorm_1.PrimaryColumn; } });
|
|
7
11
|
Object.defineProperty(exports, "PrimaryGeneratedColumn", { enumerable: true, get: function () { return typeorm_1.PrimaryGeneratedColumn; } });
|
|
8
|
-
Object.defineProperty(exports, "Column", { enumerable: true, get: function () { return typeorm_1.Column; } });
|
|
9
|
-
Object.defineProperty(exports, "BaseEntity", { enumerable: true, get: function () { return typeorm_1.BaseEntity; } });
|
|
10
|
-
Object.defineProperty(exports, "OneToOne", { enumerable: true, get: function () { return typeorm_1.OneToOne; } });
|
|
11
|
-
Object.defineProperty(exports, "JoinColumn", { enumerable: true, get: function () { return typeorm_1.JoinColumn; } });
|