pqb 0.2.9 → 0.3.0
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
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
useTestDatabase,
|
|
18
18
|
} from '../test-utils';
|
|
19
19
|
import { raw } from '../common';
|
|
20
|
-
import { DateColumn } from '../columnSchema';
|
|
20
|
+
import { columnTypes, DateColumn } from '../columnSchema';
|
|
21
21
|
import { addQueryOn } from './join';
|
|
22
22
|
import { RelationQuery, relationQueryKey } from '../relations';
|
|
23
23
|
|
|
@@ -289,6 +289,21 @@ describe('selectMethods', () => {
|
|
|
289
289
|
createdAt: now,
|
|
290
290
|
});
|
|
291
291
|
});
|
|
292
|
+
|
|
293
|
+
it('should have proper type for conditional sub queries', async () => {
|
|
294
|
+
const condition = true;
|
|
295
|
+
|
|
296
|
+
const query = User.select('id', {
|
|
297
|
+
hasProfile: condition
|
|
298
|
+
? () => profileRelation.exists()
|
|
299
|
+
: raw(columnTypes.boolean(), 'true'),
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
assertType<
|
|
303
|
+
Awaited<typeof query>,
|
|
304
|
+
{ id: number; hasProfile: boolean }[]
|
|
305
|
+
>();
|
|
306
|
+
});
|
|
292
307
|
});
|
|
293
308
|
|
|
294
309
|
describe('parse columns', () => {
|
|
@@ -63,6 +63,12 @@ type SelectResult<
|
|
|
63
63
|
? SelectAsArgs[K]['__column']
|
|
64
64
|
: SelectAsArgs[K] extends (q: T) => Query
|
|
65
65
|
? SelectSubQueryResult<ReturnType<SelectAsArgs[K]>>
|
|
66
|
+
: SelectAsArgs[K] extends ((q: T) => Query) | RawExpression
|
|
67
|
+
?
|
|
68
|
+
| SelectSubQueryResult<
|
|
69
|
+
ReturnType<Exclude<SelectAsArgs[K], RawExpression>>
|
|
70
|
+
>
|
|
71
|
+
| Exclude<SelectAsArgs[K], (q: T) => Query>['__column']
|
|
66
72
|
: never;
|
|
67
73
|
}
|
|
68
74
|
>;
|