A node.js javascript client implementing the ADODB protocol on windows.
'use strict';
const ADODB = require('node-adodb');
const connection = ADODB.open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=node-adodb.mdb;');
// Execute
connection
.execute('INSERT INTO Users(UserName, UserSex, UserAge) VALUES ("Newton", "Male", 25)')
.then(data => {
console.log(JSON.stringify(data, null, 2));
})
.catch(error => {
console.error(error);
});
// Execute with scalar
connection
.execute('INSERT INTO Users(UserName, UserSex, UserAge) VALUES ("Newton", "Male", 25)', 'SELECT @@Identity AS id')
.then(data => {
console.log(JSON.stringify(data, null, 2));
})
.catch(error => {
console.error(error);
});
// Query
connection
.query('SELECT * FROM Users')
.then(data => {
console.log(JSON.stringify(data, null, 2));
})
.catch(error => {
console.error(error);
});
// Schema
connection
.schema(20)
.then(schema => {
console.log(JSON.stringify(schema, null, 2));
})
.catch(error => {
console.error(error);
});
'use strict';
const ADODB = require('node-adodb');
const connection = ADODB.open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=node-adodb.mdb;');
async function query() {
try {
const users = await connection.query('SELECT * FROM Users');
console.log(JSON.stringify(users, null, 2));
} catch (error) {
console.error(error);
}
}
query();
ADODB.open(connection): ADODB
Initialization database link parameters.
ADODB.query(sql): Promise
Execute a SQL statement that returns a value.
ADODB.execute(sql[, scalar]): Promise
Execute a SQL statement with no return value or with updated statistics.
ADODB.schema(type[, criteria][, id]): Promise
Query database schema information. see: OpenSchema
Set env
DEBUG=ADODB
, see: debug
This library theory supports all databases on the Windows platform that support ADODB connections, and only need to change the database connection string to achieve the operation!
The library need system support for Microsoft.Jet.OLEDB.4.0, Windows XP SP2 above support system default, other need to upgrade their specific operation process, please refer to: How to obtain the Microsoft Jet 4 database engine of the new Service Pack