@trafficgroup/knex-rel 0.0.6 → 0.0.7

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.
@@ -2,6 +2,7 @@ import { IBaseDAO, IDataPaginator } from "../../d.types";
2
2
  import { IUser } from "../../interfaces/user/user.interfaces";
3
3
  export declare class UserDAO implements IBaseDAO<IUser> {
4
4
  private _knex;
5
+ private readonly table;
5
6
  create(item: IUser): Promise<IUser>;
6
7
  getById(id: number): Promise<IUser | null>;
7
8
  getByUuid(uuid: string): Promise<IUser | null>;
@@ -17,43 +17,44 @@ const KnexConnection_1 = __importDefault(require("../../KnexConnection"));
17
17
  class UserDAO {
18
18
  constructor() {
19
19
  this._knex = KnexConnection_1.default.getConnection();
20
+ this.table = '"user"';
20
21
  }
21
22
  create(item) {
22
23
  return __awaiter(this, void 0, void 0, function* () {
23
- const [createdUser] = yield this._knex("user").insert(item).returning("*");
24
+ const [createdUser] = yield this._knex(this.table).insert(item).returning("*");
24
25
  return createdUser;
25
26
  });
26
27
  }
27
28
  getById(id) {
28
29
  return __awaiter(this, void 0, void 0, function* () {
29
- const user = yield this._knex("user").where({ id }).first();
30
+ const user = yield this._knex(this.table).where({ id }).first();
30
31
  return user || null;
31
32
  });
32
33
  }
33
34
  getByUuid(uuid) {
34
35
  return __awaiter(this, void 0, void 0, function* () {
35
- const user = yield this._knex("user").where({ uuid }).first();
36
+ const user = yield this._knex(this.table).where({ uuid }).first();
36
37
  return user || null;
37
38
  });
38
39
  }
39
40
  update(id, item) {
40
41
  return __awaiter(this, void 0, void 0, function* () {
41
- const [updatedUser] = yield this._knex("user").where({ id }).update(item).returning("*");
42
+ const [updatedUser] = yield this._knex(this.table).where({ id }).update(item).returning("*");
42
43
  return updatedUser || null;
43
44
  });
44
45
  }
45
46
  delete(id) {
46
47
  return __awaiter(this, void 0, void 0, function* () {
47
- const result = yield this._knex("user").where({ id }).del();
48
+ const result = yield this._knex(this.table).where({ id }).del();
48
49
  return result > 0;
49
50
  });
50
51
  }
51
52
  getAll(page, limit) {
52
53
  return __awaiter(this, void 0, void 0, function* () {
53
54
  const offset = (page - 1) * limit;
54
- const [countResult] = yield this._knex("user").count("* as count");
55
+ const [countResult] = yield this._knex(this.table).count("* as count");
55
56
  const totalCount = +countResult.count;
56
- const users = yield this._knex("user").limit(limit).offset(offset);
57
+ const users = yield this._knex(this.table).limit(limit).offset(offset);
57
58
  return {
58
59
  success: true,
59
60
  data: users,
@@ -1 +1 @@
1
- {"version":3,"file":"user.dao.js","sourceRoot":"","sources":["../../../src/dao/user/user.dao.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAGA,0EAA+C;AAE/C,MAAa,OAAO;IAApB;QACY,UAAK,GAAyB,wBAAW,CAAC,aAAa,EAAE,CAAC;IA4CtE,CAAC;IA1CS,MAAM,CAAC,IAAW;;YACpB,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YAC3E,OAAO,WAAW,CAAC;QACvB,CAAC;KAAA;IAEK,OAAO,CAAC,EAAU;;YACpB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;YAC5D,OAAO,IAAI,IAAI,IAAI,CAAC;QACxB,CAAC;KAAA;IAEK,SAAS,CAAC,IAAY;;YACxB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;YAC9D,OAAO,IAAI,IAAI,IAAI,CAAC;QACxB,CAAC;KAAA;IAEK,MAAM,CAAC,EAAU,EAAE,IAAoB;;YACzC,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,IAAI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CAAC,CAAC;QACtB,CAAC;KAAA;IAEK,MAAM,CAAC,IAAY,EAAE,KAAa;;YACpC,MAAM,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;YAElC,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YACvE,MAAM,UAAU,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC;YACtC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAEvE,OAAO;gBACH,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,KAAK;gBACX,IAAI;gBACJ,KAAK;gBACL,KAAK,EAAE,KAAK,CAAC,MAAM;gBACnB,UAAU;gBACV,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;aAC5C,CAAC;QACN,CAAC;KAAA;CACJ;AA9CD,0BA8CC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trafficgroup/knex-rel",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Knex Module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -5,38 +5,39 @@ import KnexManager from "../../KnexConnection";
5
5
 
6
6
  export class UserDAO implements IBaseDAO<IUser> {
7
7
  private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
8
+ private readonly table = '"user"';
8
9
 
9
10
  async create(item: IUser): Promise<IUser> {
10
- const [createdUser] = await this._knex("user").insert(item).returning("*");
11
+ const [createdUser] = await this._knex(this.table).insert(item).returning("*");
11
12
  return createdUser;
12
13
  }
13
14
 
14
15
  async getById(id: number): Promise<IUser | null> {
15
- const user = await this._knex("user").where({ id }).first();
16
+ const user = await this._knex(this.table).where({ id }).first();
16
17
  return user || null;
17
18
  }
18
19
 
19
20
  async getByUuid(uuid: string): Promise<IUser | null> {
20
- const user = await this._knex("user").where({ uuid }).first();
21
+ const user = await this._knex(this.table).where({ uuid }).first();
21
22
  return user || null;
22
23
  }
23
24
 
24
25
  async update(id: number, item: Partial<IUser>): Promise<IUser | null> {
25
- const [updatedUser] = await this._knex("user").where({ id }).update(item).returning("*");
26
+ const [updatedUser] = await this._knex(this.table).where({ id }).update(item).returning("*");
26
27
  return updatedUser || null;
27
28
  }
28
29
 
29
30
  async delete(id: number): Promise<boolean> {
30
- const result = await this._knex("user").where({ id }).del();
31
+ const result = await this._knex(this.table).where({ id }).del();
31
32
  return result > 0;
32
33
  }
33
34
 
34
35
  async getAll(page: number, limit: number): Promise<IDataPaginator<IUser>> {
35
36
  const offset = (page - 1) * limit;
36
37
 
37
- const [countResult] = await this._knex("user").count("* as count");
38
+ const [countResult] = await this._knex(this.table).count("* as count");
38
39
  const totalCount = +countResult.count;
39
- const users = await this._knex("user").limit(limit).offset(offset);
40
+ const users = await this._knex(this.table).limit(limit).offset(offset);
40
41
 
41
42
  return {
42
43
  success: true,
@@ -48,4 +49,4 @@ export class UserDAO implements IBaseDAO<IUser> {
48
49
  totalPages: Math.ceil(totalCount / limit),
49
50
  };
50
51
  }
51
- }
52
+ }