Skip to content

Commit

Permalink
Merge pull request #19 from tonyd256/td-aff-4
Browse files Browse the repository at this point in the history
Update to Aff 4.0
  • Loading branch information
anttih authored Oct 19, 2017
2 parents 0621274 + 86ae9a5 commit 9862cba
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 141 deletions.
26 changes: 13 additions & 13 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "purescript-node-postgres",
"version": "2.0.0",
"version": "4.0.0",
"moduleType": [
"node"
],
Expand All @@ -26,22 +26,22 @@
"output"
],
"dependencies": {
"purescript-arrays": "^4.0.0",
"purescript-either": "^3.0.0",
"purescript-foreign": "^4.0.0",
"purescript-foldable-traversable": "^3.0.0",
"purescript-transformers": "^3.0.0",
"purescript-aff": "^3.0.0",
"purescript-integers": "^3.0.0",
"purescript-datetime": "^3.0.0",
"purescript-arrays": "^4.2.1",
"purescript-either": "^3.1.0",
"purescript-foreign": "^4.0.1",
"purescript-foldable-traversable": "^3.6.1",
"purescript-transformers": "^3.4.0",
"purescript-aff": "^4.0.0",
"purescript-integers": "^3.1.0",
"purescript-datetime": "^3.4.0",
"purescript-unsafe-coerce": "^3.0.0",
"purescript-nullable": "^3.0.0",
"purescript-prelude": "^3.0.0",
"purescript-foreign-generic": "^4.0.0"
"purescript-prelude": "^3.1.0",
"purescript-foreign-generic": "^5.0.0"
},
"devDependencies": {
"purescript-spec": "^1.0.0",
"purescript-spec": "^2.0.0",
"purescript-generics": "^4.0.0",
"purescript-js-date": "^4.0.0"
"purescript-js-date": "^5.1.0"
}
}
83 changes: 43 additions & 40 deletions src/Database/Postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,98 @@

var pg = require('pg');

exports["connect'"] = function (conString) {
return function(success, error) {
var client = new pg.Client(conString);
client.connect(function(err) {
if (err) {
error(err);
} else {
success(client);
}
})
return client;
exports.mkPool = function (conInfo) {
return function () {
return new pg.Pool(conInfo);
};
}

exports._withClient = function (conString, cb) {
return function(success, error) {
pg.connect(conString, function(err, client, done) {
exports["connect'"] = function (pool) {
return function(error, success) {
pool.connect(function(err, client) {
if (err) {
done(true);
return error(err);
}
cb(client)(function(v) {
done();
success(v);
}, function(err) {
done();
error(err);
})
} else {
success(client);
}
});
return function(cancelError, onCancelerError, onCancelerSuccess) {
onCancelerSuccess();
};
};
}

exports.runQuery_ = function (queryStr) {
exports.runQuery_ = function(queryStr) {
return function(client) {
return function(success, error) {
return function(error, success) {
client.query(queryStr, function(err, result) {
if (err) {
error(err);
} else {
success(result.rows);
}
})
});
return function(cancelError, onCancelerError, onCancelerSuccess) {
onCancelerSuccess();
};
};
};
}

exports.runQuery = function (queryStr) {
exports.runQuery = function(queryStr) {
return function(params) {
return function(client) {
return function(success, error) {
return function(error, success) {
client.query(queryStr, params, function(err, result) {
if (err) return error(err);
success(result.rows);
})
});
return function(cancelError, onCancelerError, onCancelerSuccess) {
onCancelerSuccess();
};
};
};
};
}

exports.runQueryValue_ = function (queryStr) {
exports.runQueryValue_ = function(queryStr) {
return function(client) {
return function(success, error) {
return function(error, success) {
client.query(queryStr, function(err, result) {
if (err) return error(err);
success(result.rows.length > 0 ? result.rows[0][result.fields[0].name] : undefined);
})
});
return function(cancelError, onCancelerError, onCancelerSuccess) {
onCancelerSuccess();
};
};
};
}

exports.runQueryValue = function (queryStr) {
exports.runQueryValue = function(queryStr) {
return function(params) {
return function(client) {
return function(success, error) {
return function(error, success) {
client.query(queryStr, params, function(err, result) {
if (err) return error(err);
success(result.rows.length > 0 ? result.rows[0][result.fields[0].name] : undefined);
})
});
return function(cancelError, onCancelerError, onCancelerSuccess) {
onCancelerSuccess();
};
};
};
};
}

exports.end = function (client) {
return function() {
client.end();
exports.release = function (client) {
return function () {
client.release();
};
}

exports.disconnect = function () {
pg.end();
exports.end = function(pool) {
return function() {
pool.end();
};
}
Loading

0 comments on commit 9862cba

Please sign in to comment.