Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix/4068 batchInsert correct definitions
- Loading branch information
1 parent
36859dc
commit c98699c
Showing
2 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Knex from '../types'; | ||
import { expectError, expectType } from 'tsd'; | ||
import { clientConfig } from './common'; | ||
|
||
const knex = Knex(clientConfig); | ||
|
||
// Use: | ||
// import Knex from 'knex' | ||
// when "esModuleInterop": true | ||
|
||
const main = async () => { | ||
// default returning is number[] | ||
expectType<number[]>(await knex.batchInsert('table', [{a: 2, id: 3}] as const, 12)); | ||
|
||
// allows any data | ||
expectType<any[]>(await knex.batchInsert('table', [{a: 2, id: 3}] as any[], 12).returning('abc')); | ||
|
||
// allows any data | ||
expectType<any[]>(await knex.batchInsert('table', [{a: 2, id: 3}] as any, 12).returning('abc')); | ||
|
||
// returning '*' allowed, return full record | ||
expectType<Array<{a: boolean, id: number}>>(await knex.batchInsert('table', [{a: false, id: 3}], 12).returning('*')); | ||
|
||
// one column for returning | ||
expectType<Array<{aa2: string}>>(await knex.batchInsert('table', [{aa2: 'string', b: 3}], 12).returning('aa2')); | ||
|
||
// many columns for returning | ||
expectType<Array<{aa2: string, b: boolean}>>(await knex.batchInsert('table', [{aa2: 'string', b: false, c: 12}], 12).returning(['aa2', 'b'])); | ||
|
||
// assert bad column in returning gives error | ||
expectError( | ||
knex.batchInsert('table', [{aa2: 'string', b: false, c: 12}], 12) | ||
.returning('bad_column') | ||
); | ||
|
||
// assert any bad column from returning list gives error | ||
// tsd gives error on this, lol | ||
/*expectError( | ||
knex.batchInsert('table', [{aa2: 'string', b: false, c: 12}], 12) | ||
.returning(['aa2', 'bad_column']) | ||
);*/ | ||
|
||
// validates insert data | ||
expectError(knex.batchInsert<{aa2: string, c: number}>('table', [{aa2: 'string', b: false, c: 12}], 12)); | ||
|
||
expectType<number[]>(await knex.batchInsert('table', [{a: 2, id: 3}] as const, 12).transacting(await knex.transaction())); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters