pqb 0.7.13 → 0.8.1
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 +12 -0
- package/dist/index.d.ts +618 -563
- package/dist/index.esm.js +1011 -402
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1014 -401
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/columnSchema/array.test.ts +67 -0
- package/src/columnSchema/array.ts +39 -13
- package/src/columnSchema/boolean.test.ts +17 -0
- package/src/columnSchema/boolean.ts +5 -1
- package/src/columnSchema/columnType.test.ts +230 -107
- package/src/columnSchema/columnType.ts +198 -28
- package/src/columnSchema/columnTypes.ts +28 -15
- package/src/columnSchema/columnsSchema.ts +6 -4
- package/src/columnSchema/commonMethods.ts +11 -4
- package/src/columnSchema/dateTime.test.ts +298 -0
- package/src/columnSchema/dateTime.ts +59 -2
- package/src/columnSchema/enum.test.ts +33 -0
- package/src/columnSchema/enum.ts +11 -1
- package/src/columnSchema/json/array.test.ts +21 -0
- package/src/columnSchema/json/array.ts +27 -13
- package/src/columnSchema/json/discriminatedUnion.test.ts +32 -0
- package/src/columnSchema/json/discriminatedUnion.ts +17 -2
- package/src/columnSchema/json/enum.test.ts +9 -0
- package/src/columnSchema/json/enum.ts +9 -1
- package/src/columnSchema/json/index.ts +19 -19
- package/src/columnSchema/json/instanceOf.test.ts +8 -0
- package/src/columnSchema/json/instanceOf.ts +4 -1
- package/src/columnSchema/json/intersection.test.ts +19 -0
- package/src/columnSchema/json/intersection.ts +9 -1
- package/src/columnSchema/json/lazy.test.ts +22 -0
- package/src/columnSchema/json/lazy.ts +22 -1
- package/src/columnSchema/json/literal.test.ts +7 -0
- package/src/columnSchema/json/literal.ts +12 -1
- package/src/columnSchema/json/map.test.ts +10 -0
- package/src/columnSchema/json/map.ts +21 -1
- package/src/columnSchema/json/nativeEnum.test.ts +10 -0
- package/src/columnSchema/json/nativeEnum.ts +4 -1
- package/src/columnSchema/json/nullable.test.ts +18 -0
- package/src/columnSchema/json/nullish.test.ts +18 -0
- package/src/columnSchema/json/object.test.ts +77 -0
- package/src/columnSchema/json/object.ts +31 -3
- package/src/columnSchema/json/optional.test.ts +18 -0
- package/src/columnSchema/json/record.test.ts +14 -0
- package/src/columnSchema/json/record.ts +12 -1
- package/src/columnSchema/json/scalarTypes.test.ts +133 -0
- package/src/columnSchema/json/scalarTypes.ts +90 -1
- package/src/columnSchema/json/set.test.ts +29 -0
- package/src/columnSchema/json/set.ts +26 -7
- package/src/columnSchema/json/tuple.test.ts +17 -0
- package/src/columnSchema/json/tuple.ts +16 -1
- package/src/columnSchema/json/typeBase.test.ts +123 -0
- package/src/columnSchema/json/typeBase.ts +52 -13
- package/src/columnSchema/json/union.test.ts +10 -0
- package/src/columnSchema/json/union.ts +18 -1
- package/src/columnSchema/json.test.ts +17 -0
- package/src/columnSchema/json.ts +10 -2
- package/src/columnSchema/number.test.ts +176 -0
- package/src/columnSchema/number.ts +48 -1
- package/src/columnSchema/string.test.ts +412 -0
- package/src/columnSchema/string.ts +126 -15
- package/src/columnSchema/timestamps.test.ts +6 -6
- package/src/columnSchema/virtual.ts +4 -0
- package/src/db.ts +1 -1
- package/src/query.ts +1 -1
- package/src/queryMethods/create.ts +6 -6
- package/src/queryMethods/for.ts +3 -3
- package/src/queryMethods/having.ts +1 -1
- package/src/queryMethods/join.ts +4 -4
- package/src/queryMethods/json.ts +1 -1
- package/src/queryMethods/queryMethods.ts +2 -2
- package/src/queryMethods/select.ts +3 -3
- package/src/queryMethods/update.ts +17 -17
- package/src/queryMethods/where.test.ts +1 -1
- package/src/queryMethods/where.ts +4 -4
- package/src/relations.ts +1 -1
- package/src/sql/aggregate.ts +2 -2
- package/src/sql/copy.ts +3 -3
- package/src/sql/delete.ts +5 -5
- package/src/sql/fromAndAs.ts +4 -4
- package/src/sql/having.ts +7 -7
- package/src/sql/insert.ts +5 -5
- package/src/sql/join.ts +16 -16
- package/src/sql/select.ts +6 -6
- package/src/sql/toSql.ts +24 -24
- package/src/sql/update.ts +4 -4
- package/src/sql/where.ts +18 -18
- package/src/utils.test.ts +9 -0
- package/src/utils.ts +3 -0
- package/src/columnSchema/columnTypes.test.ts +0 -527
package/package.json
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { assertType, db } from '../test-utils/test-utils';
|
|
2
|
+
import { ArrayColumn } from './array';
|
|
3
|
+
import { IntegerColumn } from './number';
|
|
4
|
+
|
|
5
|
+
describe('array column', () => {
|
|
6
|
+
describe('array', () => {
|
|
7
|
+
it('should output nested array of numbers', async () => {
|
|
8
|
+
const result = await db.get(
|
|
9
|
+
db.raw(
|
|
10
|
+
(t) => new ArrayColumn(new ArrayColumn(t.integer())),
|
|
11
|
+
`'{{1, 2, 3}, {4, 5, 6}}'::integer[][]`,
|
|
12
|
+
),
|
|
13
|
+
);
|
|
14
|
+
expect(result).toEqual([
|
|
15
|
+
[1, 2, 3],
|
|
16
|
+
[4, 5, 6],
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
assertType<typeof result, number[][]>();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should output nested array of strings', async () => {
|
|
23
|
+
const result = await db.get(
|
|
24
|
+
db.raw(
|
|
25
|
+
(t) => new ArrayColumn(new ArrayColumn(t.text())),
|
|
26
|
+
`'{{"a", "b"}, {"c", "d"}}'::text[][]`,
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
expect(result).toEqual([
|
|
30
|
+
['a', 'b'],
|
|
31
|
+
['c', 'd'],
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
assertType<typeof result, string[][]>();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should output nested array of booleans', async () => {
|
|
38
|
+
const result = await db.get(
|
|
39
|
+
db.raw(
|
|
40
|
+
(t) => new ArrayColumn(new ArrayColumn(t.boolean())),
|
|
41
|
+
`'{{true}, {false}}'::text[][]`,
|
|
42
|
+
),
|
|
43
|
+
);
|
|
44
|
+
expect(result).toEqual([[true], [false]]);
|
|
45
|
+
|
|
46
|
+
assertType<typeof result, boolean[][]>();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should have toCode', async () => {
|
|
50
|
+
const column = new ArrayColumn(new IntegerColumn());
|
|
51
|
+
expect(column.toCode('t')).toEqual(['t.array(', 't.integer()', ')']);
|
|
52
|
+
|
|
53
|
+
expect(column.nonEmpty().toCode('t')).toEqual([
|
|
54
|
+
't.array(',
|
|
55
|
+
't.integer()',
|
|
56
|
+
')',
|
|
57
|
+
'.nonEmpty()',
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
expect(column.min(1).max(10).length(15).toCode('t')).toEqual([
|
|
61
|
+
't.array(',
|
|
62
|
+
't.integer()',
|
|
63
|
+
').min(1).max(10).length(15)',
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { ColumnData, ColumnType } from './columnType';
|
|
1
|
+
import { Code, columnCode, ColumnData, ColumnType } from './columnType';
|
|
2
2
|
import { Operators } from '../columnsOperators';
|
|
3
3
|
import { assignMethodsToClass } from './utils';
|
|
4
4
|
import { arrayMethods } from './commonMethods';
|
|
5
|
+
import { toArray } from '../utils';
|
|
5
6
|
|
|
6
7
|
export type ArrayData<Item extends ColumnType> = ColumnData & {
|
|
7
8
|
item: Item;
|
|
8
9
|
min?: number;
|
|
9
10
|
max?: number;
|
|
10
11
|
length?: number;
|
|
12
|
+
isNonEmpty?: true;
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
type ArrayMethods = typeof arrayMethods;
|
|
@@ -34,18 +36,42 @@ export class ArrayColumn<Item extends ColumnType> extends ColumnType<
|
|
|
34
36
|
return `${this.data.item.toSQL()}[]`;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
toCode(this: ArrayColumn<Item>, t: string): Code {
|
|
40
|
+
let code = ')';
|
|
41
|
+
|
|
42
|
+
const { min, max, length, isNonEmpty } = this.data;
|
|
43
|
+
|
|
44
|
+
if (min !== undefined && (!isNonEmpty || (isNonEmpty && min !== 1)))
|
|
45
|
+
code += `.min(${min})`;
|
|
46
|
+
|
|
47
|
+
if (max !== undefined) code += `.max(${max})`;
|
|
48
|
+
|
|
49
|
+
if (length !== undefined) code += `.length(${length})`;
|
|
50
|
+
|
|
51
|
+
return columnCode(this, t, [
|
|
52
|
+
't.array(',
|
|
53
|
+
...toArray(this.data.item.toCode(t)),
|
|
54
|
+
code,
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
parseFn = Object.assign(
|
|
59
|
+
(input: unknown) => {
|
|
60
|
+
const entries: unknown[] = [];
|
|
61
|
+
parseArray(
|
|
62
|
+
input as string,
|
|
63
|
+
0,
|
|
64
|
+
(input as string).length,
|
|
65
|
+
entries,
|
|
66
|
+
false,
|
|
67
|
+
this.data.item,
|
|
68
|
+
);
|
|
69
|
+
return entries;
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
hideFromCode: true,
|
|
73
|
+
},
|
|
74
|
+
);
|
|
49
75
|
}
|
|
50
76
|
|
|
51
77
|
const parseArray = (
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { assertType, db } from '../test-utils/test-utils';
|
|
2
|
+
import { BooleanColumn } from './boolean';
|
|
3
|
+
|
|
4
|
+
describe('boolean column', () => {
|
|
5
|
+
it('should output boolean', async () => {
|
|
6
|
+
const result = await db.get(db.raw(() => new BooleanColumn(), `true`));
|
|
7
|
+
expect(result).toBe(true);
|
|
8
|
+
|
|
9
|
+
assertType<typeof result, boolean>();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should have toCode', () => {
|
|
13
|
+
const column = new BooleanColumn();
|
|
14
|
+
|
|
15
|
+
expect(column.toCode('t')).toBe('t.boolean()');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ColumnType } from './columnType';
|
|
1
|
+
import { Code, columnCode, ColumnType } from './columnType';
|
|
2
2
|
import { Operators } from '../columnsOperators';
|
|
3
3
|
|
|
4
4
|
// 1 byte, true or false
|
|
@@ -9,5 +9,9 @@ export class BooleanColumn extends ColumnType<
|
|
|
9
9
|
dataType = 'boolean' as const;
|
|
10
10
|
operators = Operators.boolean;
|
|
11
11
|
|
|
12
|
+
toCode(t: string): Code {
|
|
13
|
+
return columnCode(this, t, `${t}.boolean()`);
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
parseItem = (input: string) => input[0] === 't';
|
|
13
17
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ColumnType } from './columnType';
|
|
1
|
+
import { Code, columnCode, ColumnType } from './columnType';
|
|
2
2
|
import { Operators } from '../columnsOperators';
|
|
3
3
|
import {
|
|
4
4
|
adapter,
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from '../test-utils/test-utils';
|
|
12
12
|
import { createDb } from '../db';
|
|
13
13
|
import { columnTypes } from './columnTypes';
|
|
14
|
+
import { IntegerColumn } from './number';
|
|
14
15
|
|
|
15
16
|
describe('column base', () => {
|
|
16
17
|
useTestDatabase();
|
|
@@ -18,6 +19,9 @@ describe('column base', () => {
|
|
|
18
19
|
class Column extends ColumnType {
|
|
19
20
|
dataType = 'test';
|
|
20
21
|
operators = Operators.any;
|
|
22
|
+
toCode(t: string): Code {
|
|
23
|
+
return columnCode(this, t, `${t}.column()`);
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
26
|
const column = new Column();
|
|
23
27
|
|
|
@@ -26,6 +30,63 @@ describe('column base', () => {
|
|
|
26
30
|
expect(column.isPrimaryKey).toBe(false);
|
|
27
31
|
expect(column.primaryKey().isPrimaryKey).toBe(true);
|
|
28
32
|
});
|
|
33
|
+
|
|
34
|
+
it('should have toCode', () => {
|
|
35
|
+
expect(column.primaryKey().toCode('t')).toEqual([
|
|
36
|
+
't.column()',
|
|
37
|
+
'.primaryKey()',
|
|
38
|
+
]);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('.foreignKey', () => {
|
|
43
|
+
it('should have toCode', () => {
|
|
44
|
+
class Table {
|
|
45
|
+
table = 'table';
|
|
46
|
+
columns = { shape: { column: new IntegerColumn() } };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
expect(column.foreignKey(() => Table, 'column').toCode('t')).toEqual([
|
|
50
|
+
't.column()',
|
|
51
|
+
'.foreignKey(',
|
|
52
|
+
'()=>Table',
|
|
53
|
+
`, 'column'`,
|
|
54
|
+
')',
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
expect(column.foreignKey('table', 'column').toCode('t')).toEqual([
|
|
58
|
+
't.column()',
|
|
59
|
+
'.foreignKey(',
|
|
60
|
+
`'table'`,
|
|
61
|
+
`, 'column'`,
|
|
62
|
+
')',
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
expect(
|
|
66
|
+
column
|
|
67
|
+
.foreignKey('table', 'column', {
|
|
68
|
+
name: 'name',
|
|
69
|
+
match: 'FULL',
|
|
70
|
+
onUpdate: 'CASCADE',
|
|
71
|
+
onDelete: 'CASCADE',
|
|
72
|
+
})
|
|
73
|
+
.toCode('t'),
|
|
74
|
+
).toEqual([
|
|
75
|
+
't.column()',
|
|
76
|
+
'.foreignKey(',
|
|
77
|
+
`'table'`,
|
|
78
|
+
`, 'column'`,
|
|
79
|
+
', {',
|
|
80
|
+
[
|
|
81
|
+
`name: 'name',`,
|
|
82
|
+
`match: 'FULL',`,
|
|
83
|
+
`onUpdate: 'CASCADE',`,
|
|
84
|
+
`onDelete: 'CASCADE',`,
|
|
85
|
+
],
|
|
86
|
+
'}',
|
|
87
|
+
')',
|
|
88
|
+
]);
|
|
89
|
+
});
|
|
29
90
|
});
|
|
30
91
|
|
|
31
92
|
describe('.hidden', () => {
|
|
@@ -34,7 +95,11 @@ describe('column base', () => {
|
|
|
34
95
|
expect(column.hidden().isHidden).toBe(true);
|
|
35
96
|
});
|
|
36
97
|
|
|
37
|
-
|
|
98
|
+
it('should have toCode', () => {
|
|
99
|
+
expect(column.hidden().toCode('t')).toEqual(['t.column()', '.hidden()']);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('table with hidden column should omit from select it by default', () => {
|
|
38
103
|
const User = db('user', (t) => ({
|
|
39
104
|
id: t.serial().primaryKey(),
|
|
40
105
|
name: t.text(),
|
|
@@ -53,7 +118,7 @@ describe('column base', () => {
|
|
|
53
118
|
);
|
|
54
119
|
});
|
|
55
120
|
|
|
56
|
-
test('
|
|
121
|
+
test('table with hidden column still allows to select it', () => {
|
|
57
122
|
const User = db('user', (t) => ({
|
|
58
123
|
id: t.serial().primaryKey(),
|
|
59
124
|
name: t.text(),
|
|
@@ -79,9 +144,16 @@ describe('column base', () => {
|
|
|
79
144
|
expect(column.isNullable).toBe(false);
|
|
80
145
|
expect(column.nullable().isNullable).toBe(true);
|
|
81
146
|
});
|
|
147
|
+
|
|
148
|
+
it('should have toCode', () => {
|
|
149
|
+
expect(column.nullable().toCode('t')).toEqual([
|
|
150
|
+
't.column()',
|
|
151
|
+
'.nullable()',
|
|
152
|
+
]);
|
|
153
|
+
});
|
|
82
154
|
});
|
|
83
155
|
|
|
84
|
-
describe('.
|
|
156
|
+
describe('.encode', () => {
|
|
85
157
|
it('should set a function to encode value for this column', () => {
|
|
86
158
|
expect(column.encodeFn).toBe(undefined);
|
|
87
159
|
const fn = (input: number) => input.toString();
|
|
@@ -89,9 +161,15 @@ describe('column base', () => {
|
|
|
89
161
|
expect(withEncode.encodeFn).toBe(fn);
|
|
90
162
|
assertType<typeof withEncode.inputType, number>();
|
|
91
163
|
});
|
|
164
|
+
|
|
165
|
+
it('should have toCode', () => {
|
|
166
|
+
expect(
|
|
167
|
+
column.encode((input: number) => input.toString()).toCode('t'),
|
|
168
|
+
).toEqual(['t.column()', '.encode((input)=>input.toString())']);
|
|
169
|
+
});
|
|
92
170
|
});
|
|
93
171
|
|
|
94
|
-
describe('.
|
|
172
|
+
describe('.parse', () => {
|
|
95
173
|
it('should set a function to encode value for this column', () => {
|
|
96
174
|
expect(column.parseFn).toBe(undefined);
|
|
97
175
|
const fn = () => 123;
|
|
@@ -100,6 +178,13 @@ describe('column base', () => {
|
|
|
100
178
|
assertType<typeof withEncode.type, number>();
|
|
101
179
|
});
|
|
102
180
|
|
|
181
|
+
it('should have toCode', () => {
|
|
182
|
+
expect(column.parse((v) => parseInt(v as string)).toCode('t')).toEqual([
|
|
183
|
+
't.column()',
|
|
184
|
+
'.parse((v)=>parseInt(v))',
|
|
185
|
+
]);
|
|
186
|
+
});
|
|
187
|
+
|
|
103
188
|
describe('parsing columns', () => {
|
|
104
189
|
beforeEach(async () => {
|
|
105
190
|
await User.create(userData);
|
|
@@ -156,6 +241,13 @@ describe('column base', () => {
|
|
|
156
241
|
updatedAt: t.dateTimestamp(),
|
|
157
242
|
}));
|
|
158
243
|
|
|
244
|
+
it('should have toCode', () => {
|
|
245
|
+
expect(column.as(columnTypes.integer()).toCode('t')).toEqual([
|
|
246
|
+
't.column()',
|
|
247
|
+
'.as(t.integer())',
|
|
248
|
+
]);
|
|
249
|
+
});
|
|
250
|
+
|
|
159
251
|
it('should accept only column of same type and input type', () => {
|
|
160
252
|
columnTypes
|
|
161
253
|
.timestamp()
|
|
@@ -233,121 +325,152 @@ describe('column base', () => {
|
|
|
233
325
|
});
|
|
234
326
|
});
|
|
235
327
|
|
|
236
|
-
describe('
|
|
237
|
-
it('should
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}));
|
|
245
|
-
|
|
246
|
-
const now = Date.now();
|
|
247
|
-
|
|
248
|
-
const createQuery = UserWithNumberTimestamp.create({
|
|
249
|
-
...userData,
|
|
250
|
-
createdAt: now,
|
|
251
|
-
updatedAt: now,
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
expectSql(
|
|
255
|
-
createQuery.toSql(),
|
|
256
|
-
`
|
|
257
|
-
INSERT INTO "user"("name", "password", "createdAt", "updatedAt")
|
|
258
|
-
VALUES ($1, $2, $3, $4)
|
|
259
|
-
RETURNING *
|
|
260
|
-
`,
|
|
261
|
-
[userData.name, userData.password, new Date(now), new Date(now)],
|
|
262
|
-
);
|
|
263
|
-
|
|
264
|
-
const { id } = await createQuery;
|
|
265
|
-
const user = await UserWithNumberTimestamp.select(
|
|
266
|
-
'createdAt',
|
|
267
|
-
'updatedAt',
|
|
268
|
-
).find(id);
|
|
269
|
-
|
|
270
|
-
assertType<typeof user, { createdAt: number; updatedAt: number }>();
|
|
271
|
-
|
|
272
|
-
expect(typeof user.createdAt).toBe('number');
|
|
273
|
-
expect(typeof user.updatedAt).toBe('number');
|
|
274
|
-
|
|
275
|
-
const updateQuery = UserWithNumberTimestamp.find(id).update({
|
|
276
|
-
createdAt: now,
|
|
277
|
-
updatedAt: now,
|
|
278
|
-
});
|
|
328
|
+
describe('.default', () => {
|
|
329
|
+
it('should have toCode', () => {
|
|
330
|
+
expect(column.default(123).toCode('t')).toEqual([
|
|
331
|
+
't.column()',
|
|
332
|
+
'.default(123)',
|
|
333
|
+
]);
|
|
334
|
+
});
|
|
335
|
+
});
|
|
279
336
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
337
|
+
describe('.index', () => {
|
|
338
|
+
it('should have toCode', () => {
|
|
339
|
+
expect(
|
|
340
|
+
column
|
|
341
|
+
.index({
|
|
342
|
+
expression: 'expression',
|
|
343
|
+
collate: 'collate',
|
|
344
|
+
operator: 'operator',
|
|
345
|
+
order: 'order',
|
|
346
|
+
name: 'name',
|
|
347
|
+
using: 'using',
|
|
348
|
+
include: 'include',
|
|
349
|
+
with: 'with',
|
|
350
|
+
tablespace: 'tablespace',
|
|
351
|
+
where: 'where',
|
|
352
|
+
})
|
|
353
|
+
.toCode('t'),
|
|
354
|
+
).toEqual([
|
|
355
|
+
't.column()',
|
|
356
|
+
'.index(',
|
|
357
|
+
'{',
|
|
358
|
+
[
|
|
359
|
+
`expression: 'expression',`,
|
|
360
|
+
`collate: 'collate',`,
|
|
361
|
+
`operator: 'operator',`,
|
|
362
|
+
`order: 'order',`,
|
|
363
|
+
`name: 'name',`,
|
|
364
|
+
`using: 'using',`,
|
|
365
|
+
`include: 'include',`,
|
|
366
|
+
`with: 'with',`,
|
|
367
|
+
`tablespace: 'tablespace',`,
|
|
368
|
+
`where: 'where',`,
|
|
369
|
+
],
|
|
370
|
+
'}',
|
|
371
|
+
')',
|
|
372
|
+
]);
|
|
289
373
|
});
|
|
290
374
|
});
|
|
291
375
|
|
|
292
|
-
describe('
|
|
293
|
-
it('should
|
|
294
|
-
|
|
295
|
-
.
|
|
296
|
-
.
|
|
297
|
-
|
|
298
|
-
|
|
376
|
+
describe('unique', () => {
|
|
377
|
+
it('should have toCode', () => {
|
|
378
|
+
expect(column.unique().toCode('t')).toEqual([
|
|
379
|
+
't.column()',
|
|
380
|
+
'.unique(',
|
|
381
|
+
')',
|
|
382
|
+
]);
|
|
383
|
+
});
|
|
384
|
+
});
|
|
299
385
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
386
|
+
describe('comment', () => {
|
|
387
|
+
it('should have toCode', () => {
|
|
388
|
+
expect(column.comment('comment').toCode('t')).toEqual([
|
|
389
|
+
't.column()',
|
|
390
|
+
`.comment('comment')`,
|
|
391
|
+
]);
|
|
392
|
+
});
|
|
393
|
+
});
|
|
307
394
|
|
|
308
|
-
|
|
395
|
+
describe('validationDefault', () => {
|
|
396
|
+
it('should have toCode', () => {
|
|
397
|
+
expect(column.validationDefault('value').toCode('t')).toEqual([
|
|
398
|
+
't.column()',
|
|
399
|
+
`.validationDefault('value')`,
|
|
400
|
+
]);
|
|
401
|
+
|
|
402
|
+
expect(column.validationDefault(123).toCode('t')).toEqual([
|
|
403
|
+
't.column()',
|
|
404
|
+
`.validationDefault(123)`,
|
|
405
|
+
]);
|
|
406
|
+
|
|
407
|
+
expect(column.validationDefault(() => 'value').toCode('t')).toEqual([
|
|
408
|
+
't.column()',
|
|
409
|
+
`.validationDefault(()=>'value')`,
|
|
410
|
+
]);
|
|
411
|
+
});
|
|
412
|
+
});
|
|
309
413
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
414
|
+
describe('compression', () => {
|
|
415
|
+
it('should have toCode', () => {
|
|
416
|
+
expect(column.compression('compression').toCode('t')).toEqual([
|
|
417
|
+
't.column()',
|
|
418
|
+
`.compression('compression')`,
|
|
419
|
+
]);
|
|
420
|
+
});
|
|
421
|
+
});
|
|
315
422
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
);
|
|
423
|
+
describe('collate', () => {
|
|
424
|
+
it('should have toCode', () => {
|
|
425
|
+
expect(column.collate('collate').toCode('t')).toEqual([
|
|
426
|
+
't.column()',
|
|
427
|
+
`.collate('collate')`,
|
|
428
|
+
]);
|
|
429
|
+
});
|
|
430
|
+
});
|
|
325
431
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
'
|
|
330
|
-
|
|
432
|
+
describe('modifyQuery', () => {
|
|
433
|
+
it('should have toCode', () => {
|
|
434
|
+
expect(column.modifyQuery((table) => table).toCode('t')).toEqual([
|
|
435
|
+
't.column()',
|
|
436
|
+
`.modifyQuery((table)=>table)`,
|
|
437
|
+
]);
|
|
438
|
+
});
|
|
439
|
+
});
|
|
331
440
|
|
|
332
|
-
|
|
441
|
+
describe('transform', () => {
|
|
442
|
+
it('should have toCode', () => {
|
|
443
|
+
expect(column.transform((s) => s).toCode('t')).toEqual([
|
|
444
|
+
't.column()',
|
|
445
|
+
'.transform((s)=>s)',
|
|
446
|
+
]);
|
|
447
|
+
});
|
|
448
|
+
});
|
|
333
449
|
|
|
334
|
-
|
|
335
|
-
|
|
450
|
+
describe('to', () => {
|
|
451
|
+
it('should have toCode', () => {
|
|
452
|
+
expect(
|
|
453
|
+
column
|
|
454
|
+
.to((s) => parseInt(s as string), new IntegerColumn())
|
|
455
|
+
.toCode('t'),
|
|
456
|
+
).toEqual(['t.column()', '.to((s)=>parseInt(s), ', 't.integer()', ')']);
|
|
457
|
+
});
|
|
458
|
+
});
|
|
336
459
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
460
|
+
describe('refine', () => {
|
|
461
|
+
it('should have toCode', () => {
|
|
462
|
+
expect(
|
|
463
|
+
column.refine((s) => (s as string).length > 0).toCode('t'),
|
|
464
|
+
).toEqual(['t.column()', '.refine((s)=>s.length > 0)']);
|
|
465
|
+
});
|
|
466
|
+
});
|
|
341
467
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
`,
|
|
349
|
-
[now, now, id],
|
|
350
|
-
);
|
|
468
|
+
describe('superRefine', () => {
|
|
469
|
+
it('should have toCode', () => {
|
|
470
|
+
expect(column.superRefine((s) => s).toCode('t')).toEqual([
|
|
471
|
+
't.column()',
|
|
472
|
+
'.superRefine((s)=>s)',
|
|
473
|
+
]);
|
|
351
474
|
});
|
|
352
475
|
});
|
|
353
476
|
});
|