Skip to content

Commit 1e7f7f1

Browse files
authored
Initial read me concept
1 parent 67a3b52 commit 1e7f7f1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
11
# database-js-common
22
Common modules for database-js driver implementations
3+
4+
## About
5+
This is a module of useful functions for [database-js](https://github.com/mlaanderson/database-js) driver implementations.
6+
7+
## Usage
8+
````Javascript
9+
const Common = require("database-js-common");
10+
11+
...
12+
module.exports = {
13+
open: function(connection) {
14+
let params = Common.parseConnectionParams(connection.Parameters);
15+
let base = driver.createConnection({
16+
host: connection.Hostname || 'localhost',
17+
port: parseInt(connection.Port) || 3306,
18+
user: connection.Username || 'root',
19+
password: connection.Password,
20+
database: connection.Database,
21+
parameters: params
22+
});
23+
return new MySQL(base);
24+
}
25+
};
26+
````
27+
28+
## API
29+
#### parseConnectionParameters(paramstring: string, parseValues?: boolean = false)
30+
Parses a parameter string of the format key1=value1&key2=value2, optionally converting the string values into appropriate value types.
31+
32+
If the value types are to be converted, true and false are converted to booleans irrespective of case. Values are converted to numbers if they match the following regex ```/^[-+]?(\d+\.)?\d+(E[-+]?\d+)?$/i```.
33+
34+
If you need finer control of value conversions, leave parseValues at false and handle the conversions in your driver code.

0 commit comments

Comments
 (0)