pqb 0.4.0 → 0.4.2

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.
@@ -3,9 +3,9 @@ import {
3
3
  Query,
4
4
  QueryReturnsAll,
5
5
  QueryReturnType,
6
+ queryTypeWithLimitOne,
6
7
  SetQueryReturnsAll,
7
8
  SetQueryReturnsOne,
8
- SetQueryReturnsRowCount,
9
9
  } from '../query';
10
10
  import { pushQueryArray } from '../queryDataUtils';
11
11
  import { RawExpression } from '../common';
@@ -26,13 +26,13 @@ import { InsertQueryData, OnConflictItem, OnConflictMergeUpdate } from '../sql';
26
26
  import { WhereArg } from './where';
27
27
  import { parseResult, queryMethodByReturnType } from './then';
28
28
 
29
- export type InsertData<
29
+ export type CreateData<
30
30
  T extends Query,
31
31
  DefaultKeys extends PropertyKey = keyof T[defaultsKey],
32
32
  Data = SetOptional<T['inputType'], DefaultKeys>,
33
33
  > = [keyof T['relations']] extends [never]
34
34
  ? Data
35
- : OmitBelongsToForeignKeys<T['relations'], Data> & InsertRelationData<T>;
35
+ : OmitBelongsToForeignKeys<T['relations'], Data> & CreateRelationData<T>;
36
36
 
37
37
  type OmitBelongsToForeignKeys<R extends RelationsBase, Data> = Omit<
38
38
  Data,
@@ -43,17 +43,17 @@ type OmitBelongsToForeignKeys<R extends RelationsBase, Data> = Omit<
43
43
  }[keyof R]
44
44
  >;
45
45
 
46
- type InsertRelationData<T extends Query> = {
46
+ type CreateRelationData<T extends Query> = {
47
47
  [K in keyof T['relations']]: T['relations'][K] extends BelongsToRelation
48
- ? InsertBelongsToData<T, K, T['relations'][K]>
48
+ ? CreateBelongsToData<T, K, T['relations'][K]>
49
49
  : T['relations'][K] extends HasOneRelation
50
- ? InsertHasOneData<T, K, T['relations'][K]>
50
+ ? CreateHasOneData<T, K, T['relations'][K]>
51
51
  : T['relations'][K] extends HasManyRelation | HasAndBelongsToManyRelation
52
- ? InsertHasManyData<T, K, T['relations'][K]>
52
+ ? CreateHasManyData<T, K, T['relations'][K]>
53
53
  : EmptyObject;
54
54
  }[keyof T['relations']];
55
55
 
56
- type InsertBelongsToData<
56
+ type CreateBelongsToData<
57
57
  T extends Query,
58
58
  Key extends keyof T['relations'],
59
59
  Rel extends BelongsToRelation,
@@ -69,7 +69,7 @@ type InsertBelongsToData<
69
69
  | {
70
70
  [K in Key]:
71
71
  | {
72
- create: InsertData<Rel['nestedCreateQuery']>;
72
+ create: CreateData<Rel['nestedCreateQuery']>;
73
73
  connect?: never;
74
74
  connectOrCreate?: never;
75
75
  }
@@ -83,12 +83,12 @@ type InsertBelongsToData<
83
83
  connect?: never;
84
84
  connectOrCreate: {
85
85
  where: WhereArg<Rel['model']>;
86
- create: InsertData<Rel['nestedCreateQuery']>;
86
+ create: CreateData<Rel['nestedCreateQuery']>;
87
87
  };
88
88
  };
89
89
  };
90
90
 
91
- type InsertHasOneData<
91
+ type CreateHasOneData<
92
92
  T extends Query,
93
93
  Key extends keyof T['relations'],
94
94
  Rel extends HasOneRelation,
@@ -98,7 +98,7 @@ type InsertHasOneData<
98
98
  : {
99
99
  [K in Key]?:
100
100
  | {
101
- create: InsertData<Rel['nestedCreateQuery']>;
101
+ create: CreateData<Rel['nestedCreateQuery']>;
102
102
  connect?: never;
103
103
  connectOrCreate?: never;
104
104
  }
@@ -112,12 +112,12 @@ type InsertHasOneData<
112
112
  connect?: never;
113
113
  connectOrCreate: {
114
114
  where?: WhereArg<Rel['model']>;
115
- create?: InsertData<Rel['nestedCreateQuery']>;
115
+ create?: CreateData<Rel['nestedCreateQuery']>;
116
116
  };
117
117
  };
118
118
  };
119
119
 
120
- type InsertHasManyData<
120
+ type CreateHasManyData<
121
121
  T extends Query,
122
122
  Key extends keyof T['relations'],
123
123
  Rel extends HasManyRelation | HasAndBelongsToManyRelation,
@@ -126,30 +126,28 @@ type InsertHasManyData<
126
126
  {}
127
127
  : {
128
128
  [K in Key]?: {
129
- create?: InsertData<Rel['nestedCreateQuery']>[];
129
+ create?: CreateData<Rel['nestedCreateQuery']>[];
130
130
  connect?: WhereArg<Rel['model']>[];
131
131
  connectOrCreate?: {
132
132
  where: WhereArg<Rel['model']>;
133
- create: InsertData<Rel['nestedCreateQuery']>;
133
+ create: CreateData<Rel['nestedCreateQuery']>;
134
134
  }[];
135
135
  };
136
136
  };
137
137
 
138
- type InsertRawData = { columns: string[]; values: RawExpression };
138
+ type CreateResult<T extends Query> = T extends { isCount: true }
139
+ ? T
140
+ : QueryReturnsAll<T['returnType']> extends true
141
+ ? SetQueryReturnsOne<T>
142
+ : T;
139
143
 
140
- type InsertOneResult<T extends Query> = T['hasSelect'] extends true
141
- ? QueryReturnsAll<T['returnType']> extends true
142
- ? SetQueryReturnsOne<T>
143
- : T['returnType'] extends 'one'
144
- ? SetQueryReturnsOne<T>
145
- : T
146
- : SetQueryReturnsRowCount<T>;
144
+ type CreateManyResult<T extends Query> = T extends { isCount: true }
145
+ ? T
146
+ : T['returnType'] extends 'one' | 'oneOrThrow'
147
+ ? SetQueryReturnsAll<T>
148
+ : T;
147
149
 
148
- type InsertManyResult<T extends Query> = T['hasSelect'] extends true
149
- ? T['returnType'] extends 'one' | 'oneOrThrow'
150
- ? SetQueryReturnsAll<T>
151
- : T
152
- : SetQueryReturnsRowCount<T>;
150
+ type CreateRawData = { columns: string[]; values: RawExpression };
153
151
 
154
152
  type OnConflictArg<T extends Query> =
155
153
  | keyof T['shape']
@@ -166,17 +164,31 @@ type AppendRelations = Record<
166
164
  [rowIndex: number, data: NestedInsertItem][]
167
165
  >;
168
166
 
169
- type InsertCtx = {
167
+ type CreateCtx = {
170
168
  prependRelations: PrependRelations;
171
169
  appendRelations: AppendRelations;
172
170
  requiredReturning: Record<string, boolean>;
173
171
  relations: Record<string, Relation>;
174
172
  };
175
173
 
176
- const processInsertItem = (
174
+ const handleSelect = (q: Query) => {
175
+ const select = q.query.select?.[0];
176
+ const isCount =
177
+ typeof select === 'object' &&
178
+ 'function' in select &&
179
+ select.function === 'count';
180
+
181
+ if (isCount) {
182
+ q.query.select = undefined;
183
+ } else if (isCount || !q.query.select) {
184
+ q.query.select = ['*'];
185
+ }
186
+ };
187
+
188
+ const processCreateItem = (
177
189
  item: Record<string, unknown>,
178
190
  rowIndex: number,
179
- ctx: InsertCtx,
191
+ ctx: CreateCtx,
180
192
  columns: string[],
181
193
  columnsMap: Record<string, number>,
182
194
  ) => {
@@ -216,14 +228,14 @@ const processInsertItem = (
216
228
  });
217
229
  };
218
230
 
219
- const createInsertCtx = (q: Query): InsertCtx => ({
231
+ const createCtx = (q: Query): CreateCtx => ({
220
232
  prependRelations: {},
221
233
  appendRelations: {},
222
234
  requiredReturning: {},
223
235
  relations: (q as unknown as Query).relations,
224
236
  });
225
237
 
226
- const getInsertSingleReturnType = (q: Query) => {
238
+ const getSingleReturnType = (q: Query) => {
227
239
  const { select, returnType = 'all' } = q.query;
228
240
  if (select) {
229
241
  return returnType === 'all' ? 'one' : returnType;
@@ -232,7 +244,7 @@ const getInsertSingleReturnType = (q: Query) => {
232
244
  }
233
245
  };
234
246
 
235
- const getInsertManyReturnType = (q: Query) => {
247
+ const getManyReturnType = (q: Query) => {
236
248
  const { select, returnType } = q.query;
237
249
  if (select) {
238
250
  return returnType === 'one' || returnType === 'oneOrThrow'
@@ -243,11 +255,7 @@ const getInsertManyReturnType = (q: Query) => {
243
255
  }
244
256
  };
245
257
 
246
- const handleInsertOneData = (
247
- q: Query,
248
- data: InsertData<Query>,
249
- ctx: InsertCtx,
250
- ) => {
258
+ const handleOneData = (q: Query, data: CreateData<Query>, ctx: CreateCtx) => {
251
259
  const columns: string[] = [];
252
260
  const columnsMap: Record<string, number> = {};
253
261
  const defaults = q.query.defaults;
@@ -256,17 +264,17 @@ const handleInsertOneData = (
256
264
  data = { ...defaults, ...data };
257
265
  }
258
266
 
259
- processInsertItem(data, 0, ctx, columns, columnsMap);
267
+ processCreateItem(data, 0, ctx, columns, columnsMap);
260
268
 
261
269
  const values = [columns.map((key) => (data as Record<string, unknown>)[key])];
262
270
 
263
271
  return { columns, values };
264
272
  };
265
273
 
266
- const handleInsertManyData = (
274
+ const handleManyData = (
267
275
  q: Query,
268
- data: InsertData<Query>[],
269
- ctx: InsertCtx,
276
+ data: CreateData<Query>[],
277
+ ctx: CreateCtx,
270
278
  ) => {
271
279
  const columns: string[] = [];
272
280
  const columnsMap: Record<string, number> = {};
@@ -277,7 +285,7 @@ const handleInsertManyData = (
277
285
  }
278
286
 
279
287
  data.forEach((item, i) => {
280
- processInsertItem(item, i, ctx, columns, columnsMap);
288
+ processCreateItem(item, i, ctx, columns, columnsMap);
281
289
  });
282
290
 
283
291
  const values = Array(data.length);
@@ -299,7 +307,7 @@ const insert = (
299
307
  values: unknown[][] | RawExpression;
300
308
  },
301
309
  returnType: QueryReturnType,
302
- ctx?: InsertCtx,
310
+ ctx?: CreateCtx,
303
311
  ) => {
304
312
  const q = self as Query & { query: InsertQueryData };
305
313
  const returning = q.query.select;
@@ -407,102 +415,115 @@ const insert = (
407
415
  return q;
408
416
  };
409
417
 
410
- export class Insert {
411
- insert<T extends Query>(this: T, data: InsertData<T>): InsertOneResult<T> {
412
- return this.clone()._insert(data);
418
+ export type CreateMethodsNames =
419
+ | 'create'
420
+ | '_create'
421
+ | 'createMany'
422
+ | '_createMany'
423
+ | 'createRaw'
424
+ | '_createRaw'
425
+ | 'createFrom'
426
+ | '_createFrom';
427
+
428
+ export class Create {
429
+ create<T extends Query>(this: T, data: CreateData<T>): CreateResult<T> {
430
+ return this.clone()._create(data);
413
431
  }
414
- _insert<T extends Query>(this: T, data: InsertData<T>): InsertOneResult<T> {
415
- const ctx = createInsertCtx(this);
432
+ _create<T extends Query>(this: T, data: CreateData<T>): CreateResult<T> {
433
+ handleSelect(this);
434
+
435
+ const ctx = createCtx(this);
436
+
437
+ const obj = handleOneData(this, data, ctx);
438
+ let { columns } = obj;
439
+
440
+ const { fromQuery } = this.query as InsertQueryData;
441
+ if (fromQuery) {
442
+ if (!queryTypeWithLimitOne[fromQuery.query.returnType]) {
443
+ throw new Error(
444
+ 'Cannot create based on a query which returns multiple records',
445
+ );
446
+ }
447
+
448
+ const queryColumns: string[] = [];
449
+ fromQuery.query.select?.forEach((item) => {
450
+ if (typeof item === 'string') {
451
+ const index = item.indexOf('.');
452
+ queryColumns.push(index === -1 ? item : item.slice(index + 1));
453
+ } else if ('selectAs' in item) {
454
+ queryColumns.push(...Object.keys(item.selectAs));
455
+ }
456
+ });
457
+
458
+ queryColumns.push(...columns);
459
+ columns = queryColumns;
460
+ }
461
+
416
462
  return insert(
417
463
  this,
418
- handleInsertOneData(this, data, ctx),
419
- getInsertSingleReturnType(this),
464
+ { columns, values: obj.values },
465
+ getSingleReturnType(this),
420
466
  ctx,
421
- ) as InsertOneResult<T>;
467
+ ) as CreateResult<T>;
422
468
  }
423
469
 
424
- insertMany<T extends Query>(
470
+ createMany<T extends Query>(
425
471
  this: T,
426
- data: InsertData<T>[],
427
- ): InsertManyResult<T> {
428
- return this.clone()._insertMany(data);
472
+ data: CreateData<T>[],
473
+ ): CreateManyResult<T> {
474
+ return this.clone()._createMany(data);
429
475
  }
430
- _insertMany<T extends Query>(
476
+ _createMany<T extends Query>(
431
477
  this: T,
432
- data: InsertData<T>[],
433
- ): InsertManyResult<T> {
434
- const ctx = createInsertCtx(this);
478
+ data: CreateData<T>[],
479
+ ): CreateManyResult<T> {
480
+ handleSelect(this);
481
+ const ctx = createCtx(this);
435
482
  return insert(
436
483
  this,
437
- handleInsertManyData(this, data, ctx),
438
- getInsertManyReturnType(this),
484
+ handleManyData(this, data, ctx),
485
+ getManyReturnType(this),
439
486
  ctx,
440
- ) as InsertManyResult<T>;
487
+ ) as CreateManyResult<T>;
441
488
  }
442
489
 
443
- insertRaw<T extends Query>(
490
+ createRaw<T extends Query>(
444
491
  this: T,
445
- data: InsertRawData,
446
- ): InsertManyResult<T> {
447
- return this.clone()._insertRaw(data);
492
+ data: CreateRawData,
493
+ ): CreateManyResult<T> {
494
+ return this.clone()._createRaw(data);
448
495
  }
449
- _insertRaw<T extends Query>(
496
+ _createRaw<T extends Query>(
450
497
  this: T,
451
- data: InsertRawData,
452
- ): InsertManyResult<T> {
453
- return insert(
454
- this,
455
- data,
456
- getInsertManyReturnType(this),
457
- ) as InsertManyResult<T>;
498
+ data: CreateRawData,
499
+ ): CreateManyResult<T> {
500
+ handleSelect(this);
501
+ return insert(this, data, getManyReturnType(this)) as CreateManyResult<T>;
458
502
  }
459
503
 
460
- create<T extends Query>(this: T, data: InsertData<T>): SetQueryReturnsOne<T> {
461
- return this.clone()._create(data);
462
- }
463
- _create<T extends Query>(
504
+ createFrom<
505
+ T extends Query,
506
+ Q extends Query & { returnType: 'one' | 'oneOrThrow' },
507
+ >(
464
508
  this: T,
465
- data: InsertData<T>,
509
+ query: Q,
510
+ data: Omit<CreateData<T>, keyof Q['result']>,
466
511
  ): SetQueryReturnsOne<T> {
467
- if (!this.query.select) {
468
- this.query.select = ['*'];
469
- }
470
- return this.clone()._insert(data) as SetQueryReturnsOne<T>;
471
- }
472
-
473
- createMany<T extends Query>(
474
- this: T,
475
- data: InsertData<T>[],
476
- ): SetQueryReturnsAll<T> {
477
- return this.clone()._createMany(data);
478
- }
479
- _createMany<T extends Query>(
480
- this: T,
481
- data: InsertData<T>[],
482
- ): SetQueryReturnsAll<T> {
483
- if (!this.query.select) {
484
- this.query.select = ['*'];
485
- }
486
- return this.clone()._insertMany(data) as SetQueryReturnsAll<T>;
512
+ return this.clone()._createFrom(query, data);
487
513
  }
488
-
489
- createRaw<T extends Query>(
490
- this: T,
491
- data: InsertRawData,
492
- ): SetQueryReturnsAll<T> {
493
- return this.clone()._createRaw(data);
494
- }
495
- _createRaw<T extends Query>(
514
+ _createFrom<
515
+ T extends Query,
516
+ Q extends Query & { returnType: 'one' | 'oneOrThrow' },
517
+ >(
496
518
  this: T,
497
- data: InsertRawData,
498
- ): SetQueryReturnsAll<T> {
499
- if (!this.query.select) {
500
- this.query.select = ['*'];
501
- }
502
- return this.clone()._insertRaw(data) as SetQueryReturnsAll<T>;
519
+ query: Q,
520
+ data: Omit<CreateData<T>, keyof Q['result']>,
521
+ ): CreateResult<T> {
522
+ (this.query as InsertQueryData).fromQuery = query;
523
+ return this._create(data as CreateData<T>);
503
524
  }
504
525
 
505
- defaults<T extends Query, Data extends Partial<InsertData<T>>>(
526
+ defaults<T extends Query, Data extends Partial<CreateData<T>>>(
506
527
  this: T,
507
528
  data: Data,
508
529
  ): T & {
@@ -510,7 +531,7 @@ export class Insert {
510
531
  } {
511
532
  return (this.clone() as T)._defaults(data);
512
533
  }
513
- _defaults<T extends Query, Data extends Partial<InsertData<T>>>(
534
+ _defaults<T extends Query, Data extends Partial<CreateData<T>>>(
514
535
  this: T,
515
536
  data: Data,
516
537
  ): T & { [defaultsKey]: Record<keyof Data, true> } {
@@ -29,7 +29,7 @@ describe('delete', () => {
29
29
  });
30
30
 
31
31
  it('should delete records, returning value', async () => {
32
- const id = await User.get('id').insert(userData);
32
+ const id = await User.get('id').create(userData);
33
33
  const q = User.all();
34
34
 
35
35
  const query = q.find(id).get('id').delete();
@@ -54,7 +54,7 @@ describe('delete', () => {
54
54
  const rowsCount = 3;
55
55
 
56
56
  for (let i = 0; i < rowsCount; i++) {
57
- await User.insert(userData);
57
+ await User.create(userData);
58
58
  }
59
59
 
60
60
  const q = User.all();
@@ -8,7 +8,7 @@ describe('get', () => {
8
8
 
9
9
  describe('get', () => {
10
10
  it('should select column and return a single value', async () => {
11
- const { id } = await User.select('id').insert(userData);
11
+ const { id } = await User.select('id').create(userData);
12
12
 
13
13
  const received = await User.get('id');
14
14
 
@@ -32,7 +32,7 @@ describe('get', () => {
32
32
 
33
33
  describe('getOptional', () => {
34
34
  it('should select column and return a single value when exists', async () => {
35
- const { id } = await User.select('id').insert(userData);
35
+ const { id } = await User.select('id').create(userData);
36
36
 
37
37
  const received = await User.getOptional('id');
38
38
 
@@ -7,7 +7,7 @@ export * from './for';
7
7
  export * from './from';
8
8
  export * from './get';
9
9
  export * from './having';
10
- export * from './insert';
10
+ export * from './create';
11
11
  export * from './join';
12
12
  export * from './json';
13
13
  export * from './log';
@@ -48,7 +48,7 @@ describe('json methods', () => {
48
48
 
49
49
  describe('processing and selecting json data', () => {
50
50
  beforeEach(async () => {
51
- await User.insert({
51
+ await User.create({
52
52
  ...userData,
53
53
  data: { name: 'value', tags: ['one'] },
54
54
  });
@@ -2,6 +2,7 @@ import { createDb } from '../db';
2
2
  import { adapter, dbOptions, userData, useTestDatabase } from '../test-utils';
3
3
  import { logColors } from './log';
4
4
  import { noop } from '../utils';
5
+ import { columnTypes } from '../columnSchema';
5
6
 
6
7
  describe('query log', () => {
7
8
  useTestDatabase();
@@ -45,7 +46,7 @@ describe('query log', () => {
45
46
  error: jest.fn(),
46
47
  };
47
48
 
48
- const db = createDb({ adapter, log: true, logger });
49
+ const db = createDb({ adapter, columnTypes, log: true, logger });
49
50
 
50
51
  await db('user').where({ name: 'name' });
51
52
 
@@ -68,7 +69,12 @@ describe('query log', () => {
68
69
  error: jest.fn(),
69
70
  };
70
71
 
71
- const db = createDb({ adapter, log: { colors: false }, logger });
72
+ const db = createDb({
73
+ adapter,
74
+ columnTypes,
75
+ log: { colors: false },
76
+ logger,
77
+ });
72
78
 
73
79
  await db('user').where({ name: 'name' });
74
80
 
@@ -87,7 +93,7 @@ describe('query log', () => {
87
93
  error: jest.fn(),
88
94
  };
89
95
 
90
- const db = createDb({ adapter, log: true, logger });
96
+ const db = createDb({ adapter, columnTypes, log: true, logger });
91
97
 
92
98
  await db('user').where({ wrongColumn: 'value' }).then(noop, noop);
93
99
 
@@ -112,7 +118,12 @@ describe('query log', () => {
112
118
  error: jest.fn(),
113
119
  };
114
120
 
115
- const db = createDb({ adapter, log: { colors: false }, logger });
121
+ const db = createDb({
122
+ adapter,
123
+ columnTypes,
124
+ log: { colors: false },
125
+ logger,
126
+ });
116
127
 
117
128
  await db('user').where({ wrongColumn: 'value' }).then(noop, noop);
118
129
 
@@ -133,10 +144,15 @@ describe('query log', () => {
133
144
  error: jest.fn(),
134
145
  };
135
146
 
136
- const db = createDb({ adapter, log: { colors: false }, logger });
147
+ const db = createDb({
148
+ adapter,
149
+ columnTypes,
150
+ log: { colors: false },
151
+ logger,
152
+ });
137
153
 
138
154
  await db.transaction(async (q) => {
139
- await db('user').transacting(q).insert(userData);
155
+ await db('user').transacting(q).create(userData);
140
156
  });
141
157
 
142
158
  expect(logger.log.mock.calls).toEqual([
@@ -156,11 +172,16 @@ describe('query log', () => {
156
172
  error: jest.fn(),
157
173
  };
158
174
 
159
- const db = createDb({ adapter, log: { colors: false }, logger });
175
+ const db = createDb({
176
+ adapter,
177
+ columnTypes,
178
+ log: { colors: false },
179
+ logger,
180
+ });
160
181
 
161
182
  await expect(
162
183
  db.transaction(async (q) => {
163
- await db('user').transacting(q).insert({ name: 'name' });
184
+ await db('user').transacting(q).create({ name: 'name' });
164
185
  }),
165
186
  ).rejects.toThrow();
166
187
 
@@ -373,8 +373,8 @@ describe('merge queries', () => {
373
373
  i2.join = [{ type: 'b', args: ['b'] }];
374
374
  i1.onConflict = { type: 'ignore' };
375
375
  i2.onConflict = { type: 'merge' };
376
- i1.beforeInsert = [() => {}];
377
- i2.beforeInsert = [() => {}];
376
+ i1.beforeCreate = [() => {}];
377
+ i2.beforeCreate = [() => {}];
378
378
 
379
379
  const u1 = q1.query as unknown as UpdateQueryData;
380
380
  const u2 = q2.query as unknown as UpdateQueryData;
@@ -451,7 +451,7 @@ describe('merge queries', () => {
451
451
  expect(i.using).toEqual([...i1.using, ...i2.using]);
452
452
  expect(i.join).toEqual([...i1.join, ...i2.join]);
453
453
  expect(i.onConflict).toEqual(i2.onConflict);
454
- expect(i.beforeInsert).toEqual([...i1.beforeInsert, ...i2.beforeInsert]);
454
+ expect(i.beforeCreate).toEqual([...i1.beforeCreate, ...i2.beforeCreate]);
455
455
 
456
456
  const u = q as UpdateQueryData;
457
457
  expect(u.updateData).toEqual([...u1.updateData, ...u2.updateData]);
@@ -46,7 +46,7 @@ describe('queryMethods', () => {
46
46
 
47
47
  describe('take', () => {
48
48
  it('limits to one and returns only one', async () => {
49
- await User.insert(userData);
49
+ await User.create(userData);
50
50
 
51
51
  const q = User.all();
52
52
  expectSql(q.take().toSql(), `SELECT * FROM "user" LIMIT $1`, [1]);
@@ -73,7 +73,7 @@ describe('queryMethods', () => {
73
73
 
74
74
  describe('takeOptional', () => {
75
75
  it('limits to one and returns only one', async () => {
76
- await User.insert(userData);
76
+ await User.create(userData);
77
77
 
78
78
  const q = User.all();
79
79
  expectSql(q.takeOptional().toSql(), `SELECT * FROM "user" LIMIT $1`, [1]);
@@ -114,7 +114,7 @@ describe('queryMethods', () => {
114
114
  describe('pluck', () => {
115
115
  beforeEach(async () => {
116
116
  for (let i = 0; i < 3; i++) {
117
- await User.insert({ ...userData, createdAt: now });
117
+ await User.create({ ...userData, createdAt: now });
118
118
  }
119
119
  });
120
120
 
@@ -573,7 +573,7 @@ describe('queryMethods', () => {
573
573
 
574
574
  expect(await query).toBe(false);
575
575
 
576
- await User.insert(userData);
576
+ await User.create(userData);
577
577
 
578
578
  expect(await query).toBe(true);
579
579
 
@@ -33,7 +33,7 @@ import { Join } from './join';
33
33
  import { With } from './with';
34
34
  import { Union } from './union';
35
35
  import { Json } from './json';
36
- import { Insert } from './insert';
36
+ import { Create } from './create';
37
37
  import { Update } from './update';
38
38
  import { Delete } from './delete';
39
39
  import { Transaction } from './transaction';
@@ -81,7 +81,7 @@ export interface QueryMethods
81
81
  With,
82
82
  Union,
83
83
  Json,
84
- Insert,
84
+ Create,
85
85
  Update,
86
86
  Delete,
87
87
  Transaction,
@@ -381,7 +381,7 @@ applyMixins(QueryMethods, [
381
381
  With,
382
382
  Union,
383
383
  Json,
384
- Insert,
384
+ Create,
385
385
  Update,
386
386
  Delete,
387
387
  Transaction,