Skip to content

Latest commit

 

History

History

core

Rattus ORM

bundle size npm version (core)

Rattus ORM – Core

Contents

  1. Base of Rattus ORM: Database, Repositories, Model, Query, all typings;
  2. ObjectDataProvider – data provider for simple in-memory storage (JS Object).

Installation

Use your favorite package manager. For example, yarn:

yarn add @rattus-orm/core

Important notes

If you are using Vite with TypeScript, make sure you have these settings in tsconfig.json:

{
  "compilerOptions": {
    // ...
    "useDefineForClassFields": true,
    "experimentalDecorators": true
  }
}

Also you should use this syntax for defining models:

class User extends Model {
  public static entity = 'users'

  @Str('')
  // public id: string - will not work, 
  // all fields of your models will be "null"
  declare id: string

Basic usage

import { Model, Uid, Str } from '@rattus-orm/core'
import { ObjectDataProvider } from '@rattus-orm/core/object-data-provider'
import { createDatabase } from '@rattus-orm/core/src'

class User extends Model {
  public static entity = 'user'

  @Uid()
  public id: string

  @Str()
  public email: string
}

const database = createDatabase({
  dataProvider: new ObjectDataProvider(),
  connection: 'entities'
}).start()

const userRepo = database.getRepository(User)
userRepo.save([{ id: '1', email: '[email protected]' }, { id: '2', email: '[email protected]' }])

const found = userRepo.find('2')

Documentation

For detailed docs please read documentation website.

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct, and the process for submitting pull requests.