Total.js Node Database Management System (ORM)

1.0.9 · active · verified Wed Apr 22

The `dbms` package is a Node.js Object Relational Mapper (ORM) primarily designed for the Total.js framework. It offers a unified interface for interacting with various database systems, including PostgreSQL, MySQL, MariaDB, and Total.js's embedded TextDB, with partial support for MongoDB. Currently at version 1.0.9, the package was last updated approximately two years ago, suggesting a maintenance-focused release cadence tied to the Total.js ecosystem rather than independent rapid development. Its key differentiator is its deep integration with Total.js, exposing database access via a global `DBMS()` function within Total.js applications. This package operates exclusively within the CommonJS module system.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates initializing database connections with `dbms.init()` and performing basic `find`, `insert`, and `one` operations using the `DBMS()` global function, illustrating common patterns within a Total.js application.

const dbms = require('dbms');

// In a Total.js application, dbms.init() would typically be called once
// within a configuration or definition file (e.g., `/definitions/db.js`).
// This action makes the `DBMS()` function globally available.

// Initialize a PostgreSQL connection named 'default'
dbms.init('postgresql://user:password@localhost:5432/testdb?pooling=false');

// Initialize another PostgreSQL connection named 'mypg'
dbms.init('mypg', 'postgresql://user:password@localhost:5432/anothertestdb');

// --- Simulate Global DBMS() Function (for non-Total.js standalone use) ---
// In a real Total.js app, `DBMS()` would be globally available after init.
// This mock helps illustrate usage but isn't how it works natively outside Total.js.
function DBMS(name) {
  const _dbmsModule = require('dbms');
  return _dbmsModule(name);
}

// Example 1: Find records using the default database
DBMS().find('users').where('age', '>', 25).callback(function(err, response) {
    if (err) {
        console.error('Error finding users:', err);
        return;
    }
    console.log('Found users (default DB):', response);
});

// Example 2: Insert a new record into a named database ('mypg')
DBMS('mypg').insert('products', { name: 'New Widget', price: 99.99, stock: 100 }).callback(function(err, id) {
    if (err) {
        console.error('Error inserting product:', err);
        return;
    }
    console.log('Inserted product with ID (mypg DB):', id);
});

// Example 3: Find a single record
DBMS().one('settings').where('key', 'app_name').callback(function(err, setting) {
    if (err) {
        console.error('Error fetching setting:', err);
        return;
    }
    console.log('App Name setting:', setting);
});

// Note: Ensure the `pg` npm package is installed: `npm install pg`
// And replace `user` and `password` with actual credentials for the database.

view raw JSON →