mirror of
https://github.com/knex/knex.git
synced 2025-12-27 15:08:47 +00:00
docs work, test cleanup, adding fix for #287
This commit is contained in:
parent
1aa226e7ba
commit
94e896fd41
@ -1,10 +1,14 @@
|
||||
# .travis.yml
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- '0.8'
|
||||
- '0.10'
|
||||
- '0.11'
|
||||
|
||||
before_install:
|
||||
- 'npm update npm'
|
||||
|
||||
before_script:
|
||||
- psql -c 'create database knex_test;' -U postgres
|
||||
- mysql -e 'create database knex_test;'
|
||||
|
||||
16
README.md
16
README.md
@ -1,16 +1,20 @@
|
||||
Knex.js
|
||||
knex.js
|
||||
-----
|
||||
|
||||
SQL that is flexible, portable, and fun to use.
|
||||
SQL that is flexible, portable, and fun to use!
|
||||
|
||||
[](https://travis-ci.org/tgriesser/knex)
|
||||
|
||||
### [Full Documentation Site: knexjs.org](http://knexjs.org)
|
||||
|
||||
A batteries-included, multi-dialect (MySQL, PostgreSQL, SQLite3, WebSQL) SQL query builder for Node.js, featuring
|
||||
[transactions](http://knexjs.org/#Transactions), [connection pooling](http://knexjs.org/#Initialize-pool),
|
||||
[streaming queries](http://knexjs.org/#Interface-streams), both a [promise](http://knexjs.org/#Interface-promise) and
|
||||
[callback](http://knexjs.org/#Interface-callback) API, and a [thorough test suite](https://travis-ci.org/tgriesser/knex).
|
||||
A batteries-included, multi-dialect (MySQL, PostgreSQL, SQLite3, WebSQL) SQL query builder for Node.js, featuring:
|
||||
|
||||
- [transactions](http://knexjs.org/#Transactions)
|
||||
- [connection pooling](http://knexjs.org/#Initialize-pool)
|
||||
- [streaming queries](http://knexjs.org/#Interface-streams)
|
||||
- both a [promise](http://knexjs.org/#Interface-promises) and [callback](http://knexjs.org/#Interface-callback) API
|
||||
- a [thorough test suite](https://travis-ci.org/tgriesser/knex)
|
||||
- the ability to [run in the Browser](http://knexjs.org/#faq-browser)
|
||||
|
||||
For Docs, FAQ, and other information, see: http://knexjs.org
|
||||
|
||||
|
||||
24
index.html
24
index.html
@ -63,14 +63,14 @@
|
||||
<li>– <a href="#Configuring-migration-config">migrations</a></li>
|
||||
</ul>
|
||||
|
||||
<a class="toc_title" href="#Interfaces">
|
||||
<a class="toc_title" href="#Interface">
|
||||
Interfaces
|
||||
</a>
|
||||
<ul class="toc_section">
|
||||
<li>– <a href="#Configuring-promises">promises</a></li>
|
||||
<li>– <a href="#Configuring-callbacks">callbacks</a></li>
|
||||
<li>– <a href="#Configuring-streams">streams</a></li>
|
||||
<li>– <a href="#Configuring-events">events</a></li>
|
||||
<li>– <a href="#Interface-promises">promises</a></li>
|
||||
<li>– <a href="#Interface-callbacks">callbacks</a></li>
|
||||
<li>– <a href="#Interface-streams">streams</a></li>
|
||||
<li>– <a href="#Interface-events">events</a></li>
|
||||
</ul>
|
||||
|
||||
<a class="toc_title" href="#Builder">
|
||||
@ -1275,14 +1275,13 @@ knex.schema.createTable('accounts', function() {
|
||||
});
|
||||
</pre>
|
||||
|
||||
<h3 id="raw-queries">Raw Queries:</h3>
|
||||
|
||||
<h2 id="Raw">knex.raw</h2>
|
||||
|
||||
<h3 id="Raw-Expressions">Raw Expressions:</h3>
|
||||
|
||||
<p>
|
||||
Sometimes you may need to use a raw expression in a query. These expressions will be injected
|
||||
into the query as strings, so be careful not to create any SQL injection points!
|
||||
To create a raw expression, you may use the <tt>knex.raw</tt> function.
|
||||
Sometimes you may need to use a raw expression in a query. Raw query object may be injected pretty much
|
||||
anywhere you want, properly
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
@ -1356,8 +1355,7 @@ knex.raw('select * from users where id = 1').then(function(resp) {
|
||||
|
||||
<p id="faq-debug">
|
||||
<b class="header">How do I debug?</b><br />
|
||||
If you pass <tt>{debug: true}</tt> as one of the options in your initialize settings, you can see all of the query calls being made. Sometimes you need to dive a bit further into
|
||||
the various calls and see what all is going on behind the scenes. I'd recommend
|
||||
If you pass <tt>{debug: true}</tt> as one of the options in your initialize settings, you can see all of the query calls being made. Sometimes you need to dive a bit further into the various calls and see what all is going on behind the scenes. I'd recommend
|
||||
<a href="https://github.com/dannycoates/node-inspector">node-inspector</a>, which allows you to debug code with <tt>debugger</tt> statements like you would in the browser.
|
||||
</p>
|
||||
|
||||
@ -1717,4 +1715,4 @@ process.stderr.on('data', function() {
|
||||
var sqlite3 = Knex({client: 'sqlite3'});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
@ -22,7 +22,10 @@ Formatter_PG.prototype.operators = [
|
||||
|
||||
// Wraps a value (column, tableName) with the correct ticks.
|
||||
Formatter_PG.prototype.wrapValue = function(value) {
|
||||
return (value !== '*' ? '"' + value + '"' : '*');
|
||||
if (value === '*') return value;
|
||||
var matched = value.match(/(.*?)(\[[0-9]\])/);
|
||||
if (matched) return this.wrapValue(matched[1]) + matched[2];
|
||||
return '"' + value + '"';
|
||||
};
|
||||
|
||||
// Memoize the calls to "wrap" for a little extra perf.
|
||||
|
||||
@ -8,9 +8,9 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^1.9.1",
|
||||
"chai-as-promised": "~4.1.0",
|
||||
"jshint": "~2.5.0",
|
||||
"minimist": "^0.1.0",
|
||||
"chai-as-promised": "^4.1.0",
|
||||
"jshint": "^2.5.0",
|
||||
"minimist": "~0.0.9",
|
||||
"mocha": "^1.20.0",
|
||||
"mysql": "^2.3.1",
|
||||
"node-uuid": "~1.4.0",
|
||||
@ -71,4 +71,4 @@
|
||||
"LICENSE"
|
||||
],
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -55,9 +55,9 @@ module.exports = function(knex) {
|
||||
table.text('about').comment('A comment.');
|
||||
table.timestamps();
|
||||
}).testSql(function(tester) {
|
||||
// tester('mysql', ['create table `test_table_one` (`id` bigint unsigned not null auto_increment primary key, `first_name` varchar(255), `last_name` varchar(255), `email` varchar(255) null, `logins` int default \'1\', `about` text comment \'A comment.\', `created_at` datetime, `updated_at` datetime) default character set utf8 engine = InnoDB comment = \'A table comment.\'','alter table `test_table_one` add index test_table_one_first_name_index(`first_name`)','alter table `test_table_one` add unique test_table_one_email_unique(`email`)','alter table `test_table_one` add index test_table_one_logins_index(`logins`)']);
|
||||
// tester('postgresql', ['create table "test_table_one" ("id" bigserial primary key, "first_name" varchar(255), "last_name" varchar(255), "email" varchar(255) null, "logins" integer default \'1\', "about" text, "created_at" timestamp, "updated_at" timestamp)',"comment on column \"test_table_one\".\"logins\" is NULL",'comment on column "test_table_one"."about" is \'A comment.\'','create index test_table_one_first_name_index on "test_table_one" ("first_name")','alter table "test_table_one" add constraint test_table_one_email_unique unique ("email")','create index test_table_one_logins_index on "test_table_one" ("logins")','comment on table "test_table_one" is \'A table comment.\'']);
|
||||
// tester('sqlite3', ['create table "test_table_one" ("id" integer not null primary key autoincrement, "first_name" varchar(255), "last_name" varchar(255), "email" varchar(255) null, "logins" integer default \'1\', "about" text, "created_at" datetime, "updated_at" datetime)','create index test_table_one_first_name_index on "test_table_one" ("first_name")','create unique index test_table_one_email_unique on "test_table_one" ("email")','create index test_table_one_logins_index on "test_table_one" ("logins")']);
|
||||
tester('mysql', ['create table `test_table_one` (`id` bigint unsigned not null auto_increment primary key, `first_name` varchar(255), `last_name` varchar(255), `email` varchar(255) null, `logins` int default \'1\', `about` text comment \'A comment.\', `created_at` datetime, `updated_at` datetime) engine = InnoDB comment = \'A table comment.\'','alter table `test_table_one` add index test_table_one_first_name_index(`first_name`)','alter table `test_table_one` add unique test_table_one_email_unique(`email`)','alter table `test_table_one` add index test_table_one_logins_index(`logins`)']);
|
||||
tester('postgresql', ['create table "test_table_one" ("id" bigserial primary key, "first_name" varchar(255), "last_name" varchar(255), "email" varchar(255) null, "logins" integer default \'1\', "about" text, "created_at" timestamp, "updated_at" timestamp)',"comment on column \"test_table_one\".\"logins\" is NULL",'comment on column "test_table_one"."about" is \'A comment.\'','create index test_table_one_first_name_index on "test_table_one" ("first_name")','alter table "test_table_one" add constraint test_table_one_email_unique unique ("email")','create index test_table_one_logins_index on "test_table_one" ("logins")','comment on table "test_table_one" is \'A table comment.\'']);
|
||||
tester('sqlite3', ['create table "test_table_one" ("id" integer not null primary key autoincrement, "first_name" varchar(255), "last_name" varchar(255), "email" varchar(255) null, "logins" integer default \'1\', "about" text, "created_at" datetime, "updated_at" datetime)','create index test_table_one_first_name_index on "test_table_one" ("first_name")','create unique index test_table_one_email_unique on "test_table_one" ("email")','create index test_table_one_logins_index on "test_table_one" ("logins")']);
|
||||
});
|
||||
});
|
||||
|
||||
@ -70,7 +70,7 @@ module.exports = function(knex) {
|
||||
table.text('details');
|
||||
table.tinyint('status');
|
||||
}).testSql(function(tester){
|
||||
tester('mysql', ['create table `test_table_two` (`id` int unsigned not null auto_increment primary key, `account_id` int, `details` text, `status` tinyint) default character set utf8 engine = InnoDB']);
|
||||
tester('mysql', ['create table `test_table_two` (`id` int unsigned not null auto_increment primary key, `account_id` int, `details` text, `status` tinyint) engine = InnoDB']);
|
||||
});
|
||||
});
|
||||
|
||||
@ -81,7 +81,7 @@ module.exports = function(knex) {
|
||||
table.integer('main').primary();
|
||||
table.text('paragraph').defaultTo('Lorem ipsum Qui quis qui in.');
|
||||
}).testSql(function(tester) {
|
||||
tester('mysql', ['create table `test_table_three` (`main` int, `paragraph` text) default character set utf8 engine = InnoDB','alter table `test_table_three` add primary key test_table_three_main_primary(`main`)']);
|
||||
tester('mysql', ['create table `test_table_three` (`main` int, `paragraph` text) engine = InnoDB','alter table `test_table_three` add primary key test_table_three_main_primary(`main`)']);
|
||||
tester('postgresql', ['create table "test_table_three" ("main" integer, "paragraph" text default \'Lorem ipsum Qui quis qui in.\')','alter table "test_table_three" add primary key ("main")']);
|
||||
tester('sqlite3', ['create table "test_table_three" ("main" integer, "paragraph" text default \'Lorem ipsum Qui quis qui in.\', primary key ("main"))']);
|
||||
});
|
||||
@ -93,7 +93,7 @@ module.exports = function(knex) {
|
||||
table.enum('enum_value', ['a', 'b', 'c']);
|
||||
table.uuid('uuid').notNull();
|
||||
}).testSql(function(tester) {
|
||||
tester('mysql', ['create table `datatype_test` (`enum_value` enum(\'a\', \'b\', \'c\'), `uuid` char(36) not null) default character set utf8']);
|
||||
tester('mysql', ['create table `datatype_test` (`enum_value` enum(\'a\', \'b\', \'c\'), `uuid` char(36) not null)']);
|
||||
tester('postgresql', ['create table "datatype_test" ("enum_value" text check (enum_value in (\'a\', \'b\', \'c\')), "uuid" uuid not null)']);
|
||||
tester('sqlite3', ['create table "datatype_test" ("enum_value" varchar, "uuid" char(36) not null)']);
|
||||
});
|
||||
@ -107,7 +107,7 @@ module.exports = function(knex) {
|
||||
.references('id')
|
||||
.inTable('test_table_two');
|
||||
}).testSql(function(tester) {
|
||||
tester('mysql', ['create table `test_foreign_table_two` (`id` int unsigned not null auto_increment primary key, `fkey_two` int unsigned) default character set utf8','alter table `test_foreign_table_two` add constraint test_foreign_table_two_fkey_two_foreign foreign key (`fkey_two`) references `test_table_two` (`id`)']);
|
||||
tester('mysql', ['create table `test_foreign_table_two` (`id` int unsigned not null auto_increment primary key, `fkey_two` int unsigned)','alter table `test_foreign_table_two` add constraint test_foreign_table_two_fkey_two_foreign foreign key (`fkey_two`) references `test_table_two` (`id`)']);
|
||||
tester('postgresql', ['create table "test_foreign_table_two" ("id" serial primary key, "fkey_two" integer)','alter table "test_foreign_table_two" add constraint test_foreign_table_two_fkey_two_foreign foreign key ("fkey_two") references "test_table_two" ("id")']);
|
||||
tester('sqlite3', ['create table "test_foreign_table_two" ("id" integer not null primary key autoincrement, "fkey_two" integer, foreign key("fkey_two") references "test_table_two"("id"))']);
|
||||
});
|
||||
@ -122,7 +122,7 @@ module.exports = function(knex) {
|
||||
table.tinyint('status');
|
||||
table.unique(['column_a', 'column_b']);
|
||||
}).testSql(function(tester) {
|
||||
tester('mysql', ['create table `composite_key_test` (`column_a` int, `column_b` int, `details` text, `status` tinyint) default character set utf8','alter table `composite_key_test` add unique composite_key_test_column_a_column_b_unique(`column_a`, `column_b`)']);
|
||||
tester('mysql', ['create table `composite_key_test` (`column_a` int, `column_b` int, `details` text, `status` tinyint)','alter table `composite_key_test` add unique composite_key_test_column_a_column_b_unique(`column_a`, `column_b`)']);
|
||||
tester('postgresql', ['create table "composite_key_test" ("column_a" integer, "column_b" integer, "details" text, "status" smallint)','alter table "composite_key_test" add constraint composite_key_test_column_a_column_b_unique unique ("column_a", "column_b")']);
|
||||
tester('sqlite3', ['create table "composite_key_test" ("column_a" integer, "column_b" integer, "details" text, "status" tinyint)','create unique index composite_key_test_column_a_column_b_unique on "composite_key_test" ("column_a", "column_b")']);
|
||||
}).then(function() {
|
||||
|
||||
@ -648,6 +648,11 @@ module.exports = function(pgclient, mysqlclient, sqlite3client) {
|
||||
expect(err).to.equal("The operator \"isnt\" is not permitted");
|
||||
});
|
||||
|
||||
it("#287 - wraps correctly for arrays", function() {
|
||||
var str = sql().select('*').from('value').join('table', 'table.array_column[1]', '=', raw('?', 1)).toString();
|
||||
expect(str).to.equal('select * from "value" inner join "table" on "table"."array_column"[1] = \'1\'');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user