Browse files

Ready to roll with merge

  • Loading branch information...
1 parent 599a63b commit 00cb0923c64ac53331fb36ad2ce181a89c18aa72 @subsonic subsonic committed May 4, 2012
View
3 lib/index.js → index.js
@@ -1,5 +1,4 @@
-var pg = require("./postgres_db");
-
+var pg = require("./lib/postgres_db");
module.exports.connect = function(connection, callback) {
View
174 lib/postgres_db.js
@@ -7,6 +7,7 @@ var parseWhere = function(conditions) {
var where = {};
var params = [];
+
if(_.isObject(conditions) &! _.isArray(conditions)) {
var operations = {'=': '=', '!': '!=', '>': '>', '<': '<', '>=': '>=', '<=': '<=', '!=' : '<>', '<>': '<>'};
@@ -41,65 +42,98 @@ var parseWhere = function(conditions) {
var Query = function(sql, params, table) {
events.EventEmitter.call(this);
var self = this;
- this.sql = sql;
- this.params = params || [];
- this.table = table;
- this.db = table.db;
+ self.sql = sql;
+ self.params = params || [];
+ self.table = table;
+ self.db = table.db;
+ self.columns = ""
+ self.where = {};
+ self.limit = "";
+ self.order = "";
self.on('newListener', function(eventName){
- console.log('Adding a listener for ' + eventName);
if(eventName === 'row'){
//fire the query
- //self.execute(self);
- this.db.execute(self.sql,self.params);
+ self.each();
}
});
- this.order = function(){
- this.sql += util.format(" \nORDER BY %s", arguments[0]);
- return this;
+ self.order = function(){
+ self.sql += util.format(" \nORDER BY %s", arguments[0]);
+ return self;
}
- this.limit = function() {
+ self.limit = function() {
if(arguments.length > 1){
- this.sql += util.format(" \nLIMIT(%d,%d)", arguments[0], arguments[1]);
+ self.sql += util.format(" \nLIMIT(%d,%d)", arguments[0], arguments[1]);
}else{
- this.sql += " \nLIMIT " + arguments[0];
+ self.sql += " \nLIMIT " + arguments[0];
}
- return this;
+ return self;
};
- this.raiseError = function(err){
- this.error = err;
- return this;
+ self.raiseError = function(err){
+ self.error = err;
+ return self;
};
- this.parseArgs = function(args) {
+ self.parseArgs = function(args) {
+ if(_.isFunction(args[0])) return;
var columns = " * ";
var where = {};
//if the first argument is an array, columns are specified
if(args.length > 0 && _.isArray(args[0])){
columns = args[0].join(",");
- this.sql = this.sql.replace("*", columns);
+ self.sql = self.sql.replace("*", columns);
}else if(args.length > 1 && args[1].columns) {
- this.sql = this.sql.replace("*", args[1].columns);
+ self.sql = self.sql.replace("*", args[1].columns);
}else if (args.length > 0 && _.isNumber(args[0])){
var criteria = {};
- criteria[this.table.pk] = args[0];
+ criteria[self.table.pk] = args[0];
where = parseWhere(criteria);
- this.sql += where.sql;
- this.params = where.params;
+ self.sql += where.sql;
+ self.params = where.params;
}else if (args.length > 0 && _.isObject(args[0])){
where = parseWhere(args[0]);
- this.sql += where.sql;
- this.params = where.params;
+ self.sql += where.sql;
+ self.params = where.params;
}
- return this;
+ return self;
}
- this.execute = function(callback) {
- this.table.db.execute(this.sql, this.params, callback)
+ self.execute = function(callback) {
+ self.db.execute(self.sql, self.params, function(err,result){
+ if(callback) callback(err,result);
+ self.emit("executed");
+ })
}
+ self.each = function(callback) {
+ self.db.execute(self.sql,self.params, function(err,results){
+ if(err && callback) callback(err,self.raiseError(err));
+ else {
+ _.each(results, function(r){
+ self.emit("row", r);
+ if(callback) callback(null,r);
+ });
+ self.emit("end");
+ }
+ });
+ };
+
+ self.first = function(callback) {
+ self.sql += " LIMIT(1) ";
+ self.db.execute(self.sql,self.params, function(err,results){
+ if(err) callback(err,self.raiseError(err));
+ else callback(null,results[0]);
+ });
+ };
+ self.last = function(callback) {
+ self.sql += util.format(" ORDER BY %s DESC LIMIT(1) ", this.table.pk);
+ self.db.execute(self.sql,self.params, function(err,results){
+ if(err) callback(err,self.raiseError(err));
+ else callback(null,results[0]);
+ });
+ };
}
util.inherits(Query, events.EventEmitter);
@@ -109,11 +143,21 @@ var Table = function(tableName, pk, _db) {
this.pk = pk;
this.db = _db;
+ this.last = function(callback) {
+ this.find().last(callback);
+ };
+ this.first = function(callback) {
+ this.find().first(callback);
+ };
+
+ this.each = function(callback) {
+ this.find().each(callback);
+ };
+
this.find = function() {
var query = new Query("SELECT * FROM " + this.name, [], this);
query.parseArgs(arguments);
return query;
-
};
this.count = function(where) {
var query = new Query("SELECT COUNT(1) FROM " + this.name, [] ,this);
@@ -142,7 +186,7 @@ var Table = function(tableName, pk, _db) {
values.push(util.format('(%s)', v.join(', ')));
parameters.push(_.values(data[i]));
}
- sql += values.join(",\n");
+ sql += values.join(",\n") + " \nRETURN *";
return new Query(sql, _.flatten(parameters), this);
};
@@ -200,6 +244,7 @@ var PostgresDB = function(connection){
where table_schema NOT IN ('pg_catalog', 'information_schema')";
this.execute = function(sql, params, callback) {
+ //console.log("Executing " + sql)
var self = this;
pg.connect(self.connectionString, function(err,db){
self.emit("beforeExecute", self);
@@ -209,7 +254,7 @@ var PostgresDB = function(connection){
else {
if(results && results.rows.length > 0){
if(callback)callback(null,results.rows);
- }else{
+ }else {
if(callback)callback(null,results);
}
self.emit("executed");
@@ -232,6 +277,73 @@ var PostgresDB = function(connection){
callback(null,self);
});
};
+var _translateType = function(typeName) {
+ var _result = typeName;
+
+ switch(typeName){
+ case "pk" :
+ _result ="serial PRIMARY KEY";
+ break;
+ case "money" :
+ _result ="decimal(8,2)";
+ break;
+ case "date" :
+ _result = "timestamptz";
+ break;
+ case "string" :
+ _result ="varchar(255)";
+ break;
+ case "search" :
+ _result ="tsvector";
+ break;
+ case "int" :
+ _result ="int4";
+ break;
+ }
+ return _result;
+}
+
+var _containsPK = function(columns) {
+ return _.any(columns.values,"pk");
+}
+
+this.dropTable = function(tableName) {
+ return new Query("DROP TABLE IF EXISTS " + tableName + ";", [], this);
+}
+
+this.createTable = function(tableName, columns) {
+
+ var _sql ="CREATE TABLE " + tableName + "(";
+ var _cols = [];
+
+ //force a PK
+ if(!_containsPK(columns)){
+ columns.id = "pk";
+ }
+
+ for(var c in columns){
+
+ if(c == "timestamps"){
+ _cols.push("created_at timestamptz not null default 'now'");
+ _cols.push("updated_at timestamptz not null default 'now'");
+ }else{
+ var colName = c;
+ var colParts = columns[c].split(" ");
+ var colType = colParts[0];
+ var translated = _translateType(colType);
+ var extras = _.without(colParts,colType).join(" ");
+ var declaration = colName + " " + translated + " " + extras;
+ //console.log(declaration);
+ _cols.push(declaration);
+ }
+ }
+
+ _sql+= _cols.join(",") + ");";
+ //console.log(_sql);
+ return new Query(_sql, [], this);
+};
+
+
};
util.inherits(PostgresDB,events.EventEmitter);
View
88 lib/query.js
@@ -1,88 +0,0 @@
-var events =require('events');
-var util = require('util');
-var massive = require('./index');
-var _ = require('underscore')._;
-
-var Query = function(_sql,_params){
-
- var self = this;
- events.EventEmitter.call(self);
-
- self.params = _params || [];
- self.sql = _sql;
-
- self.on('newListener', function(eventName){
- console.log('Adding a listener for ' + eventName);
- if(eventName === 'row'){
- //fire the query
- massive.Client.execute(self);
- }
- });
-
- this._error = function(message) {
- self.error = message;
- return self;
- }
-
- this.execute = function(callback) {
- if (self.error) { callback(self.error); return; }
- massive.Client.execute(self,callback);
- };
-
- this.isSelect = function() {
- return self.sql.indexOf('SELECT') > -1;
- }
- this.limit = function (count, offset){
- var _limit = _.isUndefined(offset) ? util.format(' \nLIMIT %d', count) : util.format(' \nLIMIT(%d, %d)', count, offset);
- self.sql += _limit;
- return self;
- }
-
- this.columns = function(columns) {
- if (arguments.length > 1) { columns = _.toArray(arguments); }
- if (_.isArray(columns)) { columns = columns.join(', '); }
- self.sql = self.sql.replace('SELECT *', 'SELECT ' + columns);
- return self;
- }
-
- this.order = function(order) {
- self.sql += ' \nORDER BY ' + order;
- return self;
- }
-
- var _operations = {'=': '=', '!': '!=', '>': '>', '<': '<', '>=': '>=', '<=': '<=', '!=' : '<>', '<>': '<>'}
- this.where = function(conditions) {
- var _conditions = [];
- var seed = self.params.length;
-
- _.each(conditions, function(value, key) {
- var parts = key.trim().split(/ +/);
- var property = parts[0];
- var operation = _operations[parts[1]] || '=';
-
- if (_.isBoolean(value) || _.isNumber(value)) {
- _conditions.push(util.format('"%s" %s %d', property, operation, value));
- } else if (_.isArray(value)) {
- var arrayConditions = [];
- _.each(value, function(v) {
- arrayConditions.push('$' + ++seed);
- self.params.push(v);
- });
- _conditions.push(util.format('"%s" %s (%s)', property, operation == '!=' || operation == '<>' ? 'NOT IN' : 'IN', arrayConditions.join(', ')));
- } else {
- _conditions.push(util.format('"%s" %s %s', property, operation, '$' + ++seed));
- self.params.push(value);
- }
- });
-
- self.sql+= ' \nWHERE ' + _conditions.join(' \nAND ');
- return self;
- };
-}
-
-Query.error = function(message) {
- return new Query(null, null)._error(message);
-}
-
-util.inherits(Query,events.EventEmitter);
-module.exports = Query;
View
62 lib/table.js
@@ -1,62 +0,0 @@
-var _query = require('./query');
-var _ = require("underscore")._;
-var util = require("util");
-
-var Table = function(tableName, primaryKey) {
- this.tableName = tableName;
- this.primaryKey = primaryKey || "id";
-
- this.count = function(where) {
- return this._createQuery(util.format("SELECT COUNT(1) FROM %s", this.tableName), null, where);
- };
-
- this.all = function(where){
- return this._createQuery(util.format("SELECT * FROM %s", this.tableName), null, where);
- };
-
- this.destroy = function(where) {
- return this._createQuery(util.format("DELETE FROM %s", this.tableName), null, where);
- }
-
- this.insert = function(data) {
- if(!data) { return _query.error("insert should be called with data"); }
- if (!_.isArray(data)) { data = [data]; }
-
- var sql = util.format("INSERT INTO %s (%s) VALUES\n", this.tableName, _.keys(data[0]).join(", "));
- var parameters = [];
- var values = []
- for(var i = 0, seed = 0; i < data.length; ++i) {
- var v = _.map(data[i], function() { return '$' + ++seed;});
- values.push(util.format('(%s)', v.join(', ')));
- parameters.push(_.values(data[i]));
- }
- sql += values.join(",\n");
- return new _query(sql, _.flatten(parameters));
- };
-
-
- this.update = function(fields, where){
- if(_.isObject(fields) === false) { return _query.error("Update requires a hash of fields=>values to update to"); }
-
- var parameters = [];
- var f = [];
- var seed = 0;
- _.each(fields, function(value, key) {
- f.push(key + ' = $' + ++seed);
- parameters.push(value);
- });
- var sql = util.format("UPDATE %s SET %s", this.tableName, f.join(', '));
- return this._createQuery(sql, parameters, where);
- };
-
- this._createQuery = function(sql, parameters, where) {
- var query = new _query(sql, parameters)
- if (_.isUndefined(where)) { return query; }
- if (_.isObject(where)) { return query.where(where); }
- var criteria = {}
- criteria[this.primaryKey] = where;
- return query.where(criteria);
- }
-};
-
-module.exports = Table;
View
188 test/massive_spec.coffee
@@ -1,188 +0,0 @@
-massive = require("../lib/");
-should = require("should");
-util = require("util");
-
-# massive.connect("postgres://postgres@localhost/test");
-# describe "initialization", ->
-# m={}
-# before ->
-# m = new massive.table("products")
-
-# it "sets the table name", ->
-# m.tableName.should.equal("products")
-
-# it "defaults the pk to id", ->
-# m.primaryKey.should.equal("id")
-
-# describe "queries", ->
-# m = {}
-# beforeEach (done) ->
-# m = new massive.table("products")
-# done()
-
-# describe "sanity", ->
-# it "creates 2 separate query objects", ->
-# query1 = m.all()
-# query2 = m.all("name > 1")
-# query1.sql.should.not.equal(query2.sql)
-
-# describe "select", ->
-# it "runs a select star", ->
-# query = m.all()
-# query.sql.should.equal("SELECT * FROM products")
-# query.params.length.should.equal 0
-
-# it "adds columns when specified", ->
-# query =m.all().columns("name,price")
-# query.sql.should.equal("SELECT name,price FROM products")
-
-# it "adds columns as array when explicitely specified", ->
-# query =m.all().columns(["leto", "spice"])
-# query.sql.should.equal("SELECT leto, spice FROM products")
-
-# it "adds columns as array when implicitely specified", ->
-# query =m.all().columns("paul", "sand")
-# query.sql.should.equal("SELECT paul, sand FROM products")
-
-# it "adds a where when specified as an argument", ->
-# query = m.all({name : "steve"})
-# query.sql.should.equal("SELECT * FROM products \nWHERE \"name\" = $1")
-# query.params.length.should.equal 1
-
-# it "adds a where when specified as a method", ->
-# query = m.all().where({name : "steve"})
-# query.sql.should.equal("SELECT * FROM products \nWHERE \"name\" = $1")
-# query.params.length.should.equal 1
-
-# it "adds a where when id is a number", ->
-# query = m.all({id : 1})
-# query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" = 1")
-# query.params.length.should.equal 0
-
-# it "adds a where as a primary key", ->
-# query = m.all(5)
-# query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" = 5")
-# query.params.length.should.equal 0
-
-# it "tracks params when where specified", ->
-# query = m.all().where({name : "steve"})
-# query.params.length.should.equal 1
-
-# it "adds a LIMIT if specified", ->
-# query = m.all().where({name : "steve"}).limit(1);
-# query.sql.should.equal("SELECT * FROM products \nWHERE \"name\" = $1 \nLIMIT 1")
-# query.params.length.should.equal 1
-
-# it "adds an ORDER if specified", ->
-# query = m.all().where({name : "steve"}).order("name").limit(1);
-# query.sql.should.equal("SELECT * FROM products \nWHERE \"name\" = $1 \nORDER BY name \nLIMIT 1")
-# query.params.length.should.equal 1
-
-# it "handles greater than", ->
-# query = m.all().where({"id >" : "steve"})
-# query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" > $1")
-# query.params.length.should.equal 1
-
-# it "handles less than", ->
-# query = m.all({"id <" : "steve"})
-# query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" < $1")
-# query.params.length.should.equal 1
-
-# it "handles bang equal", ->
-# query = m.all({"id !=" : "steve"})
-# query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" <> $1")
-# query.params.length.should.equal 1
-
-# it "handles ineqaulity", ->
-# query = m.all({"id <>" : "steve"})
-# query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" <> $1")
-# query.params.length.should.equal 1
-
-# it "handles IN", ->
-# query = m.all({id : ["steve","juice","pete"]})
-# query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" IN ($1, $2, $3)")
-# query.params.length.should.equal 3
-
-# it "handles NOT IN", ->
-# query = m.all({"id != ": ["steve","juice","pete"]})
-# query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" NOT IN ($1, $2, $3)")
-# query.params.length.should.equal 3
-
-# it "handles inline goodness", ->
-# query = massive.run("select * from crazytown where id = $1", [1]);
-# query.sql.should.equal("select * from crazytown where id = $1")
-# query.params.length.should.equal 1
-
-# describe "destroy", ->
-# it "creates a delete everything", ->
-# query = m.destroy()
-# query.sql.should.equal "DELETE FROM products"
-# query.params.length.should.equal 0
-
-# it "uses where when specified as an argument", ->
-# query = m.destroy({id : 1})
-# query.sql.should.equal "DELETE FROM products \nWHERE \"id\" = 1"
-# query.params.length.should.equal 0
-
-# it "uses where when specified as a method", ->
-# query = m.destroy().where({id : 1});
-# query.sql.should.equal "DELETE FROM products \nWHERE \"id\" = 1"
-# query.params.length.should.equal 0
-
-# it "adds a where as a primary key", ->
-# query = m.destroy(6)
-# query.sql.should.equal("DELETE FROM products \nWHERE \"id\" = 6")
-# query.params.length.should.equal 0
-
-# describe "insert", ->
-# it "creates a basic insert with returning", ->
-# query = m.insert({name : "steve", price : 12.00})
-# query.sql.should.equal "INSERT INTO products (name, price) VALUES\n($1, $2)"
-# query.params.length.should.equal 2
-
-# it "creates a batch for item arrays", ->
-# items = [{title:"stuffy stuff", price: 12.00, desc : "bubble"},{title:"poofy poof", price: 24.00, desc : "glurp"}];
-# query = m.insert(items)
-# query.sql.should.equal "INSERT INTO products (title, price, desc) VALUES\n($1, $2, $3),\n($4, $5, $6)"
-# query.params.length.should.equal 6
-
-# it "executes an error if no data was supplied", (done) ->
-# m.insert().execute (err) ->
-# err.should.equal('insert should be called with data')
-# done()
-
-# describe "updates", ->
-# it "creates a basic update", ->
-# query = m.update({name:"pumpkin", price:1000}, 12)
-# query.sql.should.equal("UPDATE products SET name = $1, price = $2 \nWHERE \"id\" = 12")
-# query.params.length.should.equal 2
-
-# it "creates a basic update with multi result", ->
-# query = m.update({name:"pumpkin", price:1000}, {"id >": 12})
-# query.sql.should.equal("UPDATE products SET name = $1, price = $2 \nWHERE \"id\" > 12")
-# query.params.length.should.equal 2
-
-# it "updates all rows", ->
-# query = m.update({name:"leto", sand: true})
-# query.sql.should.equal("UPDATE products SET name = $1, sand = $2")
-# query.params.length.should.equal 2
-
-# it "throws if values are not passed", (done) ->
-# m.update().execute (err) ->
-# err.should.equal('Update requires a hash of fields=>values to update to')
-# done()
-
-# describe "aggregates", ->
-# it "counts with SELECT COUNT", ->
-# query = m.count()
-# query.sql.should.equal("SELECT COUNT(1) FROM products");
-
-
-# describe "events", ->
-# beforeEach (done)->
-# done()
-
-# it "fires iterator when new events are added", ->
-# query = m.all();
-# query.on "row", (row)->
-# should.exist(row.name)
View
57 test/pg_query_spec.coffee
@@ -1,4 +1,4 @@
-massive = require("../lib/");
+massive = require("../index");
should = require("should");
util = require("util");
@@ -116,13 +116,13 @@ describe "Postgres Queries", ->
describe "insert", ->
it "creates a basic insert with returning", ->
query = db.products.insert({name : "steve", price : 12.00})
- query.sql.should.equal "INSERT INTO products (name, price) VALUES\n($1, $2)"
+ query.sql.should.equal "INSERT INTO products (name, price) VALUES\n($1, $2) \nRETURN *"
query.params.length.should.equal 2
it "creates a batch for item arrays", ->
items = [{title:"stuffy stuff", price: 12.00, desc : "bubble"},{title:"poofy poof", price: 24.00, desc : "glurp"}];
query = db.products.insert(items)
- query.sql.should.equal "INSERT INTO products (title, price, desc) VALUES\n($1, $2, $3),\n($4, $5, $6)"
+ query.sql.should.equal "INSERT INTO products (title, price, desc) VALUES\n($1, $2, $3),\n($4, $5, $6) \nRETURN *"
query.params.length.should.equal 6
it "throws an error if no data was supplied", ->
@@ -163,9 +163,60 @@ describe "Postgres Queries", ->
it "fires iterator when new events are added", ->
query = db.products.find ->
query.on "row", (row)->
+ console.log(row)
should.exist(row)
+ describe "iterators on tables and queries", ->
+ it "has an each method", ->
+ query = db.products.find()
+ should.exist query.each
+
+ it "should iterate", ->
+ query = db.products.find()
+ query.each (err,result) ->
+ should.exist result
+
+ it "tables should have an each method", ->
+ should.exist db.products.each
+ #this is a stupid test
+ it "iterates on the table", ->
+ count = 0
+ db.products.each (err,result) ->
+ count++
+ count.should.be.greaterThan 0
+ describe "singles on queries and tables", ->
+ it "query has a first method", ->
+ query = db.products.find()
+ should.exist query.first
+
+ it "query returns a single item", (done)->
+ query = db.products.find()
+ query.first (err,result) ->
+ should.exist result
+ done()
+
+ it "table has a first method", ->
+ should.exist db.products.first
+
+ it "returns the first item in table", ->
+ db.products.first (err,result) ->
+ should.exist(result)
+
+ it "has a last method", ->
+ query = db.products.find()
+ should.exist query.last
+
+ it "returns a single item", (done)->
+ query = db.products.find()
+ query.last (err,result) ->
+ should.exist result
+ done()
+ it "table has a first method", ->
+ should.exist db.products.last
+ it "returns the first item in table", ->
+ db.products.last (err,result) ->
+ should.exist(result)
View
52 test/pg_schema_spec.coffee
@@ -0,0 +1,52 @@
+massive = require("../index");
+should = require("should");
+util = require("util");
+
+
+describe "schema queries", ->
+ db = null
+ before (done) ->
+ massive.connect "postgres://postgres@localhost/test", (err,_db) ->
+ db = _db
+ done()
+
+ it "should exist", ->
+ should.exist db
+
+ describe "dropTable", ->
+ it "creates a drop statement", ->
+ db.dropTable("cheese").sql.should.equal("DROP TABLE IF EXISTS cheese;");
+
+ describe "create table", ->
+
+ it "adds a column with NULL declaration", ->
+ query = db.createTable "cheese", {bucket:"beef NOT NULL PLEASE"}
+ query.sql.indexOf("bucket beef NOT NULL PLEASE").should.be.greaterThan(0)
+
+ it "adds an ID of serial by default", ->
+ query = db.createTable "cheese",{title:"string"}
+ query.sql.indexOf("id serial PRIMARY KEY").should.be.greaterThan(0)
+
+ it "adds a varchar 255 for string", ->
+ query = db.createTable "cheese",{title:"string"}
+ query.sql.indexOf("title varchar(255)").should.be.greaterThan(0)
+
+ it "adds a varchar 255 for string with null", ->
+ query = db.createTable "cheese",{title:"string null"}
+ query.sql.indexOf("title varchar(255) null").should.be.greaterThan(0)
+
+ it "adds a decimal(8,2) for money", ->
+ query = db.createTable "cheese",{price:"money"}
+ query.sql.indexOf("price decimal(8,2)").should.be.greaterThan(0)
+
+ it "adds a timestamptz for date", ->
+ query = db.createTable "cheese",{created:"date"}
+ query.sql.indexOf("created timestamptz").should.be.greaterThan(0)
+
+ it "adds a bool for... bool", ->
+ query = db.createTable "cheese",{stuff:"bool"}
+ query.sql.indexOf("stuff bool").should.be.greaterThan(0)
+
+ it "adds created and updated for timestamps", ->
+ query = db.createTable "cheese",{timestamps:true}
+ query.sql.indexOf("created_at timestamptz not null default 'now',updated_at timestamptz not null default 'now'").should.be.greaterThan(0)
View
8 test/client_spec.coffee → test/pg_spec.coffee
@@ -1,4 +1,4 @@
-massive = require("../lib/");
+massive = require("../index");
should = require("should");
util = require("util");
@@ -9,10 +9,10 @@ describe "Connections", ->
db = _db
#console.log(db)
done()
-
+
it "returns a new postgres db", ->
should.exist db
-
+
it "has a tables array", ->
should.exist db.tables
@@ -30,4 +30,4 @@ describe "Connections", ->
should.exist db.products
it "returns the pk", ->
- db.products.pk.should.equal("id")
+ db.products.pk.should.equal("id")
View
37 test/schema_spec.coffee
@@ -1,37 +0,0 @@
-# massive = require "../lib"
-# should = require "should"
-
-# describe "schema", ->
-# describe "create table", ->
-
-# it "adds a column with NULL declaration", ->
-# query = massive.createTable "cheese", {bucket:"beef NOT NULL PLEASE"}
-# query.sql.indexOf("bucket beef NOT NULL PLEASE").should.be.greaterThan(0)
-
-# it "adds an ID of serial by default", ->
-# query = massive.createTable "cheese",{title:"string"}
-# query.sql.indexOf("id serial PRIMARY KEY").should.be.greaterThan(0)
-
-# it "adds a varchar 255 for string", ->
-# query = massive.createTable "cheese",{title:"string"}
-# query.sql.indexOf("title varchar(255)").should.be.greaterThan(0)
-
-# it "adds a varchar 255 for string with null", ->
-# query = massive.createTable "cheese",{title:"string null"}
-# query.sql.indexOf("title varchar(255) null").should.be.greaterThan(0)
-
-# it "adds a decimal(8,2) for money", ->
-# query = massive.createTable "cheese",{price:"money"}
-# query.sql.indexOf("price decimal(8,2)").should.be.greaterThan(0)
-
-# it "adds a timestamptz for date", ->
-# query = massive.createTable "cheese",{created:"date"}
-# query.sql.indexOf("created timestamptz").should.be.greaterThan(0)
-
-# it "adds a bool for... bool", ->
-# query = massive.createTable "cheese",{stuff:"bool"}
-# query.sql.indexOf("stuff bool").should.be.greaterThan(0)
-
-# it "adds created and updated for timestamps", ->
-# query = massive.createTable "cheese",{timestamps:true}
-# query.sql.indexOf("created_at timestamptz not null default 'now',updated_at timestamptz not null default 'now'").should.be.greaterThan(0)

0 comments on commit 00cb092

Please sign in to comment.