sevenwestmedia-labs / node-knex-query-executor

TypeScript first encapsulation and reusability of knex database queries
MIT License
3 stars 4 forks source link

Run execute query immediately with type safety in args #11

Closed Tombre closed 5 years ago

Tombre commented 5 years ago

Previously, when you wanted to run a query, you had to write it it like this:

.execute(queryFn).withArgs({})

Note how you had to add withArgs to the end. This was so that we could get type safety with the query arguments, i.e. withArgs() would complain if the arguments were different to what queryFn would accept.

This PR makes it so you no longer have to write withArgs(), you can now just run your queries like this:

.execute(queryFn, { ... }) // arguments as the second argument

The execute function will have all the same type safety that withArgs had. It will also infer the types for you based on what what query function looks like.

The only exception is if you're not using any arguments in your query, you will have to still pass an empty object to the .execute() fn. This is because:

const query = queryExecutor.createQuery(
   async ({ tables }) => {
       tables.tableOne()
       return {}
    }
)

 // you still need to pass an empty object for it to not complain
await queryExecutor.execute(query, {})
JakeGinnivan commented 5 years ago

Need to update commits to conform with https://github.com/semantic-release/semantic-release#commit-message-format

This will be a breaking change and needs to be a major version bump.

Tombre commented 5 years ago

Need to update commits to conform with https://github.com/semantic-release/semantic-release#commit-message-format

This will be a breaking change and needs to be a major version bump.

Done! @JakeGinnivan

JakeGinnivan commented 5 years ago

There is another breaking change not described.

The query itself has separated args into the second argument. A small example would not go astray. The commit messages directly go into the release notes :)

Tombre commented 5 years ago

There is another breaking change not described.

The query itself has separated args into the second argument. A small example would not go astray. The commit messages directly go into the release notes :)

done!

JakeGinnivan commented 5 years ago

:tada: This PR is included in version 2.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: