Comparing version 0.4.10 to 0.4.11
@@ -1,2 +0,2 @@ | ||
// Knex.js 0.4.10 | ||
// Knex.js 0.4.11 | ||
// -------------- | ||
@@ -94,3 +94,3 @@ | ||
// Keep in sync with package.json | ||
knex.VERSION = '0.4.10'; | ||
knex.VERSION = '0.4.11'; | ||
@@ -97,0 +97,0 @@ // Runs a new transaction, taking a container and returning a promise |
@@ -37,2 +37,5 @@ // Builder | ||
// Valid values for the `order by` clause generation. | ||
var orderBys = ['asc', 'desc']; | ||
_.extend(Builder.prototype, Common, { | ||
@@ -300,3 +303,6 @@ | ||
orderBy: function(column, direction) { | ||
this.orders.push({column: column, direction: (direction || 'asc')}); | ||
if (!(direction instanceof Raw)) { | ||
if (!_.contains(orderBys, (direction || '').toLowerCase())) direction = 'asc'; | ||
} | ||
this.orders.push({column: column, direction: direction}); | ||
return this; | ||
@@ -303,0 +309,0 @@ }, |
{ | ||
"name": "knex", | ||
"version": "0.4.10", | ||
"version": "0.4.11", | ||
"description": "A query builder for Postgres, MySQL and SQLite3, designed to be flexible, portable, and fun to use.", | ||
@@ -5,0 +5,0 @@ "main": "knex.js", |
@@ -291,2 +291,36 @@ var _ = require('underscore'); | ||
it('should default to "asc" if no value is provided', function() { | ||
builder.orderBy('columnName'); | ||
expect(builder.orders[0].column).to.equal('columnName'); | ||
expect(builder.orders[0].direction).to.equal('asc'); | ||
}); | ||
it('should not allow any values other than "asc" or "desc"', function() { | ||
builder.orderBy('columnName', 'desc, select * from items'); | ||
expect(builder.orders[0].column).to.equal('columnName'); | ||
expect(builder.orders[0].direction).to.equal('asc'); | ||
}); | ||
it('should not allow capitalized "desc"', function() { | ||
builder.orderBy('columnName', 'DESC'); | ||
expect(builder.toString()).to.equal("select * order by `columnName` DESC"); | ||
builder.reset(); | ||
builder.orderBy('columnName', 'ASC'); | ||
expect(builder.toString()).to.equal("select * order by `columnName` ASC"); | ||
}); | ||
}); | ||
@@ -293,0 +327,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
229735
5968