Skip to main content

Database Overview

Loopar uses Sequelize ORM (version 7) as its database abstraction layer, providing a robust and flexible way to interact with multiple database systems.

Supported Databases

Loopar supports the following database systems out of the box:

MySQL

Production-ready relational database

MariaDB

MySQL-compatible open source database

SQLite

Lightweight file-based database

Database Configuration

Database configuration is stored in db.config.json and managed through the loopar instance:
packages/loopar/core/loopar.js
const loopar = new Loopar();

// Get database configuration
const dbConfig = loopar.getDbConfig();

// Set database configuration
await loopar.setDbConfig({
  dialect: 'mysql',
  host: 'localhost',
  port: 3306,
  database: 'loopar_db',
  username: 'root',
  password: 'password'
});

Configuration Options

dialect
string
required
Database type: mysql, mariadb, or sqlite
host
string
Database host (not required for SQLite)
port
number
Database port (default: 3306 for MySQL/MariaDB)
database
string
required
Database name
username
string
Database username (not required for SQLite)
password
string
Database password (not required for SQLite)

Database Initialization

The database connection is initialized automatically when Loopar starts:
packages/loopar/core/loopar.js
export class Loopar extends Document {
  constructor() {
    super("Loopar");
    this.db = new SequelizeORM();
  }

  async initialize() {
    console.log(`......Initializing Loopar.......`);
    
    await this.buildGlobalEnvironment();
    await this.loadConfig();
   
    // Initialize database connection
    await this.db.initialize();
    
    await this.build();
    await this.buildIcons();
  }
}

Database Dependencies

Loopar uses the following packages for database connectivity:
packages/db-env/package.json
{
  "name": "db-env",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "@sequelize/core": "7.0.0-alpha.47",
    "@sequelize/mariadb": "7.0.0-alpha.47",
    "@sequelize/mysql": "7.0.0-alpha.47",
    "@sequelize/sqlite3": "7.0.0-alpha.47",
    "sequelize": "v7.0.0-next.1"
  }
}

Table Naming Convention

All database tables in Loopar are prefixed with tbl by default:
// Entity name: User
// Table name: tblUser

// Entity name: System Settings
// Table name: tblSystem Settings

Transactions

Loopar supports database transactions for atomic operations:
// Begin transaction
await loopar.db.beginTransaction();

try {
  // Perform database operations
  await loopar.db.insertRow('User', userData);
  await loopar.db.updateRow('Profile', profileData, profileName);
  
  // Commit transaction
  await loopar.db.endTransaction();
} catch (error) {
  // Rollback on error
  await loopar.db.rollbackTransaction();
  throw error;
}

Next Steps

Models

Learn how to define database models

Queries

Query data using the ORM

Migrations

Manage schema changes

Build docs developers (and LLMs) love