@rattus-orm/core
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

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: 'test@test.com' }, { id: '2', email: 'test2@test.com' }])

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.

Package Sidebar

Install

npm i @rattus-orm/core

Weekly Downloads

2

Version

0.4.0

License

MIT

Unpacked Size

391 kB

Total Files

82

Last publish

Collaborators

  • lyohaplotinka