• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jclo / kapp / 7492643875

11 Jan 2024 05:56PM UTC coverage: 76.125%. Remained the same
7492643875

push

github

jclo
Added kube-local.yaml to run KApp inside a kubernetes node.

258 of 333 branches covered (0.0%)

Branch coverage included in aggregate %.

7270 of 9556 relevant lines covered (76.08%)

1.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/server/libs/pgsql/api_without_pool.js
1
/** ****************************************************************************
×
2
 *
×
3
 * Public interface for the PostgreSQL database.
×
4
 * (this api doesn't use a pool - it is not used)
×
5
 *
×
6
 * api.js is just a literal object that contains a set of functions.
×
7
 * It can't be instantiated.
×
8
 *
×
9
 * Private Functions:
×
10
 *  . none,
×
11
 *
×
12
 *
×
13
 * Public Static Methods:
×
14
 *  . _getArgs                    returns the decoded arguments (for testing),
×
15
 *  . create                      establishes a connection to the database,
×
16
 *  . connect                     connects to the database,
×
17
 *  . query                       queries the database,
×
18
 *  . end                         removes the connection to the database,
×
19
 *
×
20
 *
×
21
 *
×
22
 * @namespace    -
×
23
 * @dependencies none
×
24
 * @exports      -
×
25
 * @author       -
×
26
 * @since        0.0.0
×
27
 * @version      -
×
28
 * ************************************************************************** */
×
29
/* eslint one-var: 0, semi-style: 0, no-underscore-dangle: 0 */
×
30

×
31

×
32
// -- Vendor Modules
×
33
const PG = require('pg');
×
34

×
35

×
36
// -- Local Modules
×
37
const U1 = require('../../dbi/util')
×
38
    , U2 = require('./util')
×
39
    ;
×
40

×
41

×
42
// -- Local Constants
×
43

×
44

×
45
// -- Local Variables
×
46

×
47

×
48
// -- Private Functions --------------------------------------------------------
×
49
// none,
×
50

×
51

×
52
// -- Public Static Methods ----------------------------------------------------
×
53

×
54
const PGSQL = {
×
55

×
56
  /**
×
57
   * Returns the decoded passed-in arguments.
×
58
   * (for testing purpose)
×
59
   *
×
60
   * @method (...args)
×
61
   * @public
×
62
   * @param {Array}         the query values,
×
63
   * @param {Function}      the callback function,
×
64
   * @returns {Array}       returns an array with the query, params, and callback,
×
65
   * @since 0.0.0
×
66
   */
×
67
  _getArgs(...args) {
×
68
    return U1._getArgs(...args);
×
69
  },
×
70

×
71
  /**
×
72
   * Establishes a connection to the database.
×
73
   *
×
74
   * @method (arg1, arg2, arg3, arg4)
×
75
   * @public
×
76
   * @param {String}        the database server url,
×
77
   * @param {String}        the database,
×
78
   * @param {String}        the user,
×
79
   * @param {String}        the user's password,
×
80
   * @returns {}            -,
×
81
   * @since 0.0.0
×
82
   */
×
83
  createConnection(host, database, user, password) {
×
84
    this.db = new PG.Client({
×
85
      host,
×
86
      port: 5432,
×
87
      database,
×
88
      user,
×
89
      password,
×
90
    });
×
91
  },
×
92

×
93
  /**
×
94
   * Connects to the database.
×
95
   *
×
96
   * @method ([arg1])
×
97
   * @public
×
98
   * @param {Function}      the function to call at the completion,
×
99
   * @returns {Object}      returns a promise,
×
100
   * @since 0.0.0
×
101
   */
×
102
  connect(callback) {
×
103
    return new Promise((resolve, reject) => {
×
104
      this.db.connect((err, result) => {
×
105
        if (err) {
×
106
          reject(err);
×
107
          if (callback) callback(err);
×
108
        } else {
×
109
          resolve(result);
×
110
          if (callback) callback(null, result);
×
111
        }
×
112
      });
×
113
    });
×
114
  },
×
115

×
116
  /**
×
117
   * Queries the database.
×
118
   *
×
119
   * @method (arg1, [arg2], [arg3])
×
120
   * @public
×
121
   * @param {String}        the query operation,
×
122
   * @param {Array}         the values to insert into the query,
×
123
   * @param {Function}      the function to call at the completion,
×
124
   * @returns {Object}      returns a promise,
×
125
   * @since 0.0.0
×
126
   */
×
127
  query(query, ...args) {
×
128
    const [params, convert, dump, callback] = this._getArgs(...args);
×
129

×
130
    let q = query;
×
131
    q = convert ? U1.convert(q, 'pgsql') : q;
×
132
    params.forEach((item, index) => { q = q.replace(/\?/, `$${index + 1}`); });
×
133
    if (dump) process.stdout.write(`${q}\n`);
×
134

×
135
    return new Promise((resolve, reject) => {
×
136
      this.db.query(query, params, (err, results, fields) => {
×
137
        if (err) {
×
138
          reject(err);
×
139
          if (callback) callback(err);
×
140
        } else {
×
141
          resolve(results);
×
142
          if (callback) callback(null, results, fields);
×
143
        }
×
144
      });
×
145
    });
×
146
  },
×
147

×
148
  /**
×
149
   * Removes the connection to the database.
×
150
   *
×
151
   * @method ([arg1])
×
152
   * @public
×
153
   * @param {Function}      the function to call at the completion,
×
154
   * @returns {Object}      returns a promise,
×
155
   * @since 0.0.0
×
156
   */
×
157
  end(callback) {
×
158
    return new Promise((resolve, reject) => {
×
159
      this.db.end((err) => {
×
160
        if (err) {
×
161
          reject(err);
×
162
          if (callback) callback(err);
×
163
        } else {
×
164
          resolve(true);
×
165
          if (callback) callback(null);
×
166
        }
×
167
      });
×
168
    });
×
169
  },
×
170

×
171

×
172
  // -- Specific to PgSQL ------------------------------------------------------
×
173

×
174
  /**
×
175
   * Converts MySQL types to PgSQL.
×
176
   *
×
177
   * @method (arg1)
×
178
   * @public
×
179
   * @param {String}        the SQL command for creating a table,
×
180
   * @returns {String}      returns the SQL command with PgSQL types,
×
181
   * @since 0.0.0
×
182
   */
×
183
  convertTypes(sql) {
×
184
    return U2.convertTypes(sql);
×
185
  },
×
186
};
×
187

×
188

×
189
// -- Export
×
190
module.exports = PGSQL;
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc