orchid-orm 1.5.10 → 1.5.11
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/CHANGELOG.md +8 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/table.test.ts +5 -5
- package/src/table.ts +7 -4
- package/src/test-utils/test-tables.ts +5 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orchid-orm",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.11",
|
|
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.
|
|
42
|
+
"pqb": "0.9.9"
|
|
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.
|
|
49
|
+
"orchid-orm-schema-to-zod": "0.2.15",
|
|
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.
|
|
61
|
+
"rake-db": "2.3.14"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"typescript": "*"
|
package/src/table.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { createBaseTable } from './table';
|
|
|
2
2
|
import { orchidORM } from './orm';
|
|
3
3
|
import { adapter, db } from './test-utils/test-db';
|
|
4
4
|
import { assertType, userData, useTestDatabase } from './test-utils/test-utils';
|
|
5
|
-
import { ColumnType,
|
|
5
|
+
import { ColumnType, Operators } from 'pqb';
|
|
6
6
|
import { BaseTable } from './test-utils/test-tables';
|
|
7
7
|
|
|
8
8
|
describe('table', () => {
|
|
@@ -68,12 +68,12 @@ describe('table', () => {
|
|
|
68
68
|
await db.user.create(userData);
|
|
69
69
|
|
|
70
70
|
const BaseTable = createBaseTable({
|
|
71
|
-
columnTypes: {
|
|
72
|
-
serial:
|
|
71
|
+
columnTypes: (t) => ({
|
|
72
|
+
serial: t.serial,
|
|
73
73
|
timestamp() {
|
|
74
|
-
return
|
|
74
|
+
return t.timestamp().parse((input) => new Date(input));
|
|
75
75
|
},
|
|
76
|
-
},
|
|
76
|
+
}),
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
class UserTable extends BaseTable {
|
package/src/table.ts
CHANGED
|
@@ -50,12 +50,15 @@ export type Table = {
|
|
|
50
50
|
|
|
51
51
|
export const createBaseTable = <CT extends ColumnTypesBase>(
|
|
52
52
|
options: {
|
|
53
|
-
columnTypes?: CT;
|
|
53
|
+
columnTypes?: CT | ((t: DefaultColumnTypes) => CT);
|
|
54
54
|
} = { columnTypes: columnTypes as unknown as CT },
|
|
55
55
|
) => {
|
|
56
|
-
|
|
57
|
-
options.columnTypes
|
|
58
|
-
|
|
56
|
+
const ct =
|
|
57
|
+
typeof options.columnTypes === 'function'
|
|
58
|
+
? options.columnTypes(columnTypes)
|
|
59
|
+
: options.columnTypes;
|
|
60
|
+
|
|
61
|
+
return create(ct as ColumnTypesBase extends CT ? DefaultColumnTypes : CT);
|
|
59
62
|
};
|
|
60
63
|
|
|
61
64
|
const create = <CT extends ColumnTypesBase>(columnTypes: CT) => {
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { createBaseTable } from '../table';
|
|
2
|
-
import { columnTypes } from 'pqb';
|
|
3
2
|
import { tableToZod } from 'orchid-orm-schema-to-zod';
|
|
4
3
|
|
|
5
4
|
export const BaseTable = createBaseTable({
|
|
6
|
-
columnTypes: {
|
|
7
|
-
...
|
|
8
|
-
text: (min = 0, max = Infinity) =>
|
|
5
|
+
columnTypes: (t) => ({
|
|
6
|
+
...t,
|
|
7
|
+
text: (min = 0, max = Infinity) => t.text(min, max),
|
|
9
8
|
timestamp() {
|
|
10
|
-
return
|
|
9
|
+
return t.timestamp().parse((input) => new Date(input));
|
|
11
10
|
},
|
|
12
|
-
},
|
|
11
|
+
}),
|
|
13
12
|
});
|
|
14
13
|
|
|
15
14
|
export type User = UserTable['columns']['type'];
|