| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Note
This is a fork of the original driver sqlanywhere/node-sqlanywhere which has not had any updates for several years and was no longer working with newer versions of NodeJS.
A modern, high-performance Node.js driver for SAP SQL Anywhere.
This driver is built using N-API, ensuring a stable and future-proof interface that is independent of the underlying JavaScript engine. It is fully async/await compatible, providing a clean and modern developer experience.
Caution
This has only been tested in my environment and 1 set of specific databases - your mileage may vary
If you are running into issues, feel free to open an issue, however on the off chance that this does work for you - please let me know via discussions
npm install @iqx-limited/sqlanywhereThe installation process will attempt to use pre-built binaries, if that fails, it will automatically compile the native C++ addon for your platform.
If dbcapi is only available as x86_64, you can keep your main Node.js app running natively on ARM and run only the SQL Anywhere driver work in a Rosetta-backed helper process.
Enable bridge mode:
SQLANYWHERE_BRIDGE=1 node app.jsOn MacOS ARM, bridge mode automatically starts the helper as:
arch -x86_64 <current-node-exec> <package>/bridge/server.jsOptional overrides:
Example with explicit executable + args:
SQLANYWHERE_BRIDGE=1 \
SQLANYWHERE_BRIDGE_EXECUTABLE=arch \
SQLANYWHERE_BRIDGE_ARGS='["-x86_64","/usr/local/bin/node","/absolute/path/to/node_modules/@iqx-limited/sqlanywhere/bridge/server.js"]' \
node app.jsTip
This package provides two entry points:
All examples below use the /promise entry point for modern, promise-based usage. If you prefer callbacks, use the main package import instead.
const sqlanywhere = require('@iqx-limited/sqlanywhere/promise');
// --- For security, use environment variables for credentials ---
const connParams = {
ServerName: process.env.DB_SERVER || 'demo',
UserID: process.env.DB_USER || 'DBA',
Password: process.env.DB_PASSWORD || 'sql'
};
async function main() {
const connection = sqlanywhere.createConnection();
try {
// 1. Connect to the database
console.log('Connecting...');
await connection.connect(connParams);
console.log('Connection successful!');
// 2. Execute a query with parameters
const products = await connection.exec(
'SELECT Name, Description FROM Products WHERE id = ?',
[301]
);
console.log('Query Result:', products[0]);
// output --> Query Result: { Name: 'Tee Shirt', Description: 'V-neck' }
} catch (error) {
console.error('An error occurred:', error);
} finally {
// 3. Disconnect when finished
console.log('Disconnecting...');
await connection.disconnect();
console.log('Disconnected.');
}
}
main();sqlanywhere.createConnection() Creates a new, uninitialized connection object.
connection.connect(params) Establishes a connection to the database. The params object can contain most valid SQL Anywhere connection properties.
connection.disconnect() or connection.close() Closes the database connection.
connection.exec(sql, [params]) Executes a SQL statement directly.
connection.prepare(sql) Prepares a SQL statement for later execution. Returns a Promise that resolves to a Statement object.
connection.commit() Commits the current transaction.
connection.rollback() Rolls back the current transaction.
statement.exec([params]) Executes a prepared statement. The return value is the same as connection.exec().
statement.getMoreResults() For procedures or batches that return multiple result sets, this method advances to the next result set. Returns a Promise that resolves to the next array of results. When no more result sets are available, the promise will reject with a "Procedure has completed" message.
statement.drop() Frees the resources associated with the prepared statement on the database server.
This driver provides comprehensive support for a wide range of SQL Anywhere data types, which are automatically mapped to the most appropriate JavaScript types:
| SQL Anywhere Type(s) | JavaScript Type |
|---|---|
| INTEGER, BIGINT, SMALLINT, TINYINT, DECIMAL, DOUBLE, FLOAT, BIT, etc. | number |
| VARCHAR, CHAR, LONG NVARCHAR, DATE, TIME, TIMESTAMP, UNIQUEIDENTIFIER, XML | string |
| BINARY, VARBINARY, LONG BINARY, ST_GEOMETRY | Buffer |
// Import from the main package:
import { debugLogging } from '@iqx-limited/sqlanywhere';
// or: const { debugLogging } = require('@iqx-limited/sqlanywhere');
// Or import from the /promise entry point:
import { debugLogging } from '@iqx-limited/sqlanywhere/promise';
// or: const { debugLogging } = require('@iqx-limited/sqlanywhere/promise');
// Then set to true
debugLogging(true);The project includes a comprehensive test suite that validates all driver functionality against a live database.
Configure Credentials: Copy the examples/.env.sample file to a new file named examples/.env and fill in your database connection details.
Run Tests: Execute the following command from the examples directory:
npm run test| Back | FazBrowse Home | New Git URL |