drizzle-orm 0.10.8 → 0.10.9
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/docs/tables/usersTable.d.ts +1 -1
- package/package.json +1 -1
- package/tables/abstractTable.d.ts +2 -2
- package/tables/aggregators.d.ts +27 -0
- package/tables/aggregators.js +56 -0
- package/tables/migrationsTable.d.ts +1 -1
- package/test.d.ts +0 -1
- package/test.js +44 -260
- package/data/tables/citiesTable.d.ts +0 -14
- package/data/tables/citiesTable.js +0 -17
- package/data/tables/userGroupsTable.d.ts +0 -7
- package/data/tables/userGroupsTable.js +0 -15
- package/data/tables/usersTable.d.ts +0 -16
- package/data/tables/usersTable.js +0 -31
- package/data/tables/usersToUserGroups.d.ts +0 -7
- package/data/tables/usersToUserGroups.js +0 -17
- package/data/types/rolesType.d.ts +0 -1
- package/data/types/rolesType.js +0 -6
|
@@ -6,7 +6,7 @@ export default class UsersTable extends AbstractTable<UsersTable> {
|
|
|
6
6
|
phone: import("../../columns/column").Column<import("../..").PgVarChar, true, false, this>;
|
|
7
7
|
media: import("../../columns/column").Column<import("../..").PgJsonb<string[]>, true, false, this>;
|
|
8
8
|
decimalField: import("../../columns/column").Column<import("../..").PgBigDecimal, false, false, this>;
|
|
9
|
-
bigIntField: import("../../columns/column").Column<import("../..").PgBigInt, true,
|
|
9
|
+
bigIntField: import("../../columns/column").Column<import("../..").PgBigInt, true, false, this>;
|
|
10
10
|
role: import("../../columns/column").Column<import("../../columns/types/pgEnum").default<"foo" | "bar" | "baz">, false, false, this>;
|
|
11
11
|
createdAt: import("../../columns/column").Column<import("../..").PgTimestamp, false, false, this>;
|
|
12
12
|
updatedAt: import("../../columns/column").Column<import("../..").PgTimestamp, true, false, this>;
|
package/package.json
CHANGED
|
@@ -54,8 +54,8 @@ export default abstract class AbstractTable<TTable extends AbstractTable<TTable>
|
|
|
54
54
|
protected bigSerial(name: string, maxBytes: 'max_bytes_64'): Column<PgBigSerial64, true, true, this>;
|
|
55
55
|
protected timestamp(name: string): Column<PgTimestamp, true, false, this>;
|
|
56
56
|
protected timestamptz(name: string): Column<PgTimestamptz, true, false, this>;
|
|
57
|
-
protected bigint(name: string, maxBytes: 'max_bytes_53'): Column<PgBigInt53, true,
|
|
58
|
-
protected bigint(name: string, maxBytes: 'max_bytes_64'): Column<PgBigInt64, true,
|
|
57
|
+
protected bigint(name: string, maxBytes: 'max_bytes_53'): Column<PgBigInt53, true, false, this>;
|
|
58
|
+
protected bigint(name: string, maxBytes: 'max_bytes_64'): Column<PgBigInt64, true, false, this>;
|
|
59
59
|
protected type<ETtype extends string>(typeEnum: Enum<ETtype>, name: string): Column<PgEnum<ExtractEnumValues<Enum<ETtype>>>, true, false, this>;
|
|
60
60
|
protected decimal(name: string, params?: {
|
|
61
61
|
precision?: number;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AbstractColumn } from '../columns/column';
|
|
2
|
+
import ColumnType from '../columns/types/columnType';
|
|
3
|
+
import { DB } from '../db';
|
|
4
|
+
import AbstractTable from './abstractTable';
|
|
5
|
+
export declare class AggregatedColumn<T extends ColumnType, TNullable extends boolean = true, TAutoIncrement extends boolean = false, TParent extends AbstractTable<any> = any> extends AbstractColumn<T, TNullable, TAutoIncrement, TParent> {
|
|
6
|
+
columnToAggregate?: AbstractColumn<ColumnType<any>, boolean, boolean>;
|
|
7
|
+
constructor(parent: TParent, columnName: string, columnType: T, columnToAggregate?: AbstractColumn<ColumnType<any>, boolean, boolean>);
|
|
8
|
+
foreignKey<ITable extends AbstractTable<ITable>>(table: new (db: DB) => ITable, callback: (table: ITable) => AbstractColumn<T, boolean, boolean, TParent>, onConstraint: {
|
|
9
|
+
onDelete?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT' | undefined;
|
|
10
|
+
onUpdate?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT' | undefined;
|
|
11
|
+
}): AbstractColumn<T, TNullable, TAutoIncrement, any>;
|
|
12
|
+
primaryKey(): AbstractColumn<T, boolean, boolean, TParent>;
|
|
13
|
+
notNull(): AbstractColumn<T, boolean, boolean, TParent>;
|
|
14
|
+
getAlias(): string;
|
|
15
|
+
}
|
|
16
|
+
export declare abstract class PgAggregatedColumnType<TType, T extends AbstractColumn<ColumnType<any>, boolean, boolean> = any> extends ColumnType<TType> {
|
|
17
|
+
protected dbName: string;
|
|
18
|
+
protected column?: T;
|
|
19
|
+
constructor(column?: T);
|
|
20
|
+
insertStrategy(value: TType): string;
|
|
21
|
+
}
|
|
22
|
+
export declare class PgCount<T extends AbstractColumn<ColumnType<any>, boolean, boolean> = any> extends PgAggregatedColumnType<number, T> {
|
|
23
|
+
constructor(column?: T);
|
|
24
|
+
getDbName(): string;
|
|
25
|
+
selectStrategy(value: any): number | undefined;
|
|
26
|
+
}
|
|
27
|
+
export declare const count: <TType extends ColumnType<any>, T extends AbstractColumn<TType, boolean, boolean, any>>(column?: T | undefined) => AggregatedColumn<PgCount<any>, false, true, any>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable import/no-cycle */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
4
|
+
/* eslint-disable max-len */
|
|
5
|
+
/* eslint-disable max-classes-per-file */
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.count = exports.PgCount = exports.PgAggregatedColumnType = exports.AggregatedColumn = void 0;
|
|
8
|
+
const column_1 = require("../columns/column");
|
|
9
|
+
const columnType_1 = require("../columns/types/columnType");
|
|
10
|
+
const ecranate_1 = require("../utils/ecranate");
|
|
11
|
+
class AggregatedColumn extends column_1.AbstractColumn {
|
|
12
|
+
constructor(parent, columnName, columnType, columnToAggregate) {
|
|
13
|
+
super(parent, columnName, columnType);
|
|
14
|
+
this.columnToAggregate = columnToAggregate;
|
|
15
|
+
}
|
|
16
|
+
foreignKey(table, callback, onConstraint) {
|
|
17
|
+
throw new Error('Method not implemented.');
|
|
18
|
+
}
|
|
19
|
+
primaryKey() {
|
|
20
|
+
throw new Error('Method not implemented.');
|
|
21
|
+
}
|
|
22
|
+
notNull() {
|
|
23
|
+
throw new Error('Method not implemented.');
|
|
24
|
+
}
|
|
25
|
+
getAlias() {
|
|
26
|
+
super.getAlias();
|
|
27
|
+
return `${this.columnName}`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.AggregatedColumn = AggregatedColumn;
|
|
31
|
+
class PgAggregatedColumnType extends columnType_1.default {
|
|
32
|
+
constructor(column) {
|
|
33
|
+
super();
|
|
34
|
+
this.column = column;
|
|
35
|
+
}
|
|
36
|
+
insertStrategy(value) {
|
|
37
|
+
throw new Error('Method not implemented.');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.PgAggregatedColumnType = PgAggregatedColumnType;
|
|
41
|
+
class PgCount extends PgAggregatedColumnType {
|
|
42
|
+
constructor(column) {
|
|
43
|
+
super(column);
|
|
44
|
+
}
|
|
45
|
+
getDbName() {
|
|
46
|
+
const tableName = this.column ? `${this.column.getParentName()}.` : '*';
|
|
47
|
+
const columnName = this.column ? ecranate_1.ecranate(this.column.getColumnName()) : '';
|
|
48
|
+
return `COUNT(${tableName}${columnName})`;
|
|
49
|
+
}
|
|
50
|
+
selectStrategy(value) {
|
|
51
|
+
return value ? parseInt(value, 10) : undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.PgCount = PgCount;
|
|
55
|
+
const count = (column) => new AggregatedColumn(column ? column.getParent() : undefined, 'count', new PgCount(column), column);
|
|
56
|
+
exports.count = count;
|
|
@@ -2,6 +2,6 @@ import AbstractTable from './abstractTable';
|
|
|
2
2
|
export default class MigrationsTable extends AbstractTable<MigrationsTable> {
|
|
3
3
|
id: import("..").Column<import("../columns/types/pgSerial").default, true, true, this>;
|
|
4
4
|
hash: import("..").Column<import("..").PgText, false, false, this>;
|
|
5
|
-
createdAt: import("..").Column<import("..").PgBigInt, true,
|
|
5
|
+
createdAt: import("..").Column<import("..").PgBigInt, true, false, this>;
|
|
6
6
|
tableName(): string;
|
|
7
7
|
}
|
package/test.d.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/test.js
CHANGED
|
@@ -1,261 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// .set({
|
|
47
|
-
// phone: 'hello'
|
|
48
|
-
// })
|
|
49
|
-
// .all();
|
|
50
|
-
// await table.select()
|
|
51
|
-
// .where({
|
|
52
|
-
// and: {
|
|
53
|
-
// id: {
|
|
54
|
-
// eq: 1,
|
|
55
|
-
// },
|
|
56
|
-
// phone: {
|
|
57
|
-
// notEq: 'hello',
|
|
58
|
-
// },
|
|
59
|
-
// },
|
|
60
|
-
// })
|
|
61
|
-
// .all();
|
|
62
|
-
// await table.select()
|
|
63
|
-
// .where({
|
|
64
|
-
// and: {
|
|
65
|
-
// id: eq(1),
|
|
66
|
-
// phone: notEq('hello'),
|
|
67
|
-
// },
|
|
68
|
-
// })
|
|
69
|
-
// .all();
|
|
70
|
-
// await table.select()
|
|
71
|
-
// .where(and([
|
|
72
|
-
// eq(table.id, 1),
|
|
73
|
-
// notEq(table.phone, 'hello'),
|
|
74
|
-
// ]))
|
|
75
|
-
// .all();
|
|
76
|
-
// await table.insertMany([{
|
|
77
|
-
// decimalField: 12.4,
|
|
78
|
-
// createdAt: new Date(),
|
|
79
|
-
// role: 'foo',
|
|
80
|
-
// },
|
|
81
|
-
// {
|
|
82
|
-
// decimalField: 13.4,
|
|
83
|
-
// createdAt: new Date(),
|
|
84
|
-
// role: 'foo',
|
|
85
|
-
// }]).all();
|
|
86
|
-
// const d = await table.update().where(and([
|
|
87
|
-
// or([
|
|
88
|
-
// notEq(table.id, 1),
|
|
89
|
-
// eq(table.bigIntField, 1)]),
|
|
90
|
-
// or([notEq(table.id, 2),
|
|
91
|
-
// eq(table.bigIntField, 1),
|
|
92
|
-
// and([notEq(table.id, 1),
|
|
93
|
-
// eq(table.isArchived, true),
|
|
94
|
-
// ]),
|
|
95
|
-
// ])])).set({
|
|
96
|
-
// // phone: 'updated',
|
|
97
|
-
// bigIntField: 1,
|
|
98
|
-
// decimalField: 1.2,
|
|
99
|
-
// }).all();
|
|
100
|
-
// console.log(d);
|
|
101
|
-
// await table.delete().where(eq(table.id, 4)).all();
|
|
102
|
-
// const cities = new CitiesTable(db);
|
|
103
|
-
// const d = new UsersToUserGroupsTable(db);
|
|
104
|
-
// SELECT * FROM users WHERE id = $1 and name = $2
|
|
105
|
-
// const res = notEq(table.id, 1).toQuery();
|
|
106
|
-
// const res1 = and([notEq(table.id, 1), like(table.phone, 'phone')]).toQuery();
|
|
107
|
-
// const res2 = and([
|
|
108
|
-
// or([
|
|
109
|
-
// notEq(table.id, 1),
|
|
110
|
-
// like(table.phone, 'phone')]),
|
|
111
|
-
// or([notEq(table.id, 2),
|
|
112
|
-
// like(table.phone, 'phone2'),
|
|
113
|
-
// and([notEq(table.id, 1),
|
|
114
|
-
// eq(table.isArchived, true),
|
|
115
|
-
// ]),
|
|
116
|
-
// ]),
|
|
117
|
-
// ]).toQuery();
|
|
118
|
-
// const res3 = and([notEq(table.id, 2),
|
|
119
|
-
// like(table.phone, 'phone2'),
|
|
120
|
-
// or([
|
|
121
|
-
// notEq(table.id, 1),
|
|
122
|
-
// like(table.phone, 'phone')]),
|
|
123
|
-
// ]).toQuery();
|
|
124
|
-
// // console.log(res);
|
|
125
|
-
// console.log(res2);
|
|
126
|
-
// console.log(res3);
|
|
127
|
-
// const serializer = new MigrationSerializer();
|
|
128
|
-
// const res = serializer.generate([table], []);
|
|
129
|
-
// console.log(JSON.stringify(res, null, 2));
|
|
130
|
-
// fs.writeFileSync('introspected.json', JSON.stringify(res, null, 2), 'utf8');
|
|
131
|
-
// const ser = new MigrationSerializer();
|
|
132
|
-
// const d = db.create(UsersTable) as unknown as AbstractTable<any>;
|
|
133
|
-
// const f = ser.generate([d], []);
|
|
134
|
-
// console.log(JSON.stringify(f, null, 2));
|
|
135
|
-
// await drizzle.migrator(db).smigrate('drizzle.config.yml');
|
|
136
|
-
// await drizzle.migrator(db).migrate({ migrationFolder: 'drizzle' });
|
|
137
|
-
// const typesFileNames = fs.readdirSync('/Users/andrewsherman/IdeaProjects/datalayer-orm/src/examples/types');
|
|
138
|
-
// typesFileNames.forEach((filename) => {
|
|
139
|
-
// const types = fromTypeFile(`./examples/types/${filename.split('.')[0]}`);
|
|
140
|
-
// const typeValues = types[0].values;
|
|
141
|
-
// console.log(typeValues);
|
|
142
|
-
// // console.log(Object.values(typeValues));
|
|
143
|
-
// });
|
|
144
|
-
// const usersTable = new UsersTable(db);
|
|
145
|
-
// const citiesTable = new CitiesTable(db);
|
|
146
|
-
// await db.session().execute(Create.table(usersTable).build());
|
|
147
|
-
// await db.session().execute(Create.table(citiesTable).build());
|
|
148
|
-
// await usersTable.select().where(greater(usersTable.createdAtWithTimezone, new Date())).execute();
|
|
149
|
-
// const db = await new DbConnector()
|
|
150
|
-
// .connectionString('postgresql://postgres@127.0.0.1/drizzle')
|
|
151
|
-
// .connect();
|
|
152
|
-
// const db = await new DbConnector()
|
|
153
|
-
// .connectionString('postgresql://postgres@127.0.0.1/migrator')
|
|
154
|
-
// .connect();
|
|
155
|
-
// const usersTable: UsersTable = new UsersTable(db);
|
|
156
|
-
// const knexInstance = knex.knex({
|
|
157
|
-
// client: 'pg',
|
|
158
|
-
// connection: 'postgresql://postgres@127.0.0.1/migrator',
|
|
159
|
-
// });
|
|
160
|
-
// const userTableForKnex: UsersTable = new UsersTable(knexDb);
|
|
161
|
-
// const users = await userTableForKnex.select().all();
|
|
162
|
-
// console.log(users[0]);
|
|
163
|
-
// const arr: AbstractColumn<ColumnType<any>, boolean, boolean>[] = [usersTable.id, usersTable.phone];
|
|
164
|
-
// const objectRes: {[name: string]: AbstractColumn<ColumnType, boolean, boolean>} = arr.reduce(
|
|
165
|
-
// (obj, item, index) => Object.assign(obj, { [Object.getOwnPropertyNames(item)[index]]: item }), {},
|
|
166
|
-
// );
|
|
167
|
-
// type f = ExtractModel<typeof objectRes1>;
|
|
168
|
-
// type d1 = ExtractModel<UsersTable>;
|
|
169
|
-
// const dff = usersTable.phone;
|
|
170
|
-
// const f = usersTable.select()
|
|
171
|
-
// .partial({
|
|
172
|
-
// // usersCount: usersTable.id,
|
|
173
|
-
// sumNumber: usersTable.phone,
|
|
174
|
-
// });
|
|
175
|
-
// const f = usersTable.select({
|
|
176
|
-
// usersCount: usersTable.id,
|
|
177
|
-
// sumNumber: usersTable.phone,
|
|
178
|
-
// })
|
|
179
|
-
// .limit(2)
|
|
180
|
-
// .offset(2)
|
|
181
|
-
// .all();
|
|
182
|
-
// Done: provide partial interface + partial objects to each join inside and use in each execute mapper
|
|
183
|
-
// Add possibility tp join on another table -> https://www.postgresqltutorial.com/postgresql-inner-join/
|
|
184
|
-
// ________________________
|
|
185
|
-
// const f1 = await usersTable.select({
|
|
186
|
-
// usersCount: usersTable.id,
|
|
187
|
-
// sumNumber: usersTable.phone,
|
|
188
|
-
// }).leftJoin(CitiesTable,
|
|
189
|
-
// (user) => user.id,
|
|
190
|
-
// (city) => city.id)
|
|
191
|
-
// .leftJoin(CitiesTable, CitiesTable,
|
|
192
|
-
// (user) => user.id,
|
|
193
|
-
// (city) => city.userId)
|
|
194
|
-
// .leftJoin(CitiesTable, CitiesTable,
|
|
195
|
-
// (user) => user.id,
|
|
196
|
-
// (city) => city.userId)
|
|
197
|
-
// .execute();
|
|
198
|
-
// const res = f1.map((user, city, city1) => ({ user, city, city1 }));
|
|
199
|
-
// console.log(res);
|
|
200
|
-
// type d = ExtractModel<{
|
|
201
|
-
// usersCount: Column<PgSerial, true, true, UsersTable>;
|
|
202
|
-
// sumNumber: Column<PgVarChar, true, false, UsersTable>;
|
|
203
|
-
// }>;
|
|
204
|
-
// type f = Check<UserGroupsTable, UsersTable, CitiesTable>;
|
|
205
|
-
// f1.map((user, city, city1, city2, city3, city4) => {
|
|
206
|
-
// });
|
|
207
|
-
// const f = usersTable.select().testTypes();
|
|
208
|
-
// const rg = {
|
|
209
|
-
// // usersCount: usersTable.id,
|
|
210
|
-
// sumNumber: usersTable.phone,
|
|
211
|
-
// };
|
|
212
|
-
// const f = await usersTable.select({
|
|
213
|
-
// usersCount: usersTable.id,
|
|
214
|
-
// sumNumber: usersTable.phone,
|
|
215
|
-
// }).all();
|
|
216
|
-
// console.log(typeof f);
|
|
217
|
-
// const objectRes1 = {
|
|
218
|
-
// usersCount: usersTable.id,
|
|
219
|
-
// sumNumber: usersTable.phone,
|
|
220
|
-
// };
|
|
221
|
-
// type fd = ExtractModel<typeof f>;
|
|
222
|
-
// const g = await usersTable.select().execute();
|
|
223
|
-
// type fd = ExtractModel<typeof g>;
|
|
224
|
-
// if (res.isLeft()) {
|
|
225
|
-
// console.log(res.value.reason);
|
|
226
|
-
// } else {
|
|
227
|
-
// console.log(res.value);
|
|
228
|
-
// }
|
|
229
|
-
// const userTable = new UsersTable(db);
|
|
230
|
-
// const citiesTable = new CitiesTable(db);
|
|
231
|
-
// const uni = new UniJoin(userTable).innerJoin(
|
|
232
|
-
// UsersTable,
|
|
233
|
-
// (table) => table.id,
|
|
234
|
-
// (t) => t.id,
|
|
235
|
-
// );
|
|
236
|
-
// Inner.join1(
|
|
237
|
-
// { table: CitiesTable, column: ((table) => table.id), on: ((table) => table.userId1) },
|
|
238
|
-
// );
|
|
239
|
-
// const res = await userTable.select().leftJoin(
|
|
240
|
-
// UsersTable,
|
|
241
|
-
// (table) => table.id,
|
|
242
|
-
// (t) => t.id,
|
|
243
|
-
// ).execute();
|
|
244
|
-
// const d = await userTable
|
|
245
|
-
// .insert({ phone: 'phone1', createdAt: new Date(), role: 'foo' }).all();
|
|
246
|
-
// const all = await userTable.select().all();
|
|
247
|
-
// console.log(all[1]?.role);
|
|
248
|
-
// console.log(typeof d[0]?.role);
|
|
249
|
-
// const users = await userTable.update()
|
|
250
|
-
// .where(eq(userTable.id, 1))
|
|
251
|
-
// .set({
|
|
252
|
-
// phone: 'dsdf',
|
|
253
|
-
// createdAt: new Date(),
|
|
254
|
-
// })
|
|
255
|
-
// .all();
|
|
256
|
-
// console.log(users);
|
|
257
|
-
}
|
|
258
|
-
catch (e) {
|
|
259
|
-
console.log(e);
|
|
260
|
-
}
|
|
261
|
-
})();
|
|
2
|
+
// import DbConnector from './db/dbConnector';
|
|
3
|
+
// import UsersTable from './docs/tables/usersTable';
|
|
4
|
+
// import ConsoleLogger from './logger/consoleLogger';
|
|
5
|
+
// import { count } from './tables/aggregators';
|
|
6
|
+
// (async () => {
|
|
7
|
+
// try {
|
|
8
|
+
// const db = await new DbConnector()
|
|
9
|
+
// .connectionString('postgresql://postgres@127.0.0.1/migrator')
|
|
10
|
+
// .connect();
|
|
11
|
+
// const usersTable = new UsersTable(db);
|
|
12
|
+
// db.useLogger(new ConsoleLogger());
|
|
13
|
+
// // const f = {
|
|
14
|
+
// // id: count(usersTable.id),
|
|
15
|
+
// // };
|
|
16
|
+
// // type d = ExtractModel<typeof f>;
|
|
17
|
+
// // const res = await usersTable.select({
|
|
18
|
+
// // piska: count(),
|
|
19
|
+
// // mongodibil: count(usersTable.phone),
|
|
20
|
+
// // })
|
|
21
|
+
// // .where({
|
|
22
|
+
// // piska: eq(),
|
|
23
|
+
// // mongodibil: eq(usersTable.phone),
|
|
24
|
+
// // }).leftJoin(UsersTable, (table) => table.id, (table) => table.id)
|
|
25
|
+
// // .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
|
|
26
|
+
// // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
|
|
27
|
+
// // .orderBy((table, join1, join2, join3) => [{table.id}, join1.id, join1.phone])
|
|
28
|
+
// // .execute();
|
|
29
|
+
// const res = await usersTable.select()
|
|
30
|
+
// .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
|
|
31
|
+
// .leftJoin(UsersTable, (table) => table.id, (table) => table.id)
|
|
32
|
+
// .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
|
|
33
|
+
// .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
|
|
34
|
+
// // .groupBy({
|
|
35
|
+
// // usersTable: usersTable.id,
|
|
36
|
+
// // firstJoin: [usersTable.id],
|
|
37
|
+
// // secondJoin: usersTable.id,
|
|
38
|
+
// // thirdJoin: usersTable.id,
|
|
39
|
+
// // })
|
|
40
|
+
// .execute();
|
|
41
|
+
// console.log(res);
|
|
42
|
+
// } catch (e) {
|
|
43
|
+
// console.log(e);
|
|
44
|
+
// }
|
|
45
|
+
// })();
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import AbstractTable from '../../tables/abstractTable';
|
|
2
|
-
interface CityMeta {
|
|
3
|
-
population: number;
|
|
4
|
-
connection: string;
|
|
5
|
-
}
|
|
6
|
-
export default class CitiesTable extends AbstractTable<CitiesTable> {
|
|
7
|
-
id: import("../..").Column<import("../../columns/types/pgSerial").default, true, true, this>;
|
|
8
|
-
foundationDate: import("../..").Column<import("../..").PgTimestamp, false, false, this>;
|
|
9
|
-
location: import("../..").Column<import("../..").PgVarChar, true, false, this>;
|
|
10
|
-
userId: import("../..").Column<import("../..").PgInteger, true, false, this>;
|
|
11
|
-
metadata: import("../..").Column<import("../..").PgJsonb<CityMeta>, true, false, this>;
|
|
12
|
-
tableName(): string;
|
|
13
|
-
}
|
|
14
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const abstractTable_1 = require("../../tables/abstractTable");
|
|
4
|
-
class CitiesTable extends abstractTable_1.default {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(...arguments);
|
|
7
|
-
this.id = this.serial('id').primaryKey();
|
|
8
|
-
this.foundationDate = this.timestamp('name').notNull();
|
|
9
|
-
this.location = this.varchar('page', { size: 256 });
|
|
10
|
-
this.userId = this.int('user_id').foreignKey(CitiesTable, (table) => table.id, { onUpdate: 'CASCADE' });
|
|
11
|
-
this.metadata = this.jsonb('metadata');
|
|
12
|
-
}
|
|
13
|
-
tableName() {
|
|
14
|
-
return 'cities';
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.default = CitiesTable;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import AbstractTable from '../../tables/abstractTable';
|
|
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 abstractTable_1 = require("../../tables/abstractTable");
|
|
4
|
-
class UserGroupsTable extends abstractTable_1.default {
|
|
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,16 +0,0 @@
|
|
|
1
|
-
import AbstractTable from '../../tables/abstractTable';
|
|
2
|
-
export declare const rolesEnum: import("../../types/type").default<"user" | "guest" | "admin">;
|
|
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, true, this>;
|
|
10
|
-
createdAt: import("../..").Column<import("../..").PgTimestamp, false, false, this>;
|
|
11
|
-
createdAtWithTimezone: import("../..").Column<import("../../columns/types/pgTimestamptz").default, true, false, this>;
|
|
12
|
-
isArchived: import("../..").Column<import("../..").PgBoolean, true, false, this>;
|
|
13
|
-
phoneFullNameIndex: import("../../indexes/tableIndex").default;
|
|
14
|
-
phoneIndex: import("../../indexes/tableIndex").default;
|
|
15
|
-
tableName(): string;
|
|
16
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rolesEnum = void 0;
|
|
4
|
-
/* eslint-disable max-classes-per-file */
|
|
5
|
-
// import { Defaults } from '../../columns/column';
|
|
6
|
-
const abstractTable_1 = require("../../tables/abstractTable");
|
|
7
|
-
const type_1 = require("../../types/type");
|
|
8
|
-
// import { rolesEnum } from '../types/rolesType';
|
|
9
|
-
exports.rolesEnum = type_1.createEnum({ alias: 'test-enum', values: ['user', 'guest', 'admin'] });
|
|
10
|
-
class UsersTable extends abstractTable_1.default {
|
|
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
|
-
// public role = this.type(rolesEnum, 'name_in_table', { notNull: true });
|
|
20
|
-
this.createdAt = this.timestamp('created_at').notNull();
|
|
21
|
-
this.createdAtWithTimezone = this.timestamptz('created_at_time_zone');
|
|
22
|
-
// public updatedAt = this.timestamp('updated_at').defaultValue(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 '../../tables/abstractTable';
|
|
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,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const abstractTable_1 = require("../../tables/abstractTable");
|
|
4
|
-
const userGroupsTable_1 = require("./userGroupsTable");
|
|
5
|
-
const usersTable_1 = require("./usersTable");
|
|
6
|
-
class UsersToUserGroupsTable extends abstractTable_1.default {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(...arguments);
|
|
9
|
-
this.groupId = this.int('city_id').foreignKey(userGroupsTable_1.default, (table) => table.id, { onDelete: 'CASCADE' });
|
|
10
|
-
this.userId = this.int('user_id').foreignKey(usersTable_1.default, (table) => table.id, { onDelete: 'CASCADE' });
|
|
11
|
-
this.manyToManyIndex = this.index([this.groupId, this.userId]);
|
|
12
|
-
}
|
|
13
|
-
tableName() {
|
|
14
|
-
return 'users_to_user_groups';
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.default = UsersToUserGroupsTable;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const rolesEnum: import("../../types/type").default<"foo" | "bar" | "baz">;
|
package/data/types/rolesType.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rolesEnum = void 0;
|
|
4
|
-
const type_1 = require("../../types/type");
|
|
5
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
6
|
-
exports.rolesEnum = type_1.createEnum({ alias: 'test-enum', values: ['foo', 'bar', 'baz'] });
|