Socket
Book a DemoInstallSign in
Socket

modular-orm

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

modular-orm

A simple ORM library for TypeScript that allows you to work with the database using classes

0.3.51
latest
Source
npmnpm
Version published
Weekly downloads
13
333.33%
Maintainers
1
Weekly downloads
 
Created
Source

ModularORM Logo

Lightweight, fully object-oriented ORM library for TypeScript and MySQL. It is designed for simplicity and strong type safety, with a class-based API built around decorators.

Test Badge npm version

DescriptionResult
Sending 100.000 INSERT queries13s
Selecting 100.000 objects with DTO79ms
Lines of code needed to connect7
Test coverage66.82%
Dist size340kb

Features

  • Fully OOP Structure: Define tables, columns, and relationships using TypeScript classes.

  • Minimal Setup: Simple to configure and get started with-just a few lines of code.

  • Up and down migrations with files (or auto)

  • Class-Based DTO Mapping: Map query results to custom classes using @Result() decorators.

  • Repository Pattern Out of the Box: Create repositories with new Repository(Class) - no boilerplate or registration needed.

  • Validation and Transforms: Add validation and data transformation logic directly to your models with built-in or custom tools.

  • Logger: you can add logger method in your module and handle all queries

  • Intuitive architecture: repository.find({ userId: [1, 2] }) - select all from ur table where userId is 1 or 2

  • Caching: build-in in-memory cache system without Redis and flexible settings

  • Typed Information Schema Access: Query database metadata through typed APIs.

And more. You can see examples in GitHub repository

ModularORM is ideal for developers who want a clean, type-safe ORM experience with full control and minimal overhead.

Examples

Full documentation text

Connecting to the database

const main : ModularORM = ModularORM.getInstance()
await main.start({
    host: 'localhost',
    user: 'root',
    password: '1',
    database: 'orm',
    port: 3306,
    connectionType: 'pool',
    checkTablesExists: false, // If you want to check if tables are created. If not, it will be IF NOT EXISTS
    validationErrors: false // You can enable this to make validation errors throw real exceptions.
    // And maaany more parameters
})

Creating tables

@Table({ comment: 'Users table' })
@NamedTable('users')
class Users extends Module {

    @AutoIncrementId()
    public id!: number;

    @Column({ type: ColumnType.VARCHAR(64), notNull: true, comment: 'Users first name', index: true })
    public first_name!: string;

    @Column({ type: ColumnType.VARCHAR(64), notNull: true, comment: 'Users last name', index: true })
    public last_name!: string;

    @Column({ type: ColumnType.FLOAT, notNull: true, comment: 'Users balance', defaultValue: 0 })
    public money!: number;

}

Creating DTOs with validation and transforms

class UserDTO implements Validate {

    @Result() // Can be empty
    public id!: number;

    @Result('first_name')
    @IsSafeString() // Validator
    public firstName!: string;

    @Result('last_name')
    @IsSafeString() // Validator
    public lastName!: string;

    @Result()
    @ToNumber() // Transform
    public money!: number;

    public validateErrors: Set<string> = new Set(); // Validation errors

}

Creating repository

const repo = new Repository(Users, UserDTO); // With DTO
const repotwo = new Repository(Users); // Without DTO

Queries

// SELECT * FROM users WHERE first_name = "Alex" OR last_name = "Smith"
const res : Users[] = await repotwo.find({ first_name: ["Alex"], last_name: "Smith" })
// SELECT * FROM users WHERE (id = 1 OR id = 2) ORDER BY id DESC LIMIT 1
const restwo : UserDTO[] = await repo.find({ id: [1, 2] }, { limit: 1, order: { id: "DESC" } })

Keywords

orm

FAQs

Package last updated on 02 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.