orchid-orm 1.5.8 → 1.5.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orchid-orm",
3
- "version": "1.5.8",
3
+ "version": "1.5.10",
4
4
  "description": "Postgres ORM",
5
5
  "homepage": "https://orchid-orm.netlify.app/guide/orm-setup-and-overview.html",
6
6
  "repository": {
@@ -39,14 +39,14 @@
39
39
  "author": "Roman Kushyn",
40
40
  "license": "ISC",
41
41
  "dependencies": {
42
- "pqb": "0.9.6"
42
+ "pqb": "0.9.8"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@swc/core": "^1.3.19",
46
46
  "rollup": "^2.79.0",
47
47
  "rollup-plugin-dts": "^4.2.2",
48
48
  "rollup-plugin-esbuild": "^4.10.1",
49
- "orchid-orm-schema-to-zod": "0.2.12",
49
+ "orchid-orm-schema-to-zod": "0.2.14",
50
50
  "@swc/jest": "^0.2.21",
51
51
  "@types/jest": "^28.1.2",
52
52
  "@types/node": "^18.0.1",
@@ -58,7 +58,7 @@
58
58
  "rimraf": "^3.0.2",
59
59
  "tslib": "^2.4.0",
60
60
  "typescript": "^4.7.4",
61
- "rake-db": "2.3.9"
61
+ "rake-db": "2.3.13"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "typescript": "*"
@@ -34,13 +34,8 @@ describe('createBaseTableFile', () => {
34
34
  expect(asMock(fs.writeFile)).toBeCalledWith(
35
35
  params.baseTablePath,
36
36
  `import { createBaseTable } from 'orchid-orm';
37
- import { columnTypes } from 'pqb';
38
37
 
39
- export const ${params.baseTableName} = createBaseTable({
40
- columnTypes: {
41
- ...columnTypes,
42
- },
43
- });
38
+ export const ${params.baseTableName} = createBaseTable();
44
39
  `,
45
40
  {
46
41
  flag: 'wx',
@@ -17,13 +17,8 @@ export const createBaseTableFile = async ({
17
17
  .writeFile(
18
18
  baseTablePath,
19
19
  `import { createBaseTable } from 'orchid-orm';
20
- import { columnTypes } from 'pqb';
21
20
 
22
- export const ${baseTableName} = createBaseTable({
23
- columnTypes: {
24
- ...columnTypes,
25
- },
26
- });
21
+ export const ${baseTableName} = createBaseTable();
27
22
  `,
28
23
  {
29
24
  flag: 'wx',
package/src/index.ts CHANGED
@@ -2,3 +2,4 @@ export * from './table';
2
2
  export * from './orm';
3
3
  export * from './repo';
4
4
  export * from './codegen/appCodeUpdater';
5
+ export { columnTypes } from 'pqb';
package/src/orm.test.ts CHANGED
@@ -7,25 +7,19 @@ import {
7
7
  } from './test-utils/test-utils';
8
8
  import { pgConfig } from './test-utils/test-db';
9
9
  import { createBaseTable } from './table';
10
- import { columnTypes } from 'pqb';
11
10
 
12
11
  describe('orm', () => {
13
12
  useTestDatabase();
14
13
 
15
- const BaseTable = createBaseTable({
16
- columnTypes: {
17
- ...columnTypes,
18
- text: (min = 0, max = Infinity) => columnTypes.text(min, max),
19
- },
20
- });
14
+ const BaseTable = createBaseTable();
21
15
 
22
16
  type User = UserTable['columns']['type'];
23
17
  class UserTable extends BaseTable {
24
18
  table = 'user';
25
19
  columns = this.setColumns((t) => ({
26
20
  id: t.serial().primaryKey(),
27
- name: t.text(),
28
- password: t.text(),
21
+ name: t.text(1, 10),
22
+ password: t.text(1, 10),
29
23
  }));
30
24
  }
31
25
 
package/src/repo.test.ts CHANGED
@@ -2,10 +2,10 @@ import { orchidORM } from './orm';
2
2
  import { pgConfig } from './test-utils/test-db';
3
3
  import { createBaseTable } from './table';
4
4
  import { assertType, expectSql } from './test-utils/test-utils';
5
- import { columnTypes, QueryReturnType } from 'pqb';
5
+ import { QueryReturnType } from 'pqb';
6
6
  import { createRepo } from './repo';
7
7
 
8
- const BaseTable = createBaseTable({ columnTypes });
8
+ const BaseTable = createBaseTable();
9
9
 
10
10
  class SomeTable extends BaseTable {
11
11
  table = 'someTable';
package/src/table.test.ts CHANGED
@@ -42,7 +42,7 @@ describe('table', () => {
42
42
  it('should return date as string by default', async () => {
43
43
  await db.user.create(userData);
44
44
 
45
- const BaseTable = createBaseTable({ columnTypes });
45
+ const BaseTable = createBaseTable();
46
46
  class UserTable extends BaseTable {
47
47
  table = 'user';
48
48
  columns = this.setColumns((t) => ({
package/src/table.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  ColumnShapeOutput,
3
3
  ColumnsShape,
4
+ columnTypes,
4
5
  ColumnTypesBase,
5
6
  Db,
7
+ DefaultColumnTypes,
6
8
  getColumnTypes,
7
9
  Query,
8
10
  } from 'pqb';
@@ -46,9 +48,17 @@ export type Table = {
46
48
  noPrimaryKey?: boolean;
47
49
  };
48
50
 
49
- export const createBaseTable = <CT extends ColumnTypesBase>(options: {
50
- columnTypes: CT;
51
- }) => {
51
+ export const createBaseTable = <CT extends ColumnTypesBase>(
52
+ options: {
53
+ columnTypes?: CT;
54
+ } = { columnTypes: columnTypes as unknown as CT },
55
+ ) => {
56
+ return create(
57
+ options.columnTypes as ColumnTypesBase extends CT ? DefaultColumnTypes : CT,
58
+ );
59
+ };
60
+
61
+ const create = <CT extends ColumnTypesBase>(columnTypes: CT) => {
52
62
  return class BaseTable {
53
63
  table!: string;
54
64
  columns!: TableConfig;
@@ -57,13 +67,13 @@ export const createBaseTable = <CT extends ColumnTypesBase>(options: {
57
67
  noPrimaryKey?: boolean;
58
68
 
59
69
  constructor() {
60
- this.columnTypes = options.columnTypes;
70
+ this.columnTypes = columnTypes;
61
71
  }
62
72
 
63
73
  setColumns = <T extends ColumnsShape>(
64
74
  fn: (t: CT) => T,
65
75
  ): { shape: T; type: ColumnShapeOutput<T> } => {
66
- const shape = getColumnTypes(options.columnTypes, fn);
76
+ const shape = getColumnTypes(columnTypes, fn);
67
77
 
68
78
  return {
69
79
  shape,