1 Star 0 Fork 0

LEARN / node-adodb

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README-EN.md 4.77 KB
一键复制 编辑 原始数据 按行查看 历史
nuintun 提交于 2019-05-29 11:04 . :pencil:Update docs

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[, x64]): 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!

Common access connection strings:

  • Access 2000-2003 (*.mdb): Provider=Microsoft.Jet.OLEDB.4.0;Data Source=node-adodb.mdb;
  • Access > 2007 (*.accdb): Provider=Microsoft.ACE.OLEDB.12.0;Data Source=adodb.accdb;Persist Security Info=False; or Provider=Microsoft.ACE.OLEDB.15.0;Data Source=adodb.accdb;Persist Security Info=False;

Notes:

The library need system support Microsoft.Jet.OLEDB.4.0 or Microsoft.ACE.OLEDB.12.0, Windows XP SP2 above support Microsoft.Jet.OLEDB.4.0 by default, Others need to install support!

Recommended use Microsoft.ACE.OLEDB.12.0, download: Microsoft.ACE.OLEDB.12.0

Electron

If you want to use this module in an electron app running from an asar package you'll need to make some changes.

  1. Move adodb.js outside the asar package (in this example I use electron-builder, the extraResources option can move the file outside the asar package)
"extraResources": [
  {
    "from": "./node_modules/node-adodb/lib/adodb.js",
    "to": "adodb.js"
  }
]
  1. Tell the module where to find adodb.js while running from an asar package (I added this in electron's main.js file)
// Are we running from inside an asar package ?
if (process.mainModule.filename.indexOf('app.asar') !== -1) {
  // In that case we need to set the correct path to adodb.js
  ADODB.PATH = './resources/adodb.js';
}
1
https://gitee.com/huoxd/node-adodb.git
git@gitee.com:huoxd/node-adodb.git
huoxd
node-adodb
node-adodb
master

搜索帮助