Comparing version 0.2.0 to 0.2.1
@@ -192,3 +192,3 @@ var anyDB = require('any-db'); | ||
queryMethods.forEach(function (key) { | ||
extQuery[key] = function () { | ||
extQuery[key] = function extFn() { | ||
var q = query[key].apply(query, arguments); | ||
@@ -247,3 +247,13 @@ if (q.__extQuery) return q; | ||
+ columnName(column))]); | ||
} else if (table.aggregator) { | ||
var column = table; | ||
tableName = column.table.alias || column.table._name; | ||
tableName = tableName.split('.').slice(0, -1).join('.'); | ||
return all.concat([column.as(tableName + '.' | ||
+ columnName(column))]); | ||
} | ||
else { | ||
console.log(table); | ||
return all; | ||
} | ||
}, []); | ||
@@ -250,0 +260,0 @@ }; |
{ | ||
"name": "anydb-sql", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "anydb-sql combines node-anydb and node-sql into a single package full of awesomeness.", | ||
@@ -5,0 +5,0 @@ "main": "anydb-sql.js", |
@@ -44,11 +44,2 @@ var test = require('tap').test; | ||
t.test('hasMany columns', function(t) { | ||
//console.log(user.posts.id); | ||
var q = user.from( | ||
user.join(user.posts).on(user.id.equals(user.posts.userId))); | ||
q = q.selectDeep(user.id, user.posts, user.posts.user, user.posts.user.posts); | ||
console.log(q.toQuery().text); | ||
t.end(); | ||
}); | ||
t.test('insert exec', function(t) { | ||
@@ -110,4 +101,4 @@ user.insert({id: 1, name: 'test'}).exec(function(err, res) { | ||
t.test('allof', function(t) { | ||
var q = user.select(db.allOf(user, user)); | ||
t.test('selectDeep', function(t) { | ||
var q = user.from(user).selectDeep(user, user); | ||
var text = 'SELECT "users"."id" AS "users.id##",' | ||
@@ -120,12 +111,18 @@ + ' "users"."name" AS "users.name", "users"."id" AS "users.id##",' | ||
t.test('selectDeep treats aggregates properly', function(t) { | ||
var alias = db.allOf(user.posts.id.count().as('postCount'))[0].alias; | ||
t.equals(alias, 'users.postCount'); | ||
t.end(); | ||
}); | ||
t.test('allObject', function(t) { | ||
user.select(user.id, user.name).allObject("id", function(err, result) { | ||
t.notOk(err, "has no error " + err); | ||
t.notOk(err, "should have no error " + err); | ||
user.select(user.id, user.name).exec(function(err, data) { | ||
t.equals(Object.keys(result).length, data.length, "Amount of entries should match"); | ||
t.equals(Object.keys(result).length, data.length, | ||
"number of entries should match"); | ||
for (var i = 0; i < data.length; i++) | ||
t.equals(data[i].name, result[data[i].id], "Data should match"); | ||
t.equals(data[i].name, result[data[i].id], | ||
"data["+i+"] should match"); | ||
t.end(); | ||
@@ -132,0 +129,0 @@ }); |
27799
658