@rattus-orm/core
v0.4.2
Published
ORM for your JS/TS apps: core package
Downloads
87
Maintainers
Readme
Contents
- Base of Rattus ORM: Database, Repositories, Model, Query, all typings;
- ObjectDataProvider – data provider for simple in-memory storage (JS Object).
Installation
Use your favorite package manager. For example, yarn:
yarn add @rattus-orm/coreImportant 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: stringBasic 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.
