Browse Source

allow multiple calls of on for index creation

auto-join
Sascha Depold 12 years ago
parent
commit
f894d445bd
  1. 2
      lib/dialect/postgres.js
  2. 5
      lib/node/createIndex.js
  3. 7
      test/dialects/indexes-tests.js

2
lib/dialect/postgres.js

@ -415,7 +415,7 @@ Postgres.prototype.visitIndexes = function(node) {
};
Postgres.prototype.visitCreateIndex = function(node) {
if (!node.options.columns) {
if (!node.options.columns || (node.options.columns.length === 0)) {
throw new Error('No columns defined!');
}

5
lib/node/createIndex.js

@ -12,7 +12,7 @@ module.exports = Node.define({
this.names = [];
this.columns = [];
this.valueSets = [];
this.options = { indexName: indexName };
this.options = { indexName: indexName, columns: [] };
},
unique: function() {
@ -36,7 +36,8 @@ module.exports = Node.define({
},
on: function() {
this.options.columns = Array.prototype.slice.call(arguments);
var args = Array.prototype.slice.call(arguments);
this.options.columns = this.options.columns.concat(args);
return this;
},

7
test/dialects/indexes-tests.js

@ -38,6 +38,13 @@ Harness.test({
sqlite: "CREATE INDEX \"post_id_userId\" ON \"post\" (\"post\".\"userId\",\"post\".\"id\")"
});
Harness.test({
query: post.indexes().create().on(post.userId).on(post.id),
pg: "CREATE INDEX \"post_id_userId\" ON \"post\" (\"post\".\"userId\",\"post\".\"id\")",
mysql: "CREATE INDEX `post_id_userId` ON `post` (`post`.`userId`,`post`.`id`)",
sqlite: "CREATE INDEX \"post_id_userId\" ON \"post\" (\"post\".\"userId\",\"post\".\"id\")"
});
Harness.test({
query: post.indexes().create(),
pg: { text: 'No columns defined!', throws: true },

Loading…
Cancel
Save