Skip to content

Commit 3dca1d8

Browse files
author
Pavel Romanov
committed
Some docs
1 parent 0802bd9 commit 3dca1d8

File tree

4 files changed

+57
-24
lines changed

4 files changed

+57
-24
lines changed

README.MD

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# multi-data-source
2+
> Node.js library which helps developers to manage multiple RDBMS connections to different databases
3+
4+
[![NPM Version][npm-image]][npm-url]
5+
6+
## Installation
7+
8+
```sh
9+
npm install multi-data-source
10+
```
11+
12+
## Features
13+
14+
* Multiple data sources support
15+
* Multiple RDBMS support (only PostgreSQL and MySQL for now, but you feel free to create your own connector to favorite RDBMS)
16+
* Little query template engine
17+
* Single interface to pass query parameters to all RDBMS by built-in query param escape module
18+
19+
## Dependencies
20+
21+
* [pg](https://github.com/brianc/node-postgres) -- Postgres connector based on this module
22+
23+
## Usage example
24+
25+
26+
## Author
27+
28+
Pavel Romanov -- alkor@alkor.pw -- [GitHub](https://github.com/Shikyaro)
29+
30+
## License
31+
32+
Distributed under MIT License. See [`LICENSE`](./LICENSE) for more information;
33+
34+
[npm-image]: https://img.shields.io/npm/v/multi-data-source.svg?style=flat-square
35+
[npm-url]: https://npmjs.org/package/multi-data-source

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "multi-storage",
2+
"name": "multi-data-source",
33
"author": "Pavel Romanov <alkor@alkor.pw>",
44
"version": "0.0.1",
55
"scripts": {

query/escapeParams.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,26 @@ const processArray = (value, arrayFormattingRule = false) => {
2525
}
2626
return stringArray;
2727
};
28+
const wrapValue = value => {
29+
let resultValue = '\'';
30+
31+
for (let i = 0; i < value.length; i++) {
32+
const char = value[i];
33+
if (char === '\'') {
34+
resultValue += char + char;
35+
} else if (char === '\\') {
36+
resultValue += char + char;
37+
} else {
38+
resultValue += char;
39+
}
40+
}
41+
42+
resultValue += '\'';
43+
return resultValue;
44+
};
2845

2946
const escapeValue = (value, type) => {
30-
let literal = '';
47+
let strVal = '';
3148

3249
if (value === undefined || value === null) { // eslint-disable-line no-undefined
3350
return 'NULL';
@@ -42,28 +59,12 @@ const escapeValue = (value, type) => {
4259
} else if (Array.isArray(value) === true) {
4360
return processArray(value, type);
4461
} else if (value === Object(value)) {
45-
literal = JSON.stringify(value);
62+
strVal = JSON.stringify(value);
4663
} else {
47-
// create copy
48-
literal = value.toString().slice(0);
64+
strVal = value.toString().slice(0);
4965
}
5066

51-
let resultValue = '\'';
52-
53-
for (let i = 0; i < literal.length; i++) {
54-
const char = literal[i];
55-
if (char === '\'') {
56-
resultValue += char + char;
57-
} else if (char === '\\') {
58-
resultValue += char + char;
59-
} else {
60-
resultValue += char;
61-
}
62-
}
63-
64-
resultValue += '\'';
65-
66-
return resultValue;
67+
return wrapValue(strVal);
6768
};
6869

6970
module.exports = (query, params) => {

query/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,3 @@ module.exports = {
66
escapeParams,
77
QueryTemplater,
88
};
9-
10-
// TODO: (\/\*\*)@([a-zA-Z_\-0-9]*)\*([a-zA-Z\+\-\=_\'\"? \n$]*)(\*\/) -- may be regex for additions
11-
// TODO: example: /**@raceID*AND race_id = ? */

0 commit comments

Comments
 (0)