Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ module.exports = {
setSequence: require('./set-sequence'),
sum: require('./sum'),
teardown: require('./teardown'),
update: require('./update')
update: require('./update'),
validateConnection: require('./validate-connection')
};
72 changes: 72 additions & 0 deletions helpers/validate-connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// ██╗ ██╗ █████╗ ██╗ ██╗██████╗ █████╗ ████████╗███████╗
// ██║ ██║██╔══██╗██║ ██║██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
// ██║ ██║███████║██║ ██║██║ ██║███████║ ██║ █████╗
// ╚██╗ ██╔╝██╔══██║██║ ██║██║ ██║██╔══██║ ██║ ██╔══╝
// ╚████╔╝ ██║ ██║███████╗██║██████╔╝██║ ██║ ██║ ███████╗
// ╚═══╝ ╚═╝ ╚═╝╚══════╝╚═╝╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝
//
// ██████╗ ██████╗ ███╗ ██╗███╗ ██╗███████╗ ██████╗████████╗██╗ ██████╗ ███╗ ██╗
// ██╔════╝██╔═══██╗████╗ ██║████╗ ██║██╔════╝██╔════╝╚══██╔══╝██║██╔═══██╗████╗ ██║
// ██║ ██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██║ ██║ ██║██║ ██║██╔██╗ ██║
// ██║ ██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██║ ██║ ██║██║ ██║██║╚██╗██║
// ╚██████╗╚██████╔╝██║ ╚████║██║ ╚████║███████╗╚██████╗ ██║ ██║╚██████╔╝██║ ╚████║
// ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
//

module.exports = require('machine').build({


friendlyName: 'Validate Connection',


description: 'Test connectivity with the database.',


inputs: {

datastore: {
description: 'The datastore to use for connections.',
extendedDescription: 'Datastores represent the config and manager required to obtain an active database connection.',
required: true,
type: 'ref'
}
},


exits: {

success: {
description: 'Connection to the database was successful.'
},

error: {
friendlyName: 'Error in connection',
description: 'A connection could not be obtained.'
}
},


fn: function validateConnection(inputs, exits) {
// Dependencies
var Helpers = require('./private');

// ╔═╗╔═╗╔═╗╦ ╦╔╗╔ ┌─┐┌─┐┌┐┌┌┐┌┌─┐┌─┐┌┬┐┬┌─┐┌┐┌
// ╚═╗╠═╝╠═╣║║║║║║ │ │ │││││││├┤ │ │ ││ ││││
// ╚═╝╩ ╩ ╩╚╩╝╝╚╝ └─┘└─┘┘└┘┘└┘└─┘└─┘ ┴ ┴└─┘┘└┘
// Spawn a new connection.
Helpers.connection.spawnConnection(inputs.datastore, function spawnConnectionCb(err, connection) {
if (err) {
return exits.error(err);
}

// Release the connection.
Helpers.connection.releaseConnection(connection, false, function releaseConnectionCb(err) {
if (err) {
return exits.error(err);
}

return exits.success();
}); // </ releaseConnection >
}); // </ spawnConnection >
}
});
15 changes: 15 additions & 0 deletions lib/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ module.exports = (function sailsPostgresql() {
});
},

validateConnection: function validateConnection(datastoreName, cb) {
var datastore = datastores[datastoreName];

Helpers.validateConnection({
datastore: datastore
}).switch({
error: function error(err) {
return cb(redactPasswords(err));
},
success: function success() {
return cb();
}
});
},


// ╔╦╗╔═╗╔═╗╦═╗╔╦╗╔═╗╦ ╦╔╗╔ ┌─┐┌─┐┌┐┌┌┐┌┌─┐┌─┐┌┬┐┬┌─┐┌┐┌
// ║ ║╣ ╠═╣╠╦╝ ║║║ ║║║║║║║ │ │ │││││││├┤ │ │ ││ ││││
Expand Down