Skip to content

Latest commit

 

History

History
128 lines (95 loc) · 3.65 KB

README-EN.md

File metadata and controls

128 lines (95 loc) · 3.65 KB

node-adodb

A node.js javascript client implementing the ADODB protocol on windows.

NPM Version Download Status Windows Status Test Coverage Node Version Dependencies

Install

NPM

Introduction:

ES6
'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);
  });
ES7 async/await
'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();

API:

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

Debug:

Set env DEBUG=ADODB, see: debug

Extension:

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!

Notes:

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