pqb 0.2.0 → 0.2.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/dist/index.d.ts +24 -11
- package/dist/index.esm.js +1 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/columnSchema/columnType.ts +5 -1
- package/src/columnSchema/columnTypes.ts +4 -1
- package/src/db.ts +6 -1
- package/src/query.ts +2 -1
- package/src/queryMethods/insert.test.ts +78 -92
- package/src/queryMethods/insert.ts +6 -6
- package/src/queryMethods/queryMethods.test.ts +1 -1
- package/src/queryMethods/select.test.ts +2 -0
- package/src/queryMethods/update.test.ts +8 -9
- package/src/queryMethods/upsert.ts +1 -1
- package/src/queryMethods/where.test.ts +45 -45
- package/src/relations.ts +1 -1
- package/src/test-utils.ts +4 -31
|
@@ -1360,51 +1360,51 @@ export const testWhere = (
|
|
|
1360
1360
|
);
|
|
1361
1361
|
});
|
|
1362
1362
|
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1363
|
+
describe('orWhereExists', () => {
|
|
1364
|
+
testJoin(
|
|
1365
|
+
'orWhereExists',
|
|
1366
|
+
(target: string, conditions: string) => `
|
|
1367
|
+
SELECT * FROM "user"
|
|
1368
|
+
WHERE "user"."id" = $1 OR EXISTS (
|
|
1369
|
+
SELECT 1 FROM ${target}
|
|
1370
|
+
WHERE ${conditions}
|
|
1371
|
+
LIMIT 1
|
|
1372
|
+
)
|
|
1373
|
+
`,
|
|
1374
|
+
User.where({ id: 1 }),
|
|
1375
|
+
[1],
|
|
1376
|
+
);
|
|
1377
|
+
});
|
|
1378
|
+
|
|
1379
|
+
describe('whereNotExists', () => {
|
|
1380
|
+
testJoin(
|
|
1381
|
+
'whereNotExists',
|
|
1382
|
+
(target: string, conditions: string) => `
|
|
1383
|
+
SELECT * FROM "user"
|
|
1384
|
+
WHERE NOT EXISTS (
|
|
1385
|
+
SELECT 1 FROM ${target}
|
|
1386
|
+
WHERE ${conditions}
|
|
1387
|
+
LIMIT 1
|
|
1388
|
+
)
|
|
1389
|
+
`,
|
|
1390
|
+
);
|
|
1391
|
+
});
|
|
1392
|
+
|
|
1393
|
+
describe('orWhereNotExists', () => {
|
|
1394
|
+
testJoin(
|
|
1395
|
+
'orWhereNotExists',
|
|
1396
|
+
(target: string, conditions: string) => `
|
|
1397
|
+
SELECT * FROM "user"
|
|
1398
|
+
WHERE "user"."id" = $1 OR NOT EXISTS (
|
|
1399
|
+
SELECT 1 FROM ${target}
|
|
1400
|
+
WHERE ${conditions}
|
|
1401
|
+
LIMIT 1
|
|
1402
|
+
)
|
|
1403
|
+
`,
|
|
1404
|
+
User.where({ id: 1 }),
|
|
1405
|
+
[1],
|
|
1406
|
+
);
|
|
1407
|
+
});
|
|
1408
1408
|
};
|
|
1409
1409
|
|
|
1410
1410
|
export const testJoin = (
|
package/src/relations.ts
CHANGED
|
@@ -192,4 +192,4 @@ export type RelationQuery<
|
|
|
192
192
|
[isRequiredRelationKey]: Required;
|
|
193
193
|
[relationQueryKey]: string;
|
|
194
194
|
},
|
|
195
|
-
> = ((params: Params) => Q & { [defaultsKey]:
|
|
195
|
+
> = ((params: Params) => Q & { [defaultsKey]: Record<Populate, true> }) & Q;
|
package/src/test-utils.ts
CHANGED
|
@@ -44,8 +44,7 @@ export const User = db('user', (t) => ({
|
|
|
44
44
|
.nullable(),
|
|
45
45
|
age: t.integer().nullable(),
|
|
46
46
|
active: t.boolean().nullable(),
|
|
47
|
-
|
|
48
|
-
updatedAt: t.timestamp(),
|
|
47
|
+
...t.timestamps(),
|
|
49
48
|
}));
|
|
50
49
|
|
|
51
50
|
export type ProfileRecord = typeof Profile['type'];
|
|
@@ -53,15 +52,13 @@ export const Profile = db('profile', (t) => ({
|
|
|
53
52
|
id: t.serial().primaryKey(),
|
|
54
53
|
userId: t.integer().foreignKey('user', 'id'),
|
|
55
54
|
bio: t.text().nullable(),
|
|
56
|
-
|
|
57
|
-
updatedAt: t.timestamp(),
|
|
55
|
+
...t.timestamps(),
|
|
58
56
|
}));
|
|
59
57
|
|
|
60
58
|
export const Chat = db('chat', (t) => ({
|
|
61
59
|
id: t.serial().primaryKey(),
|
|
62
60
|
title: t.text(),
|
|
63
|
-
|
|
64
|
-
updatedAt: t.timestamp(),
|
|
61
|
+
...t.timestamps(),
|
|
65
62
|
}));
|
|
66
63
|
|
|
67
64
|
export type MessageRecord = typeof Message['type'];
|
|
@@ -70,8 +67,7 @@ export const Message = db('message', (t) => ({
|
|
|
70
67
|
chatId: t.integer().foreignKey('chat', 'id'),
|
|
71
68
|
authorId: t.integer().foreignKey('user', 'id'),
|
|
72
69
|
text: t.text(),
|
|
73
|
-
|
|
74
|
-
updatedAt: t.timestamp(),
|
|
70
|
+
...t.timestamps(),
|
|
75
71
|
}));
|
|
76
72
|
|
|
77
73
|
export const line = (s: string) =>
|
|
@@ -92,21 +88,6 @@ export const expectQueryNotMutated = (q: Query) => {
|
|
|
92
88
|
expectSql(q.toSql(), `SELECT * FROM "${q.table}"`);
|
|
93
89
|
};
|
|
94
90
|
|
|
95
|
-
export const expectMatchObjectWithTimestamps = (
|
|
96
|
-
actual: { createdAt: Date; updatedAt: Date },
|
|
97
|
-
expected: { createdAt: Date; updatedAt: Date },
|
|
98
|
-
) => {
|
|
99
|
-
expect({
|
|
100
|
-
...actual,
|
|
101
|
-
createdAt: actual.createdAt.toISOString(),
|
|
102
|
-
updatedAt: actual.updatedAt.toISOString(),
|
|
103
|
-
}).toMatchObject({
|
|
104
|
-
...expected,
|
|
105
|
-
createdAt: expected.createdAt.toISOString(),
|
|
106
|
-
updatedAt: expected.updatedAt.toISOString(),
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
|
|
110
91
|
export type AssertEqual<T, Expected> = [T] extends [Expected]
|
|
111
92
|
? [Expected] extends [T]
|
|
112
93
|
? true
|
|
@@ -142,26 +123,18 @@ export const now = new Date();
|
|
|
142
123
|
export const userData = {
|
|
143
124
|
name: 'name',
|
|
144
125
|
password: 'password',
|
|
145
|
-
createdAt: now,
|
|
146
|
-
updatedAt: now,
|
|
147
126
|
};
|
|
148
127
|
|
|
149
128
|
export const profileData = {
|
|
150
129
|
bio: 'text',
|
|
151
|
-
createdAt: now,
|
|
152
|
-
updatedAt: now,
|
|
153
130
|
};
|
|
154
131
|
|
|
155
132
|
export const chatData = {
|
|
156
133
|
title: 'title',
|
|
157
|
-
createdAt: now,
|
|
158
|
-
updatedAt: now,
|
|
159
134
|
};
|
|
160
135
|
|
|
161
136
|
export const messageData = {
|
|
162
137
|
text: 'text',
|
|
163
|
-
createdAt: now,
|
|
164
|
-
updatedAt: now,
|
|
165
138
|
};
|
|
166
139
|
|
|
167
140
|
export const useTestDatabase = () => {
|