Files
yunkong2.sql/lib/postgresql-client.js
2018-08-08 21:31:17 +08:00

159 lines
5.4 KiB
JavaScript

// Generated by CoffeeScript 1.10.0
(function() {
var ConnectionFactory, PostgreSQLClient, PostgreSQLClient2, PostgreSQLClientPool, PostgreSQLClientPool2, PostgreSQLConnectionFactory, PostgreSQLConnectionFactory2, SQLClient, SQLClientPool, pg,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty,
slice = [].slice;
SQLClient = require('sql-client/lib/sql-client').SQLClient;
SQLClientPool = require('sql-client/lib/sql-client-pool').SQLClientPool;
ConnectionFactory = require('sql-client/lib/connection-factory').ConnectionFactory;
pg = require('pg');
try {
if ((pg != null ? pg["native"] : void 0) != null) {
pg = pg["native"];
}
} catch(err) {
}
PostgreSQLConnectionFactory = (function(superClass) {
extend(PostgreSQLConnectionFactory, superClass);
function PostgreSQLConnectionFactory() {
this.pre_process_sql = bind(this.pre_process_sql, this);
this.open_connection = bind(this.open_connection, this);
return PostgreSQLConnectionFactory.__super__.constructor.apply(this, arguments);
}
PostgreSQLConnectionFactory.prototype.open_connection = function(connect_string, callback) {
var connection;
connection = new pg.Client(connect_string);
return connection.connect((function(_this) {
return function(err) {
return callback(err, connection);
};
})(this));
};
PostgreSQLConnectionFactory.prototype.pre_process_sql = function(sql, bindvars, callback) {
var index;
if ((sql != null) && (bindvars != null)) {
index = 1;
sql = sql.replace(/\?/g, (function() {
return '$' + index++;
}));
}
return callback(null, sql, bindvars);
};
return PostgreSQLConnectionFactory;
})(ConnectionFactory);
PostgreSQLClient = (function(superClass) {
extend(PostgreSQLClient, superClass);
function PostgreSQLClient() {
var options;
options = 1 <= arguments.length ? slice.call(arguments, 0) : [];
PostgreSQLClient.__super__.constructor.apply(this, slice.call(options).concat([new PostgreSQLConnectionFactory()]));
}
return PostgreSQLClient;
})(SQLClient);
PostgreSQLClientPool = (function(superClass) {
extend(PostgreSQLClientPool, superClass);
function PostgreSQLClientPool() {
var options;
options = 1 <= arguments.length ? slice.call(arguments, 0) : [];
PostgreSQLClientPool.__super__.constructor.apply(this, slice.call(options).concat([new PostgreSQLConnectionFactory()]));
}
return PostgreSQLClientPool;
})(SQLClientPool);
exports.PostgreSQLConnectionFactory = PostgreSQLConnectionFactory;
exports.PostgreSQLClient = PostgreSQLClient;
exports.PostgreSQLClientPool = PostgreSQLClientPool;
PostgreSQLConnectionFactory2 = (function(superClass) {
extend(PostgreSQLConnectionFactory2, superClass);
function PostgreSQLConnectionFactory2() {
this.close_connection = bind(this.close_connection, this);
this.open_connection = bind(this.open_connection, this);
return PostgreSQLConnectionFactory2.__super__.constructor.apply(this, arguments);
}
PostgreSQLConnectionFactory2.prototype.open_connection = function(connect_string, callback) {
return pg.connect(connect_string, (function(_this) {
return function(err, client, done_fn) {
var connection;
connection = client;
if (connection != null) {
connection._sqlclient_done = done_fn;
}
return callback(err, connection);
};
})(this));
};
PostgreSQLConnectionFactory2.prototype.close_connection = function(connection, callback) {
if ((connection != null ? connection._sqlclient_done : void 0) != null) {
connection._sqlclient_done();
return typeof callback === "function" ? callback(null) : void 0;
} else {
return PostgreSQLConnectionFactory2.__super__.close_connection.apply(this, arguments).close_connection(connection, callback);
}
};
return PostgreSQLConnectionFactory2;
})(PostgreSQLConnectionFactory);
PostgreSQLClient2 = (function(superClass) {
extend(PostgreSQLClient2, superClass);
function PostgreSQLClient2() {
var options;
options = 1 <= arguments.length ? slice.call(arguments, 0) : [];
PostgreSQLClient2.__super__.constructor.apply(this, slice.call(options).concat([new PostgreSQLConnectionFactory2()]));
}
return PostgreSQLClient2;
})(SQLClient);
PostgreSQLClientPool2 = (function(superClass) {
extend(PostgreSQLClientPool2, superClass);
function PostgreSQLClientPool2() {
var options;
options = 1 <= arguments.length ? slice.call(arguments, 0) : [];
PostgreSQLClientPool2.__super__.constructor.apply(this, slice.call(options).concat([new PostgreSQLConnectionFactory2()]));
}
return PostgreSQLClientPool2;
})(SQLClientPool);
exports.PostgreSQLConnectionFactory2 = PostgreSQLConnectionFactory2;
exports.PostgreSQLClient2 = PostgreSQLClient2;
exports.PostgreSQLClientPool2 = PostgreSQLClientPool2;
}).call(this);