pqb 0.2.1 → 0.2.3

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.
@@ -35,7 +35,7 @@ describe('update', () => {
35
35
 
36
36
  it('should update record with raw sql, returning updated rows count', async () => {
37
37
  const count = 2;
38
- const users = await User.select('id').insert([userData, userData]);
38
+ const users = await User.select('id').insertMany([userData, userData]);
39
39
 
40
40
  const query = User.or(...users).update(raw(`name = 'name'`));
41
41
  expectSql(
@@ -167,7 +167,7 @@ describe('update', () => {
167
167
  });
168
168
 
169
169
  it('should update multiple records, returning selected columns', async () => {
170
- const ids = await User.pluck('id').insert([userData, userData]);
170
+ const ids = await User.pluck('id').insertMany([userData, userData]);
171
171
 
172
172
  const update = {
173
173
  name: 'new name',
@@ -199,7 +199,7 @@ describe('update', () => {
199
199
  });
200
200
 
201
201
  it('should update multiple records, returning all columns', async () => {
202
- const ids = await User.pluck('id').insert([userData, userData]);
202
+ const ids = await User.pluck('id').insertMany([userData, userData]);
203
203
 
204
204
  const update = {
205
205
  name: 'new name',
@@ -42,7 +42,7 @@ describe('upsert', () => {
42
42
  });
43
43
 
44
44
  it('should throw if more than one row was updated', async () => {
45
- await User.create([userData, userData]);
45
+ await User.createMany([userData, userData]);
46
46
 
47
47
  await expect(
48
48
  User.findBy({ name: userData.name }).upsert({
@@ -20,11 +20,11 @@ describe('window functions', () => {
20
20
  `('$method', ({ method, functionName, results }) => {
21
21
  it('should return array of objects with number value', async () => {
22
22
  if (method === 'selectCumeDist') {
23
- await User.insert([
23
+ await User.insertMany([
24
24
  { ...userData, age: 20 },
25
25
  { ...userData, age: 20 },
26
26
  ]);
27
- await User.insert([
27
+ await User.insertMany([
28
28
  { ...userData, age: 30 },
29
29
  { ...userData, age: 30 },
30
30
  ]);
@@ -0,0 +1,37 @@
1
+ import { assertType } from './test-utils';
2
+ import { MaybeArray, SetOptional, SomeIsTrue } from './utils';
3
+
4
+ describe('utils', () => {
5
+ describe('SomeIsTrue', () => {
6
+ it('should be true if some is true', () => {
7
+ assertType<SomeIsTrue<[false, false, true, false]>, true>();
8
+ });
9
+
10
+ it('should be false if none is true', () => {
11
+ assertType<SomeIsTrue<[false, false, false]>, false>();
12
+ });
13
+
14
+ it('should be false if types array is empty', () => {
15
+ assertType<SomeIsTrue<[]>, false>();
16
+ });
17
+ });
18
+
19
+ describe('MaybeArray', () => {
20
+ it('should turn a type into union of T | T[]', () => {
21
+ assertType<MaybeArray<number>, number | number[]>();
22
+ });
23
+ });
24
+
25
+ describe('setOptional', () => {
26
+ it('should make specified keys optional', () => {
27
+ assertType<
28
+ SetOptional<{ a: number; b: string; c: boolean }, 'b' | 'c'>,
29
+ {
30
+ a: number;
31
+ b?: string;
32
+ c?: boolean;
33
+ }
34
+ >();
35
+ });
36
+ });
37
+ });
package/src/utils.ts CHANGED
@@ -1,6 +1,15 @@
1
1
  import { RawExpression } from './common';
2
2
  import { QueryData } from './sql';
3
3
 
4
+ export type SomeIsTrue<T extends unknown[]> = T extends [
5
+ infer Head,
6
+ ...infer Tail,
7
+ ]
8
+ ? Head extends true
9
+ ? true
10
+ : SomeIsTrue<Tail>
11
+ : false;
12
+
4
13
  export type MaybeArray<T> = T | T[];
5
14
 
6
15
  export type SetOptional<T, K extends PropertyKey> = Omit<T, K> & {