JugglingDB ORM

2.0.1 · abandoned · verified Wed Apr 22

JugglingDB is a JavaScript cross-database ORM designed for Node.js, offering a common interface to interact with various popular relational and NoSQL databases such as MySQL, PostgreSQL, MongoDB, Redis, SQLite, CouchDB, and Neo4j, along with an in-memory storage option. It also supported client-side usage via WebService and Memory adapters, enabling rich client-side applications to communicate with server-side JSON APIs. The npm package shows version 2.0.1 as the latest. However, active development on JugglingDB ceased around 2017-2018, as its core concepts and codebase were forked to create `loopback-datasource-juggler`, which continues to be actively maintained as part of the LoopBack framework. Consequently, JugglingDB itself is no longer maintained and does not receive updates or security patches. Its release cadence is non-existent, and it is not compatible with modern Node.js environments.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates defining a schema with the in-memory adapter, creating a model, and performing basic CRUD operations (create, find, update, delete) using async/await.

const Schema = require('jugglingdb').Schema;

// Use the in-memory adapter for a quick, no-install example
const schema = new Schema('memory', { debug: true });

const User = schema.define('User', {
  name: { type: String, limit: 50, index: true },
  email: { type: String, unique: true },
  age: { type: Number, default: 18 },
  createdAt: { type: Date, default: Date.now }
});

async function runExample() {
  try {
    // Auto-migrate the schema (create tables/collections if they don't exist)
    await schema.autoupdate(); 
    console.log('Schema autoupdated.');

    // Create a new user
    const newUser = await User.create({ name: 'Alice', email: 'alice@example.com', age: 30 });
    console.log('Created user:', newUser.toJSON());

    // Find a user by ID
    const foundUser = await User.findById(newUser.id);
    console.log('Found user by ID:', foundUser.toJSON());

    // Update a user
    await foundUser.updateAttributes({ age: 31 });
    console.log('Updated user:', foundUser.toJSON());

    // Find all users
    const allUsers = await User.all();
    console.log('All users:', allUsers.map(u => u.toJSON()));

    // Delete a user
    await foundUser.destroy();
    console.log('User deleted.');

    const remainingUsers = await User.count();
    console.log('Remaining users:', remainingUsers);

  } catch (err) {
    console.error('An error occurred:', err);
  } finally {
    // In a real application, you'd disconnect from the database here.
    // For 'memory' adapter, no explicit disconnect is usually needed.
    console.log('Example finished.');
  }
}

runExample();

view raw JSON →