drizzle-orm 0.10.36 → 0.10.39

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.
@@ -0,0 +1,16 @@
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
+ }
@@ -3,11 +3,18 @@ import DB from '../db/db';
3
3
  import { AbstractTable } from '../tables';
4
4
  import ColumnType from './types/columnType';
5
5
  import PgTimestamptz from './types/pgTimestamptz';
6
- export declare enum Defaults {
7
- CURRENT_TIMESTAMP = "CURRENT_TIMESTAMP"
8
- }
9
6
  declare type PgTimes = PgTimestamptz | PgTime | PgTimestamp;
10
- export declare type ExtractColumnType<T extends ColumnType> = T extends ColumnType<infer TCodeType> ? T extends PgTimes ? TCodeType | Defaults : TCodeType : never;
7
+ declare class RawSqlValue {
8
+ readonly value: any;
9
+ readonly escape: boolean;
10
+ constructor(value: any, escape: boolean);
11
+ toJSON(): string;
12
+ }
13
+ export declare const Defaults: {
14
+ CURRENT_TIMESTAMP: RawSqlValue;
15
+ };
16
+ export declare type ExtractColumnType<T extends ColumnType<any>> = T extends ColumnType<infer TCodeType> ? T extends PgTimes ? TCodeType : TCodeType : never;
17
+ export declare const rawValue: (value: string) => RawSqlValue;
11
18
  export declare abstract class AbstractColumn<T extends ColumnType, TNullable extends boolean = true, TAutoIncrement extends boolean = false, TParent extends AbstractTable<any> = any> {
12
19
  isNullableFlag: boolean;
13
20
  primaryKeyName?: string;
@@ -18,7 +25,7 @@ export declare abstract class AbstractColumn<T extends ColumnType, TNullable ext
18
25
  protected parentTableName: string;
19
26
  protected columnType: T;
20
27
  protected columnName: string;
21
- protected defaultParam: any;
28
+ protected defaultParam: RawSqlValue;
22
29
  protected referenced: AbstractColumn<T, boolean, boolean>;
23
30
  constructor(parent: TParent, columnName: string, columnType: T);
24
31
  getOnDelete: () => string | undefined;
@@ -34,17 +41,18 @@ export declare abstract class AbstractColumn<T extends ColumnType, TNullable ext
34
41
  onDelete?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
35
42
  onUpdate?: 'CASCADE' | 'RESTRICT' | 'SET NULL' | 'SET DEFAULT';
36
43
  }): AbstractColumn<T, TNullable, TAutoIncrement, TParent>;
37
- defaultValue: (value: ExtractColumnType<T>) => this;
44
+ defaultValue(value: ExtractColumnType<T> | RawSqlValue): AbstractColumn<T, boolean, boolean, TParent>;
38
45
  abstract primaryKey(): AbstractColumn<T, boolean, boolean, TParent>;
39
46
  unique: () => this;
40
47
  abstract notNull(): AbstractColumn<T, boolean, boolean, TParent>;
41
48
  getColumnName: () => string;
42
49
  getReferenced: () => AbstractColumn<T, boolean, boolean, TParent>;
43
50
  getColumnType: () => T;
44
- getDefaultValue: () => any;
51
+ getDefaultValue: () => RawSqlValue;
45
52
  }
46
53
  export declare class Column<T extends ColumnType, TNullable extends boolean = true, TAutoIncrement extends boolean = false, TParent extends AbstractTable<any> = any> extends AbstractColumn<T, TNullable, TAutoIncrement, TParent> {
47
54
  constructor(parent: TParent, columnName: string, columnType: T);
55
+ defaultValue: (value: ExtractColumnType<T> | RawSqlValue) => Column<T, true, TAutoIncrement, TParent>;
48
56
  notNull(): Column<T, TAutoIncrement extends true ? true : TNullable extends true ? false : true, TAutoIncrement, TParent>;
49
57
  primaryKey(): Column<T, TAutoIncrement extends true ? true : false, TAutoIncrement, TParent>;
50
58
  foreignKey<ITable extends AbstractTable<ITable>>(table: new (db: DB) => ITable, callback: (table: ITable) => Column<any, boolean, boolean, ITable>, onConstraint?: {
@@ -58,6 +66,7 @@ export declare class Column<T extends ColumnType, TNullable extends boolean = tr
58
66
  }
59
67
  export declare class IndexedColumn<T extends ColumnType, TNullable extends boolean = true, TAutoIncrement extends boolean = false, TParent extends AbstractTable<any> = any> extends AbstractColumn<T, TNullable, TAutoIncrement, TParent> {
60
68
  constructor(parent: TParent, columnName: string, columnType: T, nullable: TNullable);
69
+ defaultValue: (value: ExtractColumnType<T> | RawSqlValue) => IndexedColumn<T, true, TAutoIncrement, TParent>;
61
70
  notNull(): IndexedColumn<T, TAutoIncrement extends true ? true : TNullable extends true ? false : true, TAutoIncrement, TParent>;
62
71
  primaryKey(): IndexedColumn<T, TAutoIncrement extends true ? true : false, TAutoIncrement, TParent>;
63
72
  foreignKey<ITable extends AbstractTable<ITable>>(table: new (db: DB) => ITable, callback: (table: ITable) => Column<any, boolean, boolean, ITable>, onConstraint?: {
package/columns/column.js CHANGED
@@ -1,32 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IndexedColumn = exports.Column = exports.AbstractColumn = exports.Defaults = void 0;
4
- var Defaults;
5
- (function (Defaults) {
6
- Defaults["CURRENT_TIMESTAMP"] = "CURRENT_TIMESTAMP";
7
- })(Defaults = exports.Defaults || (exports.Defaults = {}));
3
+ exports.IndexedColumn = exports.Column = exports.AbstractColumn = exports.rawValue = exports.Defaults = void 0;
4
+ class RawSqlValue {
5
+ constructor(value, escape) {
6
+ this.value = value;
7
+ this.escape = escape;
8
+ }
9
+ toJSON() {
10
+ return this.escape ? `'${this.value}'` : this.value;
11
+ }
12
+ }
13
+ exports.Defaults = {
14
+ CURRENT_TIMESTAMP: new RawSqlValue('CURRENT_TIMESTAMP', false),
15
+ };
16
+ const rawValue = (value) => new RawSqlValue(value, false);
17
+ exports.rawValue = rawValue;
8
18
  // eslint-disable-next-line max-len
9
19
  class AbstractColumn {
10
20
  constructor(parent, columnName, columnType) {
11
21
  this.isNullableFlag = true;
12
- this.defaultParam = null;
13
22
  this.getOnDelete = () => this.onDelete;
14
23
  this.getOnUpdate = () => this.onUpdate;
15
24
  this.getAlias = () => `${this.parentTableName.replace('.', '_')}_${this.columnName}`;
16
25
  this.getParent = () => this.parent;
17
26
  this.getParentName = () => this.parentTableName;
18
- this.defaultValue = (value) => {
19
- if (Defaults[value] !== undefined) {
20
- this.defaultParam = value;
21
- }
22
- else if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'bigint') {
23
- this.defaultParam = value;
24
- }
25
- else {
26
- this.defaultParam = `'${value}'`;
27
- }
28
- return this;
29
- };
30
27
  this.unique = () => {
31
28
  this.uniqueKeyName = this.columnName;
32
29
  return this;
@@ -40,12 +37,28 @@ class AbstractColumn {
40
37
  this.parentTableName = parent.tableName();
41
38
  this.parent = parent;
42
39
  }
40
+ defaultValue(value) {
41
+ if (value instanceof RawSqlValue) {
42
+ this.defaultParam = value;
43
+ }
44
+ else if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'bigint') {
45
+ this.defaultParam = new RawSqlValue(value, false);
46
+ }
47
+ else {
48
+ this.defaultParam = new RawSqlValue(`${value}`, true);
49
+ }
50
+ return this;
51
+ }
43
52
  }
44
53
  exports.AbstractColumn = AbstractColumn;
45
54
  // eslint-disable-next-line max-len
46
55
  class Column extends AbstractColumn {
47
56
  constructor(parent, columnName, columnType) {
48
57
  super(parent, columnName, columnType);
58
+ this.defaultValue = (value) => {
59
+ super.defaultValue(value);
60
+ return this;
61
+ };
49
62
  }
50
63
  notNull() {
51
64
  this.isNullableFlag = false;
@@ -74,6 +87,10 @@ exports.Column = Column;
74
87
  class IndexedColumn extends AbstractColumn {
75
88
  constructor(parent, columnName, columnType, nullable) {
76
89
  super(parent, columnName, columnType);
90
+ this.defaultValue = (value) => {
91
+ super.defaultValue(value);
92
+ return this;
93
+ };
77
94
  }
78
95
  notNull() {
79
96
  this.isNullableFlag = false;
@@ -1,4 +1,4 @@
1
- export { Column, ExtractColumnType, Defaults } from './column';
1
+ export { Column, ExtractColumnType, Defaults, rawValue, } from './column';
2
2
  export { default as PgBigDecimal } from './types/pgBigDecimal';
3
3
  export { default as PgBigInt } from './types/pgBigInt';
4
4
  export { default as PgBoolean } from './types/pgBoolean';
package/columns/index.js CHANGED
@@ -3,10 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PgVarChar = exports.PgTimestamp = exports.PgTime = exports.PgText = exports.PgJsonb = exports.PgInteger = exports.PgBoolean = exports.PgBigInt = exports.PgBigDecimal = exports.Defaults = exports.Column = void 0;
6
+ exports.PgVarChar = exports.PgTimestamp = exports.PgTime = exports.PgText = exports.PgJsonb = exports.PgInteger = exports.PgBoolean = exports.PgBigInt = exports.PgBigDecimal = exports.rawValue = exports.Defaults = exports.Column = void 0;
7
+ /* eslint-disable import/no-cycle */
7
8
  var column_1 = require("./column");
8
9
  Object.defineProperty(exports, "Column", { enumerable: true, get: function () { return column_1.Column; } });
9
10
  Object.defineProperty(exports, "Defaults", { enumerable: true, get: function () { return column_1.Defaults; } });
11
+ Object.defineProperty(exports, "rawValue", { enumerable: true, get: function () { return column_1.rawValue; } });
10
12
  var pgBigDecimal_1 = require("./types/pgBigDecimal");
11
13
  Object.defineProperty(exports, "PgBigDecimal", { enumerable: true, get: function () { return __importDefault(pgBigDecimal_1).default; } });
12
14
  var pgBigInt_1 = require("./types/pgBigInt");
@@ -0,0 +1,9 @@
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
+ }
@@ -0,0 +1,22 @@
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;
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,15 @@
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;
@@ -0,0 +1,17 @@
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
+ }
@@ -0,0 +1,31 @@
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;
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,20 @@
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-orm",
3
- "version": "0.10.36",
3
+ "version": "0.10.39",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,9 +10,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  const columns_1 = require("../columns");
12
12
  const tableIndex_1 = __importDefault(require("../indexes/tableIndex"));
13
- const serialiseForeignKey = (fkName, table, column, onDelete, onUpdate) => {
14
- return `${fkName};${table};${column};${onDelete !== null && onDelete !== void 0 ? onDelete : ''};${onUpdate !== null && onUpdate !== void 0 ? onUpdate : ''}`;
15
- };
13
+ // eslint-disable-next-line max-len
14
+ const serialiseForeignKey = (fkName, table, column, onDelete, onUpdate) => `${fkName};${table};${column};${onDelete !== null && onDelete !== void 0 ? onDelete : ''};${onUpdate !== null && onUpdate !== void 0 ? onUpdate : ''}`;
16
15
  class MigrationSerializer {
17
16
  constructor() {
18
17
  this.generate = (tables, enums) => {
@@ -49,7 +48,7 @@ class MigrationSerializer {
49
48
  notNull: !value.isNullableFlag,
50
49
  };
51
50
  if (value.getDefaultValue() !== undefined && value.getDefaultValue() !== null) {
52
- columnToReturn[value.getColumnName()].default = value.getDefaultValue();
51
+ columnToReturn[value.getColumnName()].default = value.getDefaultValue().toJSON();
53
52
  }
54
53
  if (value.uniqueKeyName) {
55
54
  const indexName = `${value.getParent().tableName()}_${value.getColumnName()}_index`;
@@ -66,11 +65,12 @@ class MigrationSerializer {
66
65
  const referenced = value.getReferenced();
67
66
  if (referenced) {
68
67
  const fkName = `${value.getParent().tableName()}_${value.getColumnName()}_fkey`;
69
- const table = referenced.getParentName();
68
+ const tableParentName = referenced.getParentName();
70
69
  const column = referenced.getColumnName();
71
70
  const onDelete = value.getOnDelete();
72
71
  const onUpdate = value.getOnUpdate();
73
- const referenceString = serialiseForeignKey(fkName, table, column, onDelete, onUpdate);
72
+ // eslint-disable-next-line max-len
73
+ const referenceString = serialiseForeignKey(fkName, tableParentName, column, onDelete, onUpdate);
74
74
  columnToReturn[value.getColumnName()].references = referenceString;
75
75
  }
76
76
  }
@@ -162,6 +162,7 @@ class MigrationSerializer {
162
162
  const foreignKeyName = fk.constraint_name;
163
163
  const onUpdate = fk.update_rule;
164
164
  const onDelete = fk.delete_rule;
165
+ // eslint-disable-next-line max-len
165
166
  const references = serialiseForeignKey(foreignKeyName, tableTo, columnTo, onDelete, onUpdate);
166
167
  mappedRefernces[columnFrom] = references;
167
168
  }
package/test.js CHANGED
@@ -3,47 +3,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const static_1 = require("./builders/requestBuilders/where/static");
7
6
  const dbConnector_1 = __importDefault(require("./db/dbConnector"));
8
- const citiesTable_1 = __importDefault(require("./docs/tables/citiesTable"));
9
7
  const usersTable_1 = __importDefault(require("./docs/tables/usersTable"));
10
8
  const consoleLogger_1 = __importDefault(require("./logger/consoleLogger"));
9
+ const serializer_1 = __importDefault(require("./serializer/serializer"));
11
10
  (async () => {
12
11
  try {
13
12
  const db = await new dbConnector_1.default()
14
13
  .connectionString('postgresql://postgres@127.0.0.1/migrator')
15
14
  .connect();
16
- const usersTable = new usersTable_1.default(db);
17
- const citiesTable = new citiesTable_1.default(db);
18
15
  db.useLogger(new consoleLogger_1.default());
19
- const phone = undefined;
20
- const res = await usersTable.update()
21
- // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
22
- .where(static_1.eq(usersTable.id, 16))
23
- .set({
24
- phone,
25
- })
26
- // .leftJoin(CitiesTable, UsersTable, (table) => table.userId, (table) => table.id)
27
- // .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
28
- .execute();
29
- // const ser = new MigrationSerializer();
30
- // const res = ser.generate([usersTable as AbstractTable<UsersTable>], []);
31
- // console.log(JSON.stringify(res, null, 2));
16
+ const usersTable = new usersTable_1.default(db);
17
+ // const citiesTable = new CitiesTable(db);
18
+ // await usersTable.insert({
19
+ // });
20
+ // const res = await citiesTable.update()
21
+ // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
22
+ // .where(eq(citiesTable.location, 'YR'))
23
+ // .set({
24
+ // metadata: [{
25
+ // fallback_image: true,
26
+ // team_image: 'https://files.slack.com/files-pri/T016CCC3FE3-F03461UR9M5/clinic_team_photo_1.jpg?pub_secret=560c098bfb',
27
+ // image_alt_text: 'Generic Physiotherapy Clinic image 1',
28
+ // logo: '',
29
+ // logo_alt_text: ''
30
+ // }],
31
+ // })
32
+ // // .leftJoin(CitiesTable, UsersTable, (table) => table.userId, (table) => table.id)
33
+ // // .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
34
+ // .execute();
35
+ // console.log(res);
36
+ const ser = new serializer_1.default();
37
+ const res = ser.generate([usersTable], []);
38
+ console.log(JSON.stringify(res, null, 2));
32
39
  // const f = {
33
40
  // id: count(usersTable.id),
34
41
  // };
35
42
  // type d = ExtractModel<typeof f>;
36
- // const res = await usersTable.select({
37
- // piska: count(),
38
- // mongodibil: count(usersTable.phone),
39
- // })
40
- // .where({
41
- // piska: eq(),
42
- // mongodibil: eq(usersTable.phone),
43
- // }).leftJoin(UsersTable, (table) => table.id, (table) => table.id)
44
- // .leftJoin(UsersTable, UsersTable, (table) => table.id, (table) => table.id)
45
- // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])
46
- // .orderBy((table, join1, join2, join3) => [{table.id}, join1.id, join1.phone])
43
+ // const res = await usersTable.select()
44
+ // .leftJoin(UsersTable, (table) => table.id, (table) => table.id)
45
+ // .leftJoin(UsersTable, CitiesTable, (table) => table.id, (table) => table.id)
47
46
  // .execute();
48
47
  // const res = await usersTable.select()
49
48
  // // .groupBy((table, join1, join2, join3) => [table.id, join1.id, join1.phone])