mevn-orm
Version:
simple ORM for express js
70 lines (49 loc) • 1.78 kB
Markdown

[](https://github.com/StanleyMasinde/mevn-orm/blob/master/LICENSE)

A small ActiveRecord-style ORM for Node.js, built on [Knex](https://knexjs.org/). Define models, query with a fluent API, and use MySQL, PostgreSQL, SQLite, and other Knex-supported databases.
**Documentation:** [https://stanleymasinde.github.io/mevn-orm/](https://stanleymasinde.github.io/mevn-orm/)
```bash
npm install mevn-orm knex
npm install better-sqlite3
```
```ts
import { configureDatabase, Model } from 'mevn-orm'
configureDatabase({
client: 'better-sqlite3',
connection: { filename: './dev.sqlite' }
})
class User extends Model {
override fillable = ['name', 'email', 'password']
override hidden = ['password']
}
const user = await User.create({
name: 'Jane Doe',
email: 'jane@example.com',
password: 'hash-me-first'
})
const found = await User.find(user.id as number)
const users = await User.where({ name: 'Jane Doe' }).all()
return users.toArray() // plain objects for API responses
```
```ts
class Farmer extends Model {
profile() {
return this.hasOne(Profile)
}
farms() {
return this.hasMany(Farm)
}
}
const farmer = await Farmer.find(1)
const profile = await farmer.profile()
const active = await farmer.farms().where({ active: true }).get()
```
This project is in maintenance mode. Core functionality is stable and actively maintained; large new features are limited.
[](./LICENSE)