drizzle-orm 0.10.44 → 0.10.45

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/db/session.d.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { Pool, 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
+ protected abstract _execute(query: string, values?: Array<any>): Promise<QueryResult<any>>;
6
7
  }
7
8
  export default class Session extends ISession {
8
9
  private pool;
9
10
  constructor(pool: Pool);
10
- execute(query: string, values?: Array<any>): Promise<QueryResult<any>>;
11
11
  parametrized(num: number): string;
12
+ protected _execute(query: string, values?: Array<any>): Promise<QueryResult<any>>;
12
13
  }
package/db/session.js CHANGED
@@ -5,6 +5,16 @@ 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 {
@@ -12,11 +22,11 @@ class Session extends ISession {
12
22
  super();
13
23
  this.pool = pool;
14
24
  }
15
- async execute(query, values) {
16
- return this.pool.query(query, values || []);
17
- }
18
25
  parametrized(num) {
19
26
  return `$${num}`;
20
27
  }
28
+ async _execute(query, values) {
29
+ return this.pool.query(query, values || []);
30
+ }
21
31
  }
22
32
  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.45",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,19 +18,21 @@
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",
21
22
  "eslint": "7.15.0",
22
23
  "eslint-config-airbnb-typescript": "12.0.0",
23
24
  "eslint-plugin-import": "2.22.1",
24
25
  "eslint-plugin-prefer-arrow": "1.2.2",
25
26
  "ts-node": "^10.0.0",
26
- "typescript": "4.2.4"
27
+ "typescript": "4.2.4",
28
+ "uvu": "^0.5.3"
27
29
  },
28
30
  "dependencies": {
29
31
  "@types/pg": "^8.6.1",
30
32
  "pg": "^8.6.0"
31
33
  },
32
34
  "scripts": {
33
- "test": "echo \"Error: no test specified\" && exit 1",
35
+ "test": "uvu -r ts-node/register tests",
34
36
  "ts": "tsc",
35
37
  "lint": "eslint ./src --ext .ts",
36
38
  "run": "ts-node src/tables/newAbstractTable.ts"
package/test.js CHANGED
@@ -7,7 +7,7 @@ const dbConnector_1 = __importDefault(require("./db/dbConnector"));
7
7
  const session_1 = require("./db/session");
8
8
  const usersTable_1 = __importDefault(require("./docs/tables/usersTable"));
9
9
  class KnexSession extends session_1.ISession {
10
- execute(query, values) {
10
+ _execute(query, values) {
11
11
  console.log(query);
12
12
  console.log(values);
13
13
  return { rows: [] };
@@ -46,7 +46,7 @@ class KnexSession extends session_1.ISession {
46
46
  isArchived: false,
47
47
  role: 'bar',
48
48
  decimalField: 12,
49
- phone: ' tedss\'t',
49
+ phone: '12',
50
50
  media: [' tes\'t', ' t\'es\'t'],
51
51
  createdAt: new Date(),
52
52
  }).execute();
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;