drizzle-orm 0.10.44 → 0.10.47

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.
@@ -21,6 +21,7 @@ export default abstract class TableRequestBuilder<TTable extends AbstractTable<T
21
21
  /**
22
22
  * Current function will return an element only if response is of length 1
23
23
  * If there are more or less than 1 element, will throw an Error
24
+ * @deprecated Use `.execute()` or `.all()` instead
24
25
  */
25
26
  findOne: () => Promise<[keyof TPartial] extends [never] ? ExtractModel<TTable> : ExtractModel<TPartial>>;
26
27
  protected abstract _execute(): Promise<Array<[keyof TPartial] extends [never] ? ExtractModel<TTable> : ExtractModel<TPartial>>>;
@@ -9,6 +9,7 @@ class TableRequestBuilder {
9
9
  /**
10
10
  * Current function will return an element only if response is of length 1
11
11
  * If there are more or less than 1 element, will throw an Error
12
+ * @deprecated Use `.execute()` or `.all()` instead
12
13
  */
13
14
  this.findOne = async () => {
14
15
  const executionRes = await this._execute();
@@ -70,6 +70,8 @@ class SelectTRB extends abstractRequestBuilder_1.default {
70
70
  catch (e) {
71
71
  throw new builderError_1.default(builderError_1.BuilderType.SELECT, this._table.tableName(), this._columns, e, this._session, this._filter);
72
72
  }
73
+ console.log(query);
74
+ console.log(values);
73
75
  if (this._logger) {
74
76
  this._logger.info(`Selecting from ${this._table.tableName()} using query:\n ${query}`);
75
77
  this._logger.info(`Values for query:\n ${values}`);
@@ -1,4 +1,4 @@
1
- import BaseLogger from 'orm/src/logger/abstractLogger';
1
+ import BaseLogger from '@/logger/abstractLogger';
2
2
  import { QueryResult } from 'pg';
3
3
  import { AbstractColumn } from '../../../columns/column';
4
4
  import ColumnType from '../../../columns/types/columnType';
@@ -1,4 +1,4 @@
1
- import BaseLogger from 'orm/src/logger/abstractLogger';
1
+ import BaseLogger from '@/logger/abstractLogger';
2
2
  import { QueryResult } from 'pg';
3
3
  import { AbstractColumn } from '../../../columns/column';
4
4
  import ColumnType from '../../../columns/types/columnType';
@@ -1,4 +1,4 @@
1
- import BaseLogger from 'orm/src/logger/abstractLogger';
1
+ import BaseLogger from '@/logger/abstractLogger';
2
2
  import { QueryResult } from 'pg';
3
3
  import { AbstractColumn } from '../../../columns/column';
4
4
  import ColumnType from '../../../columns/types/columnType';
@@ -1,4 +1,4 @@
1
- import BaseLogger from 'orm/src/logger/abstractLogger';
1
+ import BaseLogger from '@/logger/abstractLogger';
2
2
  import { QueryResult } from 'pg';
3
3
  import { AbstractColumn } from '../../../columns/column';
4
4
  import ColumnType from '../../../columns/types/columnType';
@@ -1,4 +1,4 @@
1
- import BaseLogger from 'orm/src/logger/abstractLogger';
1
+ import BaseLogger from '@/logger/abstractLogger';
2
2
  import { QueryResult } from 'pg';
3
3
  import { AbstractColumn } from '../../../columns/column';
4
4
  import ColumnType from '../../../columns/types/columnType';
@@ -1,4 +1,4 @@
1
- import BaseLogger from 'orm/src/logger/abstractLogger';
1
+ import BaseLogger from '@/logger/abstractLogger';
2
2
  import { QueryResult } from 'pg';
3
3
  import { AbstractColumn } from '../../../columns/column';
4
4
  import ColumnType from '../../../columns/types/columnType';
package/db/dbConnector.js CHANGED
@@ -17,10 +17,10 @@ class DbConnector {
17
17
  this.connect = async () => {
18
18
  try {
19
19
  const pool = new pg_1.Pool(this.__config);
20
- await pool.connect();
20
+ const connection = await pool.connect();
21
21
  // console.log('Db connected!');
22
22
  // check if table structure is the same as in code
23
- return new db_1.default(new session_1.default(pool));
23
+ return new db_1.default(new session_1.default(pool, connection));
24
24
  }
25
25
  catch (e) {
26
26
  // console.log(`Connection error: ${e.message}`);
package/db/session.d.ts CHANGED
@@ -1,12 +1,16 @@
1
- import { Pool, QueryResult } from 'pg';
1
+ import { Pool, PoolClient, QueryResult } from 'pg';
2
2
  export declare abstract class ISession {
3
3
  constructor();
4
- abstract execute(query: string, values?: Array<any>): Promise<QueryResult<any>>;
4
+ execute(query: string, values?: Array<any>): Promise<QueryResult<any>>;
5
5
  abstract parametrized(num: number): string;
6
+ abstract closeConnection(): Promise<void>;
7
+ protected abstract _execute(query: string, values?: Array<any>): Promise<QueryResult<any>>;
6
8
  }
7
9
  export default class Session extends ISession {
8
10
  private pool;
9
- constructor(pool: Pool);
10
- execute(query: string, values?: Array<any>): Promise<QueryResult<any>>;
11
+ private connection?;
12
+ constructor(pool: Pool, connection?: PoolClient | undefined);
11
13
  parametrized(num: number): string;
14
+ closeConnection(): Promise<void>;
15
+ protected _execute(query: string, values?: Array<any>): Promise<QueryResult<any>>;
12
16
  }
package/db/session.js CHANGED
@@ -5,18 +5,35 @@ class ISession {
5
5
  // eslint-disable-next-line @typescript-eslint/no-useless-constructor
6
6
  constructor() {
7
7
  }
8
+ async execute(query, values) {
9
+ const error = new Error();
10
+ try {
11
+ return await this._execute(query, values);
12
+ }
13
+ catch (e) {
14
+ error.message = e.message;
15
+ throw error;
16
+ }
17
+ }
8
18
  }
9
19
  exports.ISession = ISession;
10
20
  class Session extends ISession {
11
- constructor(pool) {
21
+ constructor(pool, connection) {
12
22
  super();
13
23
  this.pool = pool;
14
- }
15
- async execute(query, values) {
16
- return this.pool.query(query, values || []);
24
+ this.connection = connection;
17
25
  }
18
26
  parametrized(num) {
19
27
  return `$${num}`;
20
28
  }
29
+ async closeConnection() {
30
+ if (this.connection) {
31
+ this.connection.release();
32
+ }
33
+ await this.pool.end();
34
+ }
35
+ async _execute(query, values) {
36
+ return this.pool.query(query, values || []);
37
+ }
21
38
  }
22
39
  exports.default = Session;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-orm",
3
- "version": "0.10.44",
3
+ "version": "0.10.47",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,19 +18,24 @@
18
18
  "homepage": "https://github.com/lambda-direct/drizzle-orm#readme",
19
19
  "devDependencies": {
20
20
  "@typescript-eslint/eslint-plugin": "4.10.0",
21
+ "dotenv": "^16.0.0",
22
+ "drizzle-kit": "^0.9.47",
23
+ "esbuild": "^0.14.2",
24
+ "esbuild-register": "^3.3.2",
21
25
  "eslint": "7.15.0",
22
26
  "eslint-config-airbnb-typescript": "12.0.0",
23
27
  "eslint-plugin-import": "2.22.1",
24
28
  "eslint-plugin-prefer-arrow": "1.2.2",
25
29
  "ts-node": "^10.0.0",
26
- "typescript": "4.2.4"
30
+ "typescript": "4.2.4",
31
+ "uvu": "^0.5.3"
27
32
  },
28
33
  "dependencies": {
29
34
  "@types/pg": "^8.6.1",
30
35
  "pg": "^8.6.0"
31
36
  },
32
37
  "scripts": {
33
- "test": "echo \"Error: no test specified\" && exit 1",
38
+ "test": "uvu -r esbuild-register tests",
34
39
  "ts": "tsc",
35
40
  "lint": "eslint ./src --ext .ts",
36
41
  "run": "ts-node src/tables/newAbstractTable.ts"
@@ -1,13 +1,13 @@
1
1
  import { DB } from '../db';
2
2
  import { AbstractTable } from '../tables';
3
3
  import Enum from '../types/type';
4
- interface EnumsAsObject {
4
+ export interface EnumsAsObject {
5
5
  [name: string]: {
6
6
  name: string;
7
7
  values: string[];
8
8
  };
9
9
  }
10
- interface ColumnAsObject {
10
+ export interface ColumnAsObject {
11
11
  [name: string]: {
12
12
  name?: string;
13
13
  type?: string;
@@ -18,7 +18,19 @@ interface ColumnAsObject {
18
18
  references?: string;
19
19
  };
20
20
  }
21
- interface TableAsObject {
21
+ export interface IndexColumnAsObject {
22
+ [name: string]: {
23
+ name?: string;
24
+ };
25
+ }
26
+ export interface IndexAsObject {
27
+ [name: string]: {
28
+ name?: string;
29
+ columns?: ColumnAsObject;
30
+ isUnique?: boolean;
31
+ };
32
+ }
33
+ export interface TableAsObject {
22
34
  [name: string]: {
23
35
  name: string;
24
36
  columns: ColumnAsObject;
@@ -44,4 +56,3 @@ export default class MigrationSerializer {
44
56
  enums: EnumsAsObject;
45
57
  }>;
46
58
  }
47
- export {};
package/test.d.ts CHANGED
@@ -1 +0,0 @@
1
- export {};
package/test.js CHANGED
@@ -1,104 +1,133 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const dbConnector_1 = __importDefault(require("./db/dbConnector"));
7
- const session_1 = require("./db/session");
8
- const usersTable_1 = __importDefault(require("./docs/tables/usersTable"));
9
- class KnexSession extends session_1.ISession {
10
- execute(query, values) {
11
- console.log(query);
12
- console.log(values);
13
- return { rows: [] };
14
- }
15
- parametrized(num) {
16
- return `${num}?`;
17
- }
18
- }
19
- (async () => {
20
- try {
21
- const db = await new dbConnector_1.default()
22
- .connectionString('postgresql://postgres@127.0.0.1/migrator')
23
- .connect();
24
- // const db = new DB(new KnexSession());
25
- // db.useLogger(new ConsoleLogger());
26
- const usersTable = new usersTable_1.default(db);
27
- // await usersTable.select().where(or([
28
- // and([eq(usersTable.role, 'bar'), less(usersTable.phone, 'd')]),
29
- // eq(usersTable.role, 'bar'),
30
- // greater(usersTable.decimalField, 1),
31
- // ])).execute();
32
- // await usersTable.delete().where(or([
33
- // and([eq(usersTable.role, 'bar'), less(usersTable.phone, 'd')]),
34
- // eq(usersTable.role, 'bar'),
35
- // greater(usersTable.decimalField, 1),
36
- // ])).execute();
37
- // await usersTable.update().where(or([
38
- // and([eq(usersTable.role, 'bar'), less(usersTable.phone, 'd')]),
39
- // eq(usersTable.role, 'bar'),
40
- // greater(usersTable.decimalField, 1),
41
- // ])).set({
42
- // isArchived: false,
43
- // role: 'bar',
44
- // }).execute();
45
- await usersTable.insert({
46
- isArchived: false,
47
- role: 'bar',
48
- decimalField: 12,
49
- phone: ' tedss\'t',
50
- media: [' tes\'t', ' t\'es\'t'],
51
- createdAt: new Date(),
52
- }).execute();
53
- // drizzle.migrator(db).migrate({ migrationFolder: 'drizzle' });
54
- // type g = ReturnType<typeof usersTable.updatedAt.getColumnType>['codeType'];
55
- // type f = ExtractColumnType<typeof usersTable.updatedAt>;
56
- // type f1 = ExtractColumnType1<f>;
57
- // const citiesTable = new CitiesTable(db);
58
- // await usersTable.insert({
59
- // });
60
- // const res = await citiesTable.update()
61
- // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
62
- // .where(eq(citiesTable.location, 'YR'))
63
- // .set({
64
- // metadata: [{
65
- // fallback_image: true,
66
- // team_image: 'https://files.slack.com/files-pri/T016CCC3FE3-F03461UR9M5/clinic_team_photo_1.jpg?pub_secret=560c098bfb',
67
- // image_alt_text: 'Generic Physiotherapy Clinic image 1',
68
- // logo: '',
69
- // logo_alt_text: ''
70
- // }],
71
- // })
72
- // // .leftJoin(CitiesTable, UsersTable, (table) => table.userId, (table) => table.id)
73
- // // .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
74
- // .execute();
75
- // console.log(res);
76
- // const ser = new MigrationSerializer();
77
- // const res = ser.generate([usersTable as AbstractTable<UsersTable>], []);
78
- // console.log(JSON.stringify(res, null, 2));
79
- // const f = {
80
- // id: count(usersTable.id),
81
- // };
82
- // type d = ExtractModel<typeof f>;
83
- // const res = await usersTable.select()
84
- // .leftJoin(UsersTable, (table) => table.id, (table) => table.id)
85
- // .leftJoin(UsersTable, CitiesTable, (table) => table.id, (table) => table.id)
86
- // .execute();
87
- // const res = await usersTable.select()
88
- // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
89
- // .leftJoin(UsersTable, (table) => table.foundationDate, (table) => table.id)
90
- // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
91
- // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
92
- // // .groupBy({
93
- // // usersTable: usersTable.id,
94
- // // firstJoin: [usersTable.id],
95
- // // secondJoin: usersTable.id,
96
- // // thirdJoin: usersTable.id,
97
- // // })
98
- // .execute();
99
- // console.log(res);
100
- }
101
- catch (e) {
102
- console.log(e);
103
- }
104
- })();
2
+ // import { QueryResult } from 'pg';
3
+ // // eslint-disable-next-line import/no-extraneous-dependencies
4
+ // import knex from 'knex';
5
+ // import { AbstractTable, drizzle } from '.';
6
+ // import {
7
+ // and, eq, greater, isNotNull, less, or,
8
+ // } from './builders';
9
+ // import { DB } from './db';
10
+ // import DbConnector from './db/dbConnector';
11
+ // import Session, { ISession } from './db/session';
12
+ // import UsersTable from './docs/tables/usersTable';
13
+ // import ConsoleLogger from './logger/consoleLogger';
14
+ // import CitiesTable from './docs/tables/citiesTable';
15
+ // import { ExtractFieldNames } from './tables/inferTypes';
16
+ // import UserGroupsTable from './docs/tables/userGroupsTable';
17
+ // const database = knex({
18
+ // client: 'postgresql',
19
+ // connection: {
20
+ // host: '127.0.0.1',
21
+ // user: 'postgres',
22
+ // // password: '',
23
+ // database: 'migrator',
24
+ // },
25
+ // });
26
+ // class KnexSession extends ISession {
27
+ // public _execute(query: string, values?: any[]): Promise<QueryResult<any>> {
28
+ // return database.raw(query, values ?? []);
29
+ // }
30
+ // public parametrized(num: number): string {
31
+ // return '?';
32
+ // }
33
+ // }
34
+ // (async () => {
35
+ // try {
36
+ // const db = await new DbConnector()
37
+ // .connectionString('postgresql://postgres@127.0.0.1/migrator')
38
+ // .connect();
39
+ // // await usersTable.select().where(or([
40
+ // // and([eq(usersTable.role, 'bar'), less(usersTable.phone, 'd')]),
41
+ // // eq(usersTable.role, 'bar'),
42
+ // // greater(usersTable.decimalField, 1),
43
+ // // ])).execute();
44
+ // // await usersTable.delete().where(or([
45
+ // // and([eq(usersTable.role, 'bar'), less(usersTable.phone, 'd')]),
46
+ // // eq(usersTable.role, 'bar'),
47
+ // // greater(usersTable.decimalField, 1),
48
+ // // ])).execute();
49
+ // // await usersTable.update().where(or([
50
+ // // and([eq(usersTable.role, 'bar'), less(usersTable.phone, 'd')]),
51
+ // // eq(usersTable.role, 'bar'),
52
+ // // greater(usersTable.decimalField, 1),
53
+ // // ])).set({
54
+ // // isArchived: false,
55
+ // // role: 'bar',
56
+ // // }).execute();
57
+ // // await usersTable.insert({
58
+ // // isArchived: false,
59
+ // // role: 'bar',
60
+ // // decimalField: 12,
61
+ // // phone: '12',
62
+ // // media: [' tes\'t', ' t\'es\'t'],
63
+ // // createdAt: new Date(),
64
+ // // }).execute();
65
+ // const citiesTable = new CitiesTable(db);
66
+ // const usersTable = new UsersTable(db);
67
+ // const usersGroupsTable = new UserGroupsTable(db);
68
+ // const f = usersTable.tableName();
69
+ // const newJoinRes = citiesTable.select()
70
+ // .join(usersTable, (t1, t2) => `${t1.id}, ${t2.id}`)
71
+ // .join(usersGroupsTable, (t1, t2, t3) => `${t1.id}, ${t2.id}, ${t3.id}`)
72
+ // .join(usersTable, (t1, _t2, _t3, _t4) => '')
73
+ // .join(usersTable, (t1, _t2, _t3, _t4, t5) => '');
74
+ // // .join(
75
+ // // usersTable,
76
+ // // 'users2Alias',
77
+ // // (joins) => `${joins.t2Alias.baz} ${joins.t1.foo} ${joins.t2.zxc}`,
78
+ // // )
79
+ // // .join(
80
+ // // usersTable,
81
+ // // 'users3Alias',
82
+ // // (joins) => `${joins.t2Alias} ${joins.t1.bar} ${joins.t2.baz} ${joins.t1Alias.foo}`,
83
+ // // );
84
+ // // drizzle.migrator(db).migrate({ migrationFolder: 'drizzle' });
85
+ // // type g = ReturnType<typeof usersTable.updatedAt.getColumnType>['codeType'];
86
+ // // type f = ExtractColumnType<typeof usersTable.updatedAt>;
87
+ // // type f1 = ExtractColumnType1<f>;
88
+ // // await usersTable.insert({
89
+ // // });
90
+ // // const res = await citiesTable.update()
91
+ // // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
92
+ // // .where(eq(citiesTable.location, 'YR'))
93
+ // // .set({
94
+ // // metadata: [{
95
+ // // fallback_image: true,
96
+ // // team_image: 'https://files.slack.com/files-pri/T016CCC3FE3-F03461UR9M5/clinic_team_photo_1.jpg?pub_secret=560c098bfb',
97
+ // // image_alt_text: 'Generic Physiotherapy Clinic image 1',
98
+ // // logo: '',
99
+ // // logo_alt_text: ''
100
+ // // }],
101
+ // // })
102
+ // // // .leftJoin(CitiesTable, UsersTable, (table) => table.userId, (table) => table.id)
103
+ // // // .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
104
+ // // .execute();
105
+ // // console.log(res);
106
+ // // const ser = new MigrationSerializer();
107
+ // // const res = ser.generate([usersTable as AbstractTable<UsersTable>], []);
108
+ // // console.log(JSON.stringify(res, null, 2));
109
+ // // const f = {
110
+ // // id: count(usersTable.id),
111
+ // // };
112
+ // // type d = ExtractModel<typeof f>;
113
+ // // const res = await usersTable.select()
114
+ // // .leftJoin(UsersTable, (table) => table.id, (table) => table.id)
115
+ // // .leftJoin(UsersTable, CitiesTable, (table) => table.id, (table) => table.id)
116
+ // // .execute();
117
+ // // const res = await usersTable.select()
118
+ // // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
119
+ // // .leftJoin(UsersTable, (table) => table.foundationDate, (table) => table.id)
120
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
121
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.role, (table) => table.id)
122
+ // // // .groupBy({
123
+ // // // usersTable: usersTable.id,
124
+ // // // firstJoin: [usersTable.id],
125
+ // // // secondJoin: usersTable.id,
126
+ // // // thirdJoin: usersTable.id,
127
+ // // // })
128
+ // // .execute();
129
+ // // console.log(res);
130
+ // } catch (e) {
131
+ // console.log(e);
132
+ // }
133
+ // })();
package/.pnpm-debug.log DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "0 debug pnpm:scope": {
3
- "selected": 1,
4
- "workspacePrefix": "/Users/andrewsherman/IdeaProjects/datalayer-orm"
5
- },
6
- "1 error pnpm": {
7
- "code": "ERR_PNPM_GIT_NOT_UNCLEAN",
8
- "hint": "If you want to disable Git checks on publish, set the \"git-checks\" setting to \"false\", or run again with \"--no-git-checks\".",
9
- "err": {
10
- "name": "pnpm",
11
- "message": "Unclean working tree. Commit or stash changes first.",
12
- "code": "ERR_PNPM_GIT_NOT_UNCLEAN",
13
- "stack": "pnpm: Unclean working tree. Commit or stash changes first.\n at Object.handler [as publish] (/Users/andrewsherman/.nvm/versions/node/v12.20.1/lib/node_modules/pnpm/dist/pnpm.cjs:177118:17)\n at processTicksAndRejections (internal/process/task_queues.js:97:5)\n at async /Users/andrewsherman/.nvm/versions/node/v12.20.1/lib/node_modules/pnpm/dist/pnpm.cjs:182194:21\n at async run (/Users/andrewsherman/.nvm/versions/node/v12.20.1/lib/node_modules/pnpm/dist/pnpm.cjs:182168:34)\n at async runPnpm (/Users/andrewsherman/.nvm/versions/node/v12.20.1/lib/node_modules/pnpm/dist/pnpm.cjs:182387:5)\n at async /Users/andrewsherman/.nvm/versions/node/v12.20.1/lib/node_modules/pnpm/dist/pnpm.cjs:182379:7"
14
- }
15
- }
16
- }
@@ -1,9 +0,0 @@
1
- import { AbstractTable } from '..';
2
- export default class CitiesTable extends AbstractTable<CitiesTable> {
3
- id: import("..").Column<import("../columns/types/pgSerial").default, true, true, this>;
4
- foundationDate: import("..").Column<import("..").PgTimestamp, false, false, this>;
5
- location: import("..").Column<import("..").PgVarChar, true, false, this>;
6
- userId: import("..").Column<import("..").PgInteger, true, false, this>;
7
- metadata: import("..").Column<import("..").PgJsonb<any[]>, true, false, this>;
8
- tableName(): string;
9
- }
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const __1 = require("..");
7
- const usersTable_1 = __importDefault(require("./usersTable"));
8
- class CitiesTable extends __1.AbstractTable {
9
- constructor() {
10
- super(...arguments);
11
- this.id = this.serial('id').primaryKey();
12
- this.foundationDate = this.timestamp('name').notNull();
13
- this.location = this.varchar('page', { size: 256 });
14
- this.userId = this.int('user_id').foreignKey(usersTable_1.default, (table) => table.id, { onUpdate: 'CASCADE' });
15
- this.metadata = this.jsonb('metadata');
16
- }
17
- // public metadataArray = this.jsonb<CityMeta[]>('metadata_array');
18
- tableName() {
19
- return 'cities';
20
- }
21
- }
22
- exports.default = CitiesTable;
@@ -1,7 +0,0 @@
1
- import { AbstractTable } from "..";
2
- export default class UserGroupsTable extends AbstractTable<UserGroupsTable> {
3
- id: import("..").Column<import("../columns/types/pgSerial").default, true, true, this>;
4
- name: import("..").Column<import("..").PgVarChar, true, false, this>;
5
- description: import("..").Column<import("..").PgVarChar, true, false, this>;
6
- tableName(): string;
7
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const __1 = require("..");
4
- class UserGroupsTable extends __1.AbstractTable {
5
- constructor() {
6
- super(...arguments);
7
- this.id = this.serial('id').primaryKey();
8
- this.name = this.varchar('name');
9
- this.description = this.varchar('description');
10
- }
11
- tableName() {
12
- return 'user_groups';
13
- }
14
- }
15
- exports.default = UserGroupsTable;
@@ -1,17 +0,0 @@
1
- import { AbstractTable } from "..";
2
- export declare const rolesEnum: import("../types/type").default<"foo" | "bar" | "baz">;
3
- export default class UsersTable extends AbstractTable<UsersTable> {
4
- id: import("..").Column<import("../columns/types/pgSerial").default, true, true, this>;
5
- fullName: import("..").Column<import("..").PgText, true, false, this>;
6
- phone: import("..").Column<import("..").PgVarChar, true, false, this>;
7
- media: import("..").Column<import("..").PgJsonb<string[]>, true, false, this>;
8
- decimalField: import("..").Column<import("..").PgBigDecimal, false, false, this>;
9
- bigIntField: import("..").Column<import("..").PgBigInt, true, false, this>;
10
- role: import("..").Column<import("../columns/types/pgEnum").default<"foo" | "bar" | "baz">, false, false, this>;
11
- createdAt: import("..").Column<import("..").PgTimestamp, false, false, this>;
12
- updatedAt: import("..").Column<import("..").PgTimestamp, true, false, this>;
13
- isArchived: import("..").Column<import("..").PgBoolean, true, false, this>;
14
- phoneFullNameIndex: import("../indexes/tableIndex").default;
15
- phoneIndex: import("../indexes/tableIndex").default;
16
- tableName(): string;
17
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- /* eslint-disable max-classes-per-file */
3
- // import { Defaults } from '../../columns/column';
4
- // import { rolesEnum } from '../types/rolesType';
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.rolesEnum = void 0;
7
- const __1 = require("..");
8
- const type_1 = require("../types/type");
9
- exports.rolesEnum = type_1.createEnum({ alias: 'test-enum', values: ['foo', 'bar', 'baz'] });
10
- class UsersTable extends __1.AbstractTable {
11
- constructor() {
12
- super(...arguments);
13
- this.id = this.serial('id').primaryKey();
14
- this.fullName = this.text('full_name');
15
- this.phone = this.varchar('phone', { size: 256 });
16
- this.media = this.jsonb('media');
17
- this.decimalField = this.decimal('test', { precision: 100, scale: 2 }).notNull();
18
- this.bigIntField = this.bigint('test1', 'max_bytes_53');
19
- this.role = this.type(exports.rolesEnum, 'name_in_table').notNull();
20
- this.createdAt = this.timestamp('created_at').notNull();
21
- // public createdAtWithTimezone = this.timestamptz('created_at');
22
- this.updatedAt = this.timestamp('updated_at').defaultValue(__1.Defaults.CURRENT_TIMESTAMP);
23
- this.isArchived = this.bool('is_archived').defaultValue(false);
24
- this.phoneFullNameIndex = this.index([this.phone, this.fullName]);
25
- this.phoneIndex = this.uniqueIndex(this.phone);
26
- }
27
- tableName() {
28
- return 'users';
29
- }
30
- }
31
- exports.default = UsersTable;
@@ -1,7 +0,0 @@
1
- import { AbstractTable } from '..';
2
- export default class UsersToUserGroupsTable extends AbstractTable<UsersToUserGroupsTable> {
3
- groupId: import("..").Column<import("..").PgInteger, true, false, this>;
4
- userId: import("..").Column<import("..").PgInteger, true, false, this>;
5
- manyToManyIndex: import("../indexes/tableIndex").default;
6
- tableName(): string;
7
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const __1 = require("..");
7
- const userGroupsTable_1 = __importDefault(require("./userGroupsTable"));
8
- const usersTable_1 = __importDefault(require("./usersTable"));
9
- class UsersToUserGroupsTable extends __1.AbstractTable {
10
- constructor() {
11
- super(...arguments);
12
- this.groupId = this.int('city_id').foreignKey(userGroupsTable_1.default, (table) => table.id, { onDelete: 'CASCADE' });
13
- this.userId = this.int('user_id').foreignKey(usersTable_1.default, (table) => table.id, { onDelete: 'CASCADE' });
14
- this.manyToManyIndex = this.index([this.groupId, this.userId]);
15
- }
16
- tableName() {
17
- return 'users_to_user_groups';
18
- }
19
- }
20
- exports.default = UsersToUserGroupsTable;