UNPKG

1.35 kBJavaScriptView Raw
1/**
2 * joola.io
3 *
4 * Copyright Joola Smart Solutions, Ltd. <info@joo.la>
5 *
6 * Licensed under GNU General Public License 3.0 or later.
7 * Some rights reserved. See LICENSE, AUTHORS.
8 *
9 * @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
10 */
11
12
13var
14 url = require('url'),
15 connector = require('../connectors/connector');
16
17var list = function (persist) {
18 var datasources = [];
19 _.each(joola.config.integration.datasources, function (ds) {
20 datasources.push(ds);
21 });
22
23 if (persist)
24 return datasources;
25 else
26 return ce.clone(datasources);
27};
28
29var get = function (datasourceid, persist) {
30 var datasource = _.find(list(false), function (ds) {
31
32 return ds.id.toLowerCase() == datasourceid.toLowerCase();
33 });
34
35 if (!datasource)
36 return null;
37
38 if (persist)
39 return datasource;
40 else
41 return ce.clone(datasource);
42};
43
44var validate = function (datasourceid, callback) {
45 var datasource = get(datasourceid);
46 var query = connector.createQuery();
47
48 query.sql = 'SELECT 1;';
49 query.limit = 1;
50 query.datasource = datasource;
51 connector.executeQuery(query, function (query, rows, fields, err) {
52 if (err)
53 return callback(err);
54
55 return callback(null, true);
56 });
57};
58
59exports.list = list;
60exports.get = get;
61exports.validate = validate;