Tjek node.js-modullisten
- node-mysql — Et node.js-modul, der implementerer MySQL-protokollen
- node-mysql2 — Endnu en ren JS async-driver. Pipelining, udarbejdede redegørelser.
- node-mysql-libmysqlclient — MySQL asynkrone bindinger baseret på libmysqlclient
node-mysql ser simpelt nok ud:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'example.org',
user : 'bob',
password : 'secret',
});
connection.connect(function(err) {
// connected! (unless `err` is set)
});
Forespørgsler:
var post = {id: 1, title: 'Hello MySQL'};
var query = connection.query('INSERT INTO posts SET ?', post, function(err, result) {
// Neat!
});
console.log(query.sql); // INSERT INTO posts SET `id` = 1, `title` = 'Hello MySQL'