Skip to content

Instantly share code, notes, and snippets.

@mariuz
Created November 19, 2019 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariuz/87266d930917114c276f64985a054849 to your computer and use it in GitHub Desktop.
Save mariuz/87266d930917114c276f64985a054849 to your computer and use it in GitHub Desktop.
Connect to firebird database with typescript using node-firebird-driver-native and run some queries
import { createNativeClient, getDefaultLibraryFilename } from 'node-firebird-driver-native';
const connect_options = { username: 'sysdba', password: 'masterkey' }
async function test() {
const client = createNativeClient(getDefaultLibraryFilename());
const attachment = await client.connect('localhost:/tmp/new-db.fdb', connect_options);
const transaction = await attachment.startTransaction();
await attachment.execute(transaction, 'create table t1 (n integer, d date)');
await transaction.commitRetaining();
const statement1 = await attachment.prepare(transaction, 'insert into t1 values (?, ?)');
await statement1.execute(transaction, [1, new Date()]);
await statement1.execute(transaction, [2, new Date()]);
await statement1.execute(transaction, [3, new Date()]);
await statement1.dispose();
const resultSet = await attachment.executeQuery(transaction, 'select n, d from t1 where n <= ?', [2]);
const rows = await resultSet.fetch();
for (const columns of rows)
console.log(`n: ${columns[0]}, d: ${columns[1]}`);
await resultSet.close();
await transaction.commit();
await attachment.dropDatabase();
await client.dispose();
}
test().then(() => console.log('Finish...'));
@kevinuzan
Copy link

Hello, I used this and now I'm facing an error where when I declare "import { createNativeClient, getDefaultLibraryFilename } from 'node-firebird-driver-native';" it sayd "devtools was disconnected from the page" would you know why and the solution for that?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment