Skip to content
This repository has been archived by the owner on Mar 4, 2019. It is now read-only.

Commit

Permalink
MySQL Working...
Browse files Browse the repository at this point in the history
  • Loading branch information
subsonic committed May 5, 2012
1 parent 1897ab0 commit 7b524ae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
6 changes: 3 additions & 3 deletions examples/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ var _ = require("underscore")._;



massive.connect("postgres://postgres@localhost/test", function(err,db) {
//massive.connect({user : "root", password : "", database : "test"}, function(err,db) {

//massive.connect("postgres://postgres@localhost/test", function(err,db) {
massive.connect({user : "root", password : "", database : "test"}, function(err,db) {
console.log("err " + err)
var dropProducts = db.dropTable("products").execute(function(err,data){
console.log("Products table dropped");
createProducts();
Expand Down
3 changes: 2 additions & 1 deletion examples/evented.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var massive = require("../index");
var util = require("util");
var _ = require("underscore")._;

massive.connect("postgres://postgres@localhost/test", function(err, db){
//massive.connect("postgres://postgres@localhost/test", function(err, db){
massive.connect({user : "root", password : "", database : "test"}, function(err,db) {
var dropProducts = db.dropTable("products");

var createProducts = db.createTable("products", {
Expand Down
34 changes: 16 additions & 18 deletions lib/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,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") + " \nRETURNING *";
sql += values.join(",\n");
return new Query(sql, _.flatten(parameters), this);
};

Expand All @@ -197,7 +197,7 @@ var Table = function(tableName, pk, _db) {
var f = [];
var seed = 0;
_.each(fields, function(value, key) {
f.push(key + ' = $' + ++seed);
f.push(key + ' = ?');
parameters.push(value);
});
var sql = util.format("UPDATE %s SET %s", this.name, f.join(', '));
Expand All @@ -222,6 +222,7 @@ var Table = function(tableName, pk, _db) {


var MySQL = function(credentials){
console.log("Well hello MySQL")
events.EventEmitter.call(this);
var self = this;
this.dbType = "MySQL";
Expand All @@ -230,21 +231,19 @@ var MySQL = function(credentials){
this.sql = "";
this.params = [];

this.tableSQL = "SELECT \
table_name as name, \
(select cu.column_name \
from \
information_schema.key_column_usage cu, \
information_schema.table_constraints tc \
where \
cu.constraint_name = tc.constraint_name \
and tc.table_name = ist.table_name \
) as pk \
from information_schema.tables ist \
where table_schema NOT IN ('pg_catalog', 'information_schema')";
this.tableSQL = "SELECT table_name as 'name', \
( \
select column_name from \
information_schema.key_column_usage \
where table_name = ist.table_name \
and constraint_name = 'PRIMARY' \
) as 'pk' \
from information_schema.tables ist \
where table_schema = '" + credentials.database + "'";


this.execute = function(sql, params, callback) {
//console.log("Executing " + sql)
console.log("Executing " + sql)
var client = mysql.createClient(credentials);

self.emit("beforeExecute", self);
Expand Down Expand Up @@ -316,8 +315,8 @@ this.createTable = function(tableName, columns) {
for(var c in columns){

if(c == "timestamps"){
_cols.push("created_at datetime not null");
_cols.push("updated_at timestamp not null default 'now'");
_cols.push("created_at datetime");
_cols.push("updated_at timestamp");
}else{
var colName = c;
var colParts = columns[c].split(" ");
Expand All @@ -331,7 +330,6 @@ this.createTable = function(tableName, columns) {
}

_sql+= _cols.join(",") + ");";
//console.log(_sql);
return new Query(_sql, [], new Table(tableName, columns.id, self));
};

Expand Down

0 comments on commit 7b524ae

Please sign in to comment.