Skip to content

Commit

Permalink
improving documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Mar 12, 2018
1 parent 83bafc1 commit 2ee3b8e
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 64 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

MariaDB node.js connector is a [mysql](https://www.npmjs.com/package/mysql) compatible driver, used to connect applications developed in Java to MariaDB and MySQL databases. MariaDB Connector/J is LGPL licensed.

Tracker link <a href="https://jira.mariadb.org/projects/CONJS/issues/">https://jira.mariadb.org/projects/CONJS/issues/</a>
Extended documentation of API : [Complete documentation](/documentation/readme.md)

## Status
[![Linux Build](https://travis-ci.org/rusher/mariadb-connector-nodejs.svg?branch=master)](https://travis-ci.org/rusher/mariadb-connector-nodejs)
Expand All @@ -24,7 +24,6 @@ Tracker link <a href="https://jira.mariadb.org/projects/CONJS/issues/">https://j
<img src="https://fakeimg.pl/350x200/?text=benchmark%202"/>
</p>


explain why good perfs (avoiding string concatenation, buffer are send are binary, not hexa string, ...)


Expand All @@ -47,3 +46,6 @@ For a Getting started guide, API docs, recipes, etc. see the
## Contributing
To get started with a development installation and learn more about contributing, please follow the instructions at our
[Developers Guide.](/documentation/developers-guide.md)

Tracker link <a href="https://jira.mariadb.org/projects/CONJS/issues/">https://jira.mariadb.org/projects/CONJS/issues/</a>

4 changes: 2 additions & 2 deletions benchmarks/benchmarkOne.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ var run = function() {
bench = new Bench(run);

var launchBenchs = function(path) {
var test = 'bench_select_one_user.js';
var test = 'bench_select_param.js';
var m = require(path + '/' + test);
bench.initFcts.push(m.initFct);
bench.add(m.title, m.displaySql, m.benchFct, m.onComplet);
bench.add(m.title, m.displaySql, m.benchFct, m.onComplete);
};

fs.access('./benchs', function(err) {
Expand Down
14 changes: 7 additions & 7 deletions benchmarks/benchmarks.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
var fs = require('fs');
var Bench = require('./common_benchmarks');
var bench;
const fs = require('fs');
const Bench = require('./common_benchmarks');
let bench;

var run = function() {
const run = function() {
bench.suite.run();
};

bench = new Bench(run);

var launchBenchs = function(path) {
const launchBenchs = function(path) {
fs.readdir(path, function(err, list) {
if (err) {
console.error(err);
return;
}

//launch all benchmarks
for (var i = 0; i < list.length; i++) {
var m = require('./benchs/' + list[i]);
for (let i = 0; i < list.length; i++) {
const m = require('./benchs/' + list[i]);
bench.initFcts.push(m.initFct);
bench.add(m.title, m.displaySql, m.benchFct, m.onComplete);
}
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchs/bench_basic_insert.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var assert = require('assert');
const assert = require('assert');

module.exports.title = 'simple insert';
module.exports.displaySql = 'INSERT INTO testn.perfTest(test) VALUES (?) (into BLACKHOLE ENGINE) ';
Expand Down
22 changes: 11 additions & 11 deletions benchmarks/benchs/bench_insert.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
var assert = require('assert');
const assert = require('assert');

var basechars = '123456789abcdefghijklmnop\\Z';
var chars = basechars.split('');
const basechars = '123456789abcdefghijklmnop\\Z';
const chars = basechars.split('');
chars.push('😎');
chars.push('🌶');
chars.push('🎤');
chars.push('🥂');

function randomString(length) {
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
let result = '';
for (let i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
return result;
}

var sqlTable = 'CREATE TABLE testn.perfTestText (id MEDIUMINT NOT NULL AUTO_INCREMENT,t0 text';
var sqlParam = '';
var sqlCol = 't0';
for (var i = 1; i < 10; i++) {
let sqlTable = 'CREATE TABLE testn.perfTestText (id MEDIUMINT NOT NULL AUTO_INCREMENT,t0 text';
let sqlParam = '';
let sqlCol = 't0';
for (let i = 1; i < 10; i++) {
sqlParam += ',?';
sqlCol += ',t' + i;
sqlTable += ',t' + i + ' text';
Expand All @@ -29,8 +29,8 @@ module.exports.displaySql =
'INSERT INTO testn.perfTestText VALUES (<100 ?>) (into BLACKHOLE ENGINE)';

module.exports.benchFct = function(conn, deferred) {
var params = [];
for (var i = 0; i < 10; i++) {
const params = [];
for (let i = 0; i < 10; i++) {
params.push(randomString(10));
}

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchs/bench_select_collation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var assert = require('assert');
const assert = require('assert');

module.exports.title = 'select multiple collation';
module.exports.displaySql = 'select * from information_schema.COLLATIONS';
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchs/bench_select_one_user.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var assert = require('assert');
const assert = require('assert');

module.exports.title = 'select one mysql.user';
module.exports.displaySql =
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/benchs/bench_select_param.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var assert = require('assert');
const assert = require('assert');

module.exports.title = 'select ?';
module.exports.displaySql = 'select ?';

module.exports.benchFct = function(conn, deferred) {
var rand = Math.floor(Math.random() * 50000000);
const rand = Math.floor(Math.random() * 50000000);
conn.query('select ? as t', [rand], function(err, rows) {
assert.ifError(err);
assert.equal(rand, rows[0].t);
Expand Down
74 changes: 39 additions & 35 deletions benchmarks/common_benchmarks.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
var Benchmark = require('benchmark');
var conf = require('../test/conf');
const Benchmark = require('benchmark');
const conf = require('../test/conf');

var colors = require('colors');
var mariadb = require('../index.js');
var mysql = require('mysql');
var mysql2 = require('mysql2');
var mariasqlC;
const colors = require('colors');
const mariadb = require('../index.js');
const mysql = require('mysql');
const mysql2 = require('mysql2');
let mariasqlC;
try {
mariasqlC = require('mariasql');
} catch (err) {
//mariasql not mandatory in dev to avoid having python, compiling ...
}

function Bench(callback) {
var dbReady = 0;
let dbReady = 0;
this.reportData = {};

var ready = function(name) {
const ready = function(name) {
console.log('driver for ' + name + ' connected');
dbReady++;
if (dbReady === (mariasqlC ? 4 : 3)) {
Expand All @@ -25,8 +25,12 @@ function Bench(callback) {
}
};

var config = conf.baseConfig;
const config = conf.baseConfig;
config.charsetNumber=224;
if (process.platform !== 'win32') {
config.socketPath= '\\\\.\\pipe\\MySQL';
}

this.CONN = {};

this.CONN['MYSQL'] = { drv: mysql.createConnection(config), desc: 'mysql' };
Expand All @@ -52,7 +56,7 @@ function Bench(callback) {
});

if (mariasqlC) {
var configC = Object.assign({}, common.config);
const configC = Object.assign({}, config);
configC.charset = undefined;

this.CONN['MARIASQLC'] = {
Expand All @@ -68,11 +72,11 @@ function Bench(callback) {
this.queue = true;
this.async = true;
this.minSamples = 200;
var bench = this;
const bench = this;
this.suite = new Benchmark.Suite('foo', {
// called when the suite starts running
onStart: function() {
for (var i = 0; i < bench.initFcts.length; i++) {
for (let i = 0; i < bench.initFcts.length; i++) {
if (bench.initFcts[i]) {
bench.initFcts[i].call(this, bench.CONN.MYSQL.drv);
}
Expand All @@ -85,11 +89,11 @@ function Bench(callback) {
mysql2.clearParserCache();

console.log(event.target.toString());
var drvType = event.target.options.drvType;
var benchTitle =
const drvType = event.target.options.drvType;
const benchTitle =
event.target.options.benchTitle + ' ( sql: ' + event.target.options.displaySql + ' )';
var iteration = 1 / event.target.times.period;
var variation = event.target.stats.rme;
const iteration = 1 / event.target.times.period;
const variation = event.target.stats.rme;

if (!bench.reportData[benchTitle]) {
bench.reportData[benchTitle] = [];
Expand Down Expand Up @@ -137,14 +141,14 @@ Bench.prototype.displayReport = function() {
.gray
);

var keys = Object.keys(this.reportData);
for (var i = 0; i < keys.length; i++) {
var base = 0;
var best = 0;
var data = this.reportData[keys[i]];
const keys = Object.keys(this.reportData);
for (let i = 0; i < keys.length; i++) {
let base = 0;
let best = 0;
let data = this.reportData[keys[i]];

for (var j = 0; j < data.length; j++) {
var o = data[j];
for (let j = 0; j < data.length; j++) {
let o = data[j];
if (o.drvType === (mariasqlC ? 'mariasqlC' : 'mysql')) {
base = o.iteration;
}
Expand All @@ -155,11 +159,11 @@ Bench.prototype.displayReport = function() {
console.log('');
console.log('bench : ' + keys[i]);

for (var j = 0; j < data.length; j++) {
var o = data[j];
var val = 100 * (o.iteration - base) / base;
var perc = simpleFormat.format(val);
var tt =
for (let j = 0; j < data.length; j++) {
let o = data[j];
const val = 100 * (o.iteration - base) / base;
const perc = simpleFormat.format(val);
const tt =
' ' +
this.fill(o.drvType, 10) +
' : ' +
Expand Down Expand Up @@ -196,7 +200,7 @@ Bench.prototype.fill = function(val, length, right) {
};

Bench.prototype.add = function(title, displaySql, fct, onComplete, conn) {
var self = this;
const self = this;

if (conn) {
this.suite.add({
Expand All @@ -221,7 +225,7 @@ Bench.prototype.add = function(title, displaySql, fct, onComplete, conn) {
fn: function(deferred) {
fct.call(self, self.CONN.MYSQL.drv, deferred);
},
onComplete: function() {
onComplete: () => {
if (onComplete) onComplete.call(self, self.CONN.MYSQL.drv);
},
async: this.async,
Expand All @@ -238,7 +242,7 @@ Bench.prototype.add = function(title, displaySql, fct, onComplete, conn) {
fn: function(deferred) {
fct.call(self, self.CONN.MYSQL.drv, deferred);
},
onComplete: function(defer) {
onComplete: () => {
if (onComplete) onComplete.call(self, self.CONN.MYSQL2.drv);
},
async: this.async,
Expand All @@ -255,7 +259,7 @@ Bench.prototype.add = function(title, displaySql, fct, onComplete, conn) {
fn: function(deferred) {
fct.call(self, self.CONN.MYSQL2.drv, deferred);
},
onComplete: function(defer) {
onComplete: () => {
if (onComplete) onComplete.call(self, self.CONN.MARIADB.drv);
},
async: this.async,
Expand All @@ -272,7 +276,7 @@ Bench.prototype.add = function(title, displaySql, fct, onComplete, conn) {
fn: function(deferred) {
fct.call(self, self.CONN.MARIADB.drv, deferred);
},
onComplete: function(defer) {
onComplete: () => {
if (onComplete) onComplete.call(self, self.CONN.MARIADB.drv);
},
async: this.async,
Expand All @@ -290,7 +294,7 @@ Bench.prototype.add = function(title, displaySql, fct, onComplete, conn) {
fn: function(deferred) {
fct.call(self, self.CONN.MARIASQLC.drv, deferred);
},
onComplete: function(defer) {
onComplete: () => {
if (onComplete) onComplete.call(self, self.CONN.MARIASQLC.drv);
},
async: this.async,
Expand Down
25 changes: 25 additions & 0 deletions documentation/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ Not implemented :

escape function are not implemented, since it can lead to injection.
statistic method is public in mysql, but not documented.

### Initiate a connection

For faster connections to localhost, either the Unix socket file to use (default /tmp/mysql.sock),
or, on Windows where the server has been started with the --enable-named-pipe option, the name (case-insensitive) of the named pipe to use (default MySQL).


This is done by setting the option 'socketPath' (host and port option are then ignored).
This permit to avoid TCP-IP layer.

If not on localhost, then hostname must be set, port is optional with default 3306.

```javascript
var mariadb = require('mariadb-connector');

//localhost on windows
var conn1 = mariadb.createConnection({socketPath: '\\\\.\\pipe\\MySQL'});

//localhost on unix
var conn2 = mariadb.createConnection({socketPath: '/tmp/mysql.sock'});

//not localhost
var conn3 = mariadb.createConnection({host: 'mydb.com', port:9999});
```


## Query
`connection.query(sql[, values][,callback])`
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nodejs-mariadb",
"name": "mariadb-connector",
"version": "0.0.1",
"description": "fast mysql/mariadb driver.",
"description": "fast mariadb/mysql driver.",
"main": "index.js",
"directories": {
"src": "src",
Expand Down

0 comments on commit 2ee3b8e

Please sign in to comment.