Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@soinlabs/sybase

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@soinlabs/sybase

This library provides a Node.js bridge to connect to a Sybase database. It uses a Java bridge to facilitate the connection and query execution.

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
79
decreased by-19.39%
Maintainers
0
Weekly downloads
 
Created
Source

Sybase Node.js Bridge

Overview

This library provides a Node.js bridge to connect to a Sybase database. It uses a Java bridge to facilitate the connection and query execution.

Installation

npm install @soinlabs/sybase

Requirements

  • java 1.8+

Usage

Importing the Library

const Sybase = require('@soinlabs/sybase');

Creating a Sybase Instance

const sybase = new Sybase({
  host: 'localhost',
  port: 5000,
  database: 'sybase',
  username: 'username',
  password: 'password',
  encoding: 'utf8',
  pathToJavaBridge: '/path/to/JavaSybaseLink.jar', // Optional
  logTiming: true, //Logs on JAR side
  logs: true //Logs on Node.js side
});

Connecting to the Database

connect()

sybase.connect((err, data) => {
  if (err) {
    console.error(err);
    return;
  }
  console.log('Connected:', data);
});

connectAsync()

const data = await sybase.connectAsync();
console.log('Connected:', data);

Executing Queries

query(sqlQuery)

sybase.query('SELECT * FROM users', (err, result) => {
  if (err) {
    console.error(err);
    return;
  }
  console.log('Result:', result);
});

querySync(sqlQuery)

const result = await sybase.querySync('SELECT * FROM users');
console.log('Result:', result);

disconnect()

sybase.disconnect();

disconnectSync()

The disconnectSync method allows you to disconnect synchronously from the database and terminates the associated Java process

const sybase = new Sybase(...);
await sybase.disconnectSync();

isConnected()

const isConnected = sybase.isConnected();
console.log(`Is connected: ${isConnected}`);

transaction(queriesFunction)

Executes a series of queries within a transaction. If any of the queries fail, the transaction will be rolled back.

Example
async function main() {
  try {
    const result = await sybase.transaction(async (connection) => {
      const user = await connection.querySync('SELECT * FROM users WHERE id = 1');
      await connection.querySync(`UPDATE users SET name = 'John' WHERE id = 1`);
      return user;
    });
    console.log('Transaction successful, result:', result);
  } catch (err) {
    console.error('Transaction failed:', err);
  }
}

main();

Keywords

FAQs

Package last updated on 20 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc