Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Upcoming release: 0.6.0 #252
Still need to fix up the migrations and clean up a few other things, but I wanted to create a ticket that details the new minor release so people can take a look and give any feedback, because the internal changes are pretty significant and exciting.
The library will still take the "Batteries Included" approach: calling
Added conditionally if you've specified a connection:
Added conditionally if any of the schema methods are called:
...and in SQLite3, where anything related to DDL is a complete mess:
Added conditionally if the migration utilities are used:
It helps makes things super obvious as to where features should be added, and what the model should be when adding new clients. Also, since each client has independent constructors, it's totally fine to write plugins/modify things as needed without potentially running into issues with others' instances.
Some of the main issues that have come up deal with raw queries and the fact that you can't specify bound parameters when injecting raw statements within a knex query. The solution to this was pretty in-depth, it involved rewriting most of the structure of the entire builder, each call to a query builder pushes the arguments onto a
This allows us to do things like:
knex.whereIn('id', knex.raw('(select * from table where id = ?)', [binding])).orWhere('id', 22)
or to re-use queries by placing them in other queries (see #162 for a neat use):
var q1 = knex.select('*').from('table').where('id', binding); knex.whereIn('id', q1).orWhere('id', 22);
This works because everything now follows a "Builder" -> "Compiler" sequence, where the query is first built, and then "compiled", where the compiler uses its own formatter object, keeping track of the position of the bindings as the query is compiled rather than as it is built.
This new structure also make it super straightforward on how to add new features, for example facilities for view creation. In fact I've taken the liberty of putting a viewbuilder.js & viewcompiler.js in the schema directory, they're empty, anyone can feel free to take that one on :)
Also, as you may have noticed, all methods can be chained from the
There are also major number of unit tests added, adapted from laravel's suite :)
The new structure should also make it really obvious how to add additional adapters, @tybenz if you want to take a look for mssql, that'd be great. There's also a number of unit tests to start you off that are commented out from laravel's suite.
knex.schema.createTable(args) .createTable(args) .dropTable(table)
Still left to-to:
A simple bench against building a simple query with a few where's showed about a 4x improvement from 0.5
Interested to hear any questions/thoughts people have on this, feel free to take a look through and let me know what you think. Hoping to get this out by the end of the month.
Very nice! Next up is getting Bookshelf to work with 0.6.x right?
Sent from my iPhone
referenced this pull request
Jun 4, 2014
The json values must be quoted and escaped