Socket
Socket
Sign inDemoInstall

knex

Package Overview
Dependencies
3
Maintainers
1
Versions
252
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.2 to 0.4.3

117

clients/base/sqlite3/grammar.js

@@ -12,73 +12,74 @@ // SQLite3 Grammar

var Helpers = require('../../../lib/helpers').Helpers;
var baseGrammar = require('../grammar').baseGrammar;
var _ = require('underscore');
var Helpers = require('../../../lib/helpers').Helpers;
var baseGrammar = require('../grammar').baseGrammar;
// Extends the standard sql grammar, with any SQLite specific
// dialect oddities.
exports.grammar = _.defaults({
// Extends the standard sql grammar, with any SQLite specific
// dialect oddities.
exports.grammar = _.defaults({
// The keyword identifier wrapper format.
wrapValue: function(value) {
return (value !== '*' ? Helpers.format('"%s"', value) : "*");
},
// The keyword identifier wrapper format.
wrapValue: function(value) {
return (value !== '*' ? Helpers.format('"%s"', value) : "*");
},
// Compile the "order by" portions of the query.
compileOrders: function(qb, orders) {
if (orders.length === 0) return;
return "order by " + orders.map(function(order) {
return this.wrap(order.column) + " collate nocase " + order.direction;
}, this).join(', ');
},
// Compile the "order by" portions of the query.
compileOrders: function(qb, orders) {
if (orders.length === 0) return;
return "order by " + orders.map(function(order) {
return this.wrap(order.column) + " collate nocase " + order.direction;
}, this).join(', ');
},
// Compile an insert statement into SQL.
compileInsert: function(qb) {
var values = qb.values;
var table = this.wrapTable(qb.table);
var columns = _.pluck(values[0], 0);
// Compile an insert statement into SQL.
compileInsert: function(qb) {
var values = qb.values;
var table = this.wrapTable(qb.table);
var columns = _.pluck(values[0], 0);
// If there are any "where" clauses, we need to omit
// any bindings that may have been associated with them.
if (qb.wheres.length > 0) this.clearWhereBindings(qb);
// If there are any "where" clauses, we need to omit
// any bindings that may have been associated with them.
if (qb.wheres.length > 0) this.clearWhereBindings(qb);
// If there is only one record being inserted, we will just use the usual query
// grammar insert builder because no special syntax is needed for the single
// row inserts in SQLite. However, if there are multiples, we'll continue.
if (values.length === 1) {
var sql = 'insert into ' + table + ' ';
if (columns.length === 0) {
sql += 'default values';
} else {
sql += "(" + this.columnize(columns) + ") values " + "(" + this.parameterize(_.pluck(values[0], 1)) + ")";
// If there is only one record being inserted, we will just use the usual query
// grammar insert builder because no special syntax is needed for the single
// row inserts in SQLite. However, if there are multiples, we'll continue.
if (values.length === 1) {
var sql = 'insert into ' + table + ' ';
if (columns.length === 0) {
sql += 'default values';
} else {
sql += "(" + this.columnize(columns) + ") values " + "(" + this.parameterize(_.pluck(values[0], 1)) + ")";
}
return sql;
}
return sql;
}
var blocks = [];
var blocks = [];
// SQLite requires us to build the multi-row insert as a listing of select with
// unions joining them together. So we'll build out this list of columns and
// then join them all together with select unions to complete the queries.
for (var i = 0, l = columns.length; i < l; i++) {
blocks.push('? as ' + this.wrap(columns[i]));
}
// SQLite requires us to build the multi-row insert as a listing of select with
// unions joining them together. So we'll build out this list of columns and
// then join them all together with select unions to complete the queries.
for (var i = 0, l = columns.length; i < l; i++) {
blocks.push('? as ' + this.wrap(columns[i]));
}
var joinedColumns = blocks.join(', ');
blocks = [];
for (i = 0, l = values.length; i < l; i++) {
blocks.push(joinedColumns);
}
var joinedColumns = blocks.join(', ');
blocks = [];
for (i = 0, l = values.length; i < l; i++) {
blocks.push(joinedColumns);
}
return "insert into " + table + " (" + this.columnize(columns) + ") select " + blocks.join(' union all select ');
},
return "insert into " + table + " (" + this.columnize(columns) + ") select " + blocks.join(' union all select ');
},
// Compile a truncate table statement into SQL.
compileTruncate: function (qb) {
var sql = [];
var table = this.wrapTable(qb.table);
sql.push('delete from sqlite_sequence where name = ' + table);
sql.push('delete from ' + table);
return sql;
}
// Compile a truncate table statement into SQL.
compileTruncate: function (qb) {
var sql = [];
var table = this.wrapTable(qb.table);
sql.push('delete from sqlite_sequence where name = ' + table);
sql.push('delete from ' + table);
return sql;
}
}, baseGrammar);
}, baseGrammar);

@@ -85,0 +86,0 @@ });

@@ -9,2 +9,3 @@ // SQLite3 SchemaGrammar

var _ = require('underscore');
var grammar = require('./grammar').grammar;

@@ -11,0 +12,0 @@ var baseSchemaGrammar = require('../schemagrammar').baseSchemaGrammar;

// MySQL Grammar
// -------
var _ = require('underscore');
var Helpers = require('../../../lib/helpers').Helpers;

@@ -5,0 +5,0 @@ var baseGrammar = require('../../base/grammar').baseGrammar;

// MySQL SchemaGrammar
// -------
var _ = require('underscore');
var grammar = require('./grammar').grammar;

@@ -5,0 +5,0 @@ var baseSchemaGrammar = require('../../base/schemagrammar').baseSchemaGrammar;

// PostgreSQL Grammar
// -------
var _ = require('underscore');
var Helpers = require('../../../lib/helpers').Helpers;

@@ -5,0 +5,0 @@ var baseGrammar = require('../../base/grammar').baseGrammar;

// PostgreSQL SchemaGrammar
// -------
var _ = require('underscore');
var grammar = require('./grammar').grammar;

@@ -5,0 +5,0 @@ var baseSchemaGrammar = require('../../base/schemagrammar').baseSchemaGrammar;

// SQLite3 Grammar
// -------
var _ = require('underscore');
var Helpers = require('../../../lib/helpers').Helpers;

@@ -5,0 +5,0 @@ var baseGrammar = require('../../base/sqlite3/grammar').grammar;

// SQLite3 SchemaGrammar
// -------
var _ = require('underscore');
var baseSchemaGrammar = require('../../base/sqlite3/schemagrammar').schemaGrammar;

@@ -5,0 +5,0 @@

@@ -1,2 +0,2 @@

// Knex.js 0.4.2
// Knex.js 0.4.3
// --------------

@@ -94,3 +94,3 @@

// Keep in sync with package.json
knex.VERSION = '0.4.2';
knex.VERSION = '0.4.3';

@@ -97,0 +97,0 @@ // Runs a new transaction, taking a container and returning a promise

{
"name": "knex",
"version": "0.4.2",
"version": "0.4.3",
"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",

@@ -13,3 +13,2 @@ var mocha = require('mocha');

global._ = require('underscore');
global.whenResolve = require('when').resolve;

@@ -16,0 +15,0 @@ global.expect = chai.expect;

@@ -0,1 +1,2 @@

var _ = require('underscore');
var when = require('when');

@@ -2,0 +3,0 @@ var Builder = require('../../lib/builder').Builder;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc