Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added skeleton of pg driver

  • Loading branch information...
commit 8048f44f16dc6104a7176ab3773936483c10e502 1 parent 94c08b4
Roman Ostolosh authored
Showing with 81 additions and 0 deletions.
  1. +81 −0 lib/driver/pg.js
View
81 lib/driver/pg.js
@@ -0,0 +1,81 @@
+var util = require('util');
+var pg = require('pg');
+var Base = require('./../node_modules/node-db-migrate/lib/driver/base');
+var type = require('../node_modules/node-db-migrate/lib/data_type');
+
+
+var PgDriver = Base.extend({
+ init: function(connection) {
+ console.log("initing");
+ this._super();
+ this.connection = connection;
+ this.connection.connect();
+ },
+
+ createColumnDef: function(name, spec, options) {
+ return [name, spec.autoIncrement ? '' : this.mapDataType(spec.type), this.createColumnConstraint(spec, options)].join(' ');
+ },
+
+ createColumnConstraint: function(spec, options) {
+ var constraint = [];
+ if (spec.primaryKey && options.emitPrimaryKey) {
+ if (spec.autoIncrement) {
+ constraint.push('SERIAL');
+ } else {
+ constraint.push('PRIMARY KEY');
+ }
+ }
+
+ if (spec.notNull) {
+ constraint.push('NOT NULL');
+ }
+
+ if (spec.unique) {
+ constraint.push('UNIQUE');
+ }
+
+ if (spec.defaultValue) {
+ constraint.push('DEFAULT');
+ constraint.push(spec.defaultValue);
+ }
+
+ return constraint.join(' ');
+ },
+
+ renameTable: function(tableName, newTableName, callback) {
+ var sql = util.format('RENAME TABLE %s TO %s', tableName, newTableName);
+ this.runSql(sql, callback);
+ },
+
+ //removeColumn: function(tableName, columnName, callback) {
+ //},
+
+ //renameColumn: function(tableName, oldColumnName, newColumnName, callback) {
+ //};
+
+ //changeColumn: function(tableName, columnName, columnSpec, callback) {
+ //},
+
+ runSql: function() {
+ console.log("runSql performed");
+ console.log('connection');
+ console.log(this.connection);
+ console.log('arguments');
+ console.log(arguments);
+ this.connection.query.apply(this.connection, arguments);
+ },
+
+ all: function() {
+ this.connection.query.apply(this.connection, arguments);
+ },
+
+ close: function() {
+ this.connection.end();
+ }
+
+});
+
+exports.connect = function(config, callback) {
+ var db = config.db || new pg.Client(config);
+ callback(null, new PgDriver(db));
+};
Please sign in to comment.
Something went wrong with that request. Please try again.