npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

virtuoso-connector

v1.0.3

Published

Run SPARQL/SQL queries directly on Virtuoso database with connection pool support.

Downloads

7

Readme

🔗 virtuoso-connector

Package that allows you to create a direct connection to the Virtuoso database and run queries on it. Connection can be used to execute both SQL and SPARQL queries, or even internal database stored procedures.

ℹ Background

Since there is no native Virtuoso driver for NodeJS, the only option is to use Java bindings, which enables communication between a JDBC driver and a NodeJS application.

The @naxmefy/jdbc package provides support for communication with the JDBC driver, which is appropriate because Virtuoso provides a JDBC driver and thus they can be used together. The only disadvantage of this approach is that the process needs to start JVM and whenever it crashes, it crashes the whole application. To prevent the crash of the whole application, the DatabaseConnection manages a pool of child processes (forks) (DatabaseConnectionChild) which are responsible for the queries execution.

Selection of the child process is made by Round Robin load balancing mechanism. Delegation of the execution is done in the form of sending messages through the IPC channel, with a unified interface defined in types.ts file. Once the query inside the message is being resolved by the child process, it sends a new message with the response back to the service. In case of a crash of the JVM, for instance, due to the broken connection with the database or segmentation fault, the child will be terminated and deleted from the pool. Because the child processes are detached from the parent, they do not crash the application, but only themselves.

⭐️ Features

  • connection pool,
  • support of SPARQL query builder syntax (@tpluscode/rdf-string, @tpluscode/sparql-builder),
  • support for executing stored procedures or even SQL

🚀 Installation

yarn add virtuoso-connector
npm install virtuoso-connector

Note: Install peer dependencies if needed

🤘🏻 Usage

import { DatabaseConnection } from 'virtuoso-connector'

const db = new DatabaseConnection({
  url: 'jdbc:virtuoso://127.0.0.1:1111/CHARSET=UTF-8',
  username: 'dba',
  password: 'dba',
  driverPath: '/usr/local/vos/lib/jdbc-4.2/virtjdbc4_2.jar',
  lazy: false,
  maxQueryTimeout: 360, // optional (in seconds), 0 = unlimited
  poolSize: 2 // max active connections
})

const results = await db.query(`
  SELECT ?s ?p ?o 
  WHERE { ?s ?p ?o }
  LIMIT 10
`)

results.forEach(result => {
  console.info(result.s, result.p, result.o)
})

// Destroy connection
db.destroy()
// Example preview of results (with LIMIT 1)
[{
  s: NamedNode {
    termType: 'NamedNode',
    value: 'http://www.openlinksw.com/virtrdf-data-formats#default-iid'
  },
  p: NamedNode {
    termType: 'NamedNode', 
    value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'
  },
  o: NamedNode {
    termType: 'NamedNode',
    value: 'http://www.openlinksw.com/schemas/virtrdf#QuadMapFormat'
  } 
}]