-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(execute): Remove the need to call withArgs after the execute fun…
…ction BREAKING CHANGE: The withArgs function has been removed. Previously it has been required so that type safety around the query arguments can be ensured. Now args must be passed in as a second parameter of the execute function. This change also effects how the query function is structured. Now, the “args” are passed into the second argument of the query function. Here is an example of how it now works: const query = queryExecutor.createQuery<string, string>( async ({ tables }, arg) => { tables.tableOne() return arg } ) await queryExecutor.execute(query, ‘hello!’)
- Loading branch information
Showing
11 changed files
with
140 additions
and
68 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
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 |
---|---|---|
@@ -1,10 +1,18 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Typescript: Typescript expected failures 1`] = ` | ||
"src/type-safety-fixtures/create-query-helper.ts(17,20): error TS2339: Property 'wrongTable' does not exist on type 'TableNames<\\"testTable\\">'. | ||
"src/type-safety-fixtures/args-respected.ts(37,27): error TS7006: Parameter '_' implicitly has an 'any' type. | ||
src/type-safety-fixtures/args-respected.ts(45,41): error TS2345: Argument of type '1' is not assignable to parameter of type 'object'. | ||
src/type-safety-fixtures/args-respected.ts(46,41): error TS2345: Argument of type '1' is not assignable to parameter of type 'string'. | ||
src/type-safety-fixtures/args-respected.ts(47,41): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ id: number; }'. | ||
Property 'id' is missing in type '{}' but required in type '{ id: number; }'. | ||
src/type-safety-fixtures/args-respected.ts(48,41): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ id: number; }'. | ||
Property 'id' is missing in type '{}' but required in type '{ id: number; }'. | ||
src/type-safety-fixtures/args-respected.ts(50,11): error TS2554: Expected 2 arguments, but got 1. | ||
src/type-safety-fixtures/create-query-helper.ts(17,20): error TS2339: Property 'wrongTable' does not exist on type 'TableNames<\\"testTable\\">'. | ||
src/type-safety-fixtures/create-query-helper.ts(18,16): error TS2339: Property 'wrongTable' does not exist on type 'Tables<\\"testTable\\">'. | ||
src/type-safety-fixtures/create-query-helper.ts(20,21): error TS2339: Property 'foo' does not exist on type '{ testArg: string; }'. | ||
src/type-safety-fixtures/query-arguments.ts(22,46): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ testArg: string; }'. | ||
src/type-safety-fixtures/query-arguments.ts(22,37): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ testArg: string; }'. | ||
Property 'testArg' is missing in type '{}' but required in type '{ testArg: string; }'. | ||
" | ||
`; |
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
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
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
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
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
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,55 @@ | ||
import { ReadQueryExecutor } from '../' | ||
import { createMockedKnex } from '../test-helpers/knex' | ||
|
||
const testTables = { | ||
tableOne: 'table-one' | ||
} | ||
|
||
export async function dontComplainAboutUnused() { | ||
let executedQuery: any | ||
|
||
const knex = createMockedKnex(query => query.response([])) | ||
const queryExecutor = new ReadQueryExecutor(knex, {}, testTables, { | ||
queryBuilderWrapper: query => { | ||
executedQuery = query.toString() | ||
return query | ||
} | ||
}) | ||
|
||
const query2 = async (_: any, args: string) => { | ||
return args | ||
} | ||
|
||
const query1 = queryExecutor.createQuery(async ({ tables }, args) => { | ||
;(() => args)() | ||
tables.tableOne() | ||
return {} | ||
}) | ||
|
||
const query3 = queryExecutor.createQuery<{ id: number }, {}>( | ||
async ({ tables }, args) => { | ||
;(() => args)() | ||
tables.tableOne() | ||
return {} | ||
} | ||
) | ||
|
||
const query4 = async (_, args: { id: number }) => { | ||
return {} | ||
} | ||
|
||
const query5 = async () => { | ||
return {} | ||
} | ||
|
||
await queryExecutor.execute(query1, 1) | ||
await queryExecutor.execute(query2, 1) | ||
await queryExecutor.execute(query3, {}) | ||
await queryExecutor.execute(query4, {}) | ||
await queryExecutor.execute(query5, {}) | ||
await queryExecutor.execute(query5) | ||
|
||
await queryExecutor.execute(async () => 'x', {}) | ||
|
||
return executedQuery | ||
} |
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
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
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