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

millenniumdb-driver

v1.7.5

Published

The official MillenniumDB driver for JavaScript

Downloads

64

Readme

MillenniumDB driver for JavaScript (Browser and Node.js)

Installation - npm

npm install millenniumdb-driver

Then you can require the MillenniumDB object module:

var MillenniumDB = require('millenniumdb-driver');

Installation - browser

Make the MillenniumDB object available globally with:

<!-- Direct reference non-minified -->
<script src="/lib/browser/millenniumdb-driver.js"></script>
<!-- Direct reference minified -->
<script src="/lib/browser/millenniumdb-driver.min.js"></script>

<!-- unpkg CDN non-minified -->
<script src="https://unpkg.com/millenniumdb-driver@latest/lib/browser/millenniumdb-driver.js"></script>
<!-- unpkg CDN minified -->
<script src="https://unpkg.com/millenniumdb-driver@latest/lib/browser/millenniumdb-driver.min.js"></script>

<!-- jsDelivr CDN non-minified -->
<script src="https://cdn.jsdelivr.net/npm/millenniumdb-driver@latest/lib/browser/millenniumdb-driver.js"></script>
<!-- jsDelivr CDN minified -->
<script src="https://cdn.jsdelivr.net/npm/millenniumdb-driver@latest/lib/browser/millenniumdb-driver.min.js"></script>

Or use the ESM versions

<script type="module">
  // Direct reference non-minified
  import MillenniumDB from '/lib/browser/millenniumdb-driver.esm.js';
  // Direct reference minified
  import MillenniumDB from '/lib/browser/millenniumdb-driver.esm.min.js';
  // unpkg CDN non-minified
  import MillenniumDB from 'https://unpkg.com/millenniumdb-driver@latest/lib/browser/millenniumdb-driver.esm.js';
  // unpkg CDN minified
  import MillenniumDB from 'https://unpkg.com/millenniumdb-driver@latest/lib/browser/millenniumdb-driver.esm.min.js';
  // jsDelivr CDN non-minified
  import MillenniumDB from 'https://cdn.jsdelivr.net/npm/millenniumdb-driver@latest/lib/browser/millenniumdb-driver.esm.js';
  // jsDelivr CDN minified
  import MillenniumDB from 'https://cdn.jsdelivr.net/npm/millenniumdb-driver@latest/lib/browser/millenniumdb-driver.esm.min.js';
</script>

Usage

Creating a Driver instance

First you must create a Driver instance:

const url = '<URL for the MillenniumDB server>';
const driver = MillenniumDB.driver(url)

When you are done with the driver, you should close it before exiting the application.

driver.close();

Usually you would like to have a single Driver instance in your application.

Acquiring a Session

For sending queries to the MillenniumDB server, you must acquire a session instance:

const session = driver.session();

Then you can send queries through your session

const query = 'MATCH (?from)-[:?type]->(?to) RETURN * LIMIT 10';
const result = session.run(query);

Consuming results

The alternatives for consuming results must never be mixed because it would generate undefined behavior on your client and/or server. It is important to mention that the session must be closed when your operations are done.

Streaming API

This is the preferred way to consume the results, as it is the only that does not hold all the results in memory, it just streams it to an observer object provided by the user. The observer must implement the following methods:

  • onVariables: First event trigerred, just once. It will return the variable names of the query.
  • onRecord: Subsequent events triggered for each record available in the query result. It will return a Record object.
  • onSuccess: Trigerred at the end of the query execution. It will return a summary for the query. No more events are triggered afterwards.
  • onError: Trigerred if an error occurs during the query execution. It will return an error. No more events are triggered afterwards. This could even happen before receiving the onVariables event.
result.subscribe({
  onVariables: (variables) => {
    console.log('The variables are:', variables);
  },
  onRecord: (record) => {
    // Do something with each record
  },
  onSuccess: (summary) => {
    console.log('Summary:', summary);
    session.close();
  },
  onError: (error) => {
    console.error('Error:', error);
    session.close();
  },
});

Promise-based API with async/await syntax

const variables = await result.variables();
const records = await result.records();
const summary = await result.summary();

Promise-based API with .then(), .catch(), .finally() syntax

// catch/finally are ommited for brevity

result.variables().then((variables) => {
    console.log('The variables are:', variables);
});

result.records().then((records) => {
    for (const record of records) {
        // Do something with each record
    }
});

result.summary().then((summary) => {
    console.log('Summary', summary);
});