5.1.8 • Published 10 months ago

mysql-abstraction v5.1.8

Weekly downloads
72
License
LGPL-3.0
Repository
github
Last release
10 months ago

Build Status Coverage Status

This is an abstraction layer built on https://github.com/felixge/node-mysql it add's various helper methods, helps deal with transactions and supports promises.

Example usage:

var Connection, mysql, q;

mysql = require('mysql-abstraction')({
  user: process.env.MYSQL_USER,
  host: process.env.MYSQL_HOST,
  password: process.env.MYSQL_PASSWORD,
  connectionLimit: 100
});

//select then update using a transaction
q = new mysql.Connection(true);
q.q({ q:'SELECT something FROM table WHERE id=?',params:[1],lock:1,cb: function(err,data){
    //do something with data
    q.q( { q:'UPDATE table SET something=? WHERE id=?',params:['something else',1],function(){
        q.end()
    }})
} })

//count the number of rows
q = new mysql.Connection();
q.count({ q:'SELECT count(*) FROM table',cb: function(err,data){
    //do something with data
    console.log(data);
} })

//fetch the first row
q = new mysql.Connection();
q.row({ q:'SELECT something FROM table WHERE id=1',cb: function(err,data){
    //do something with data
    console.log(data);
} })

// using promises
q = new mysql.Connection();
q.count({ q:'SELECT count(*) FROM table' }).then((data) => {
    // do something with data
}).catch((err) => {
    // do something with error
})

// using async/await

async function getCount() {
    try {
        q = new mysql.Connection();
        const data = await q.count({ q:'SELECT count(*) FROM table' })
        // do something with data
    } catch (err) {
        // do something with err
    }
}

getCount()

See tests/ for more usage examples

Note when deadlocks are automatically rolled back and queries are reissued any autoincrement columns aren't reverted, see http://stackoverflow.com/questions/14758625/mysql-auto-increment-columns-on-transaction-commit-and-rollback for more details

There is a crude stats collection via the connection.stats prameter which counts the number of select/update/delete/insert queries per connection, you can disable stats collection by setting connection.gatherStats to false

5.1.8

10 months ago

5.1.7

1 year ago

5.1.6

2 years ago

5.1.5

2 years ago

5.1.4

2 years ago

5.1.3

3 years ago

5.1.2

3 years ago

5.1.1

3 years ago

5.1.0

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

4.3.2

4 years ago

4.3.1

5 years ago

4.3.0

5 years ago

4.2.0

5 years ago

4.1.0

6 years ago

4.0.0

6 years ago

3.1.0

6 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.2.2

7 years ago

2.2.1

8 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.0

8 years ago

1.5.0

9 years ago

1.4.0

9 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.0

9 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.15

10 years ago

0.0.14

10 years ago