pinia-orm
Welcome to pinia-orm
The intuitive, type safe and flexible ORM for Pinia — normalize relational data in your stores and query it like with an ORM.
Features
- Laravel-style query builder —
where,whereLike,whereHas,orderBy(incl.Intl.Collator),groupBy, aggregates,updateOrCreate/firstOrCreateand more - All the relations:
hasOne,hasMany,belongsTo,belongsToMany,hasManyThrough,morphOne,morphTo,morphMany,morphToMany,morphedByMany - Standard ECMAScript decorators for type safe model definitions
- Single Table Inheritance with nested discriminators, lifecycle hooks, mutators, casts, hidden fields and query caching
- First class Nuxt module (Nuxt 3 & 4) and an axios plugin
Quick start
npm install pinia pinia-orm
import { createPinia } from 'pinia'
import { createORM } from 'pinia-orm'
const pinia = createPinia().use(createORM())
import { Model, useRepo } from 'pinia-orm'
import { Attr, HasMany, Str, Uid } from 'pinia-orm/decorators'
class Todo extends Model {
static entity = 'todos'
@Uid() id!: string
@Str('') text!: string
@Attr(null) userId!: string | null
}
class User extends Model {
static entity = 'users'
@Uid() id!: string
@Str('') name!: string
@HasMany(() => Todo, 'userId') todos!: Todo[]
}
const userRepo = useRepo(User)
userRepo.save({ id: '1', name: 'John', todos: [{ text: 'Read the docs' }] })
const usersWithTodos = userRepo.with('todos').get()
Read the documentation for the full guide, or check the comparison with vuex-orm and the migration guide if you're upgrading.
Requirements
| pinia-orm | pinia | Node | TypeScript |
|---|---|---|---|
| 2.x | >= 3 | >= 22.12 | >= 5.2 |
| 1.x | 2.x | >= 14 | >= 4.x |
Help me keep working on this project 💚
💻 Development
- Clone this repository
- Enable Corepack using
corepack enable - Install dependencies using
pnpm install - Build the packages once with
pnpm build:stub && pnpm build:ci - Run tests using
pnpm test(orcd packages/pinia-orm && pnpm test:uifor the interactive UI)
Credits
Related projects
License
Made with ❤️
Published under MIT License.
Related Packages
pinia-orm-edge
The Pinia plugin to enable Object-Relational Mapping access to the Pinia Store.
12,854
528
pinia-cache
Cache dispatched actions in memory and prevent repeated requests and heavy actio...
1,372
2
Version History
| Version | Released | License |
|---|---|---|
| 2.0.0 | MIT | |
| 1.10.2 | MIT | |
| 1.10.1 | MIT | |
| 1.10.0 | MIT | |
| 1.9.2 | MIT | |
| 1.9.1 | MIT | |
| 1.9.0 | MIT | |
| 1.7.2 | MIT | |
| 1.7.1 | MIT | |
| 1.7.0 | MIT | |
| 1.6.7 | MIT | |
| 1.6.6 | MIT | |
| 1.6.5 | MIT | |
| 1.6.4 | MIT | |
| 1.6.3 | MIT | |
| 1.6.2 | MIT | |
| 1.6.1 | MIT | |
| 1.6.0 | MIT | |
| 1.5.1 | MIT | |
| 1.5.0 | MIT | |
| 1.4.0 | MIT | |
| 1.3.0 | MIT | |
| 1.2.2 | MIT | |
| 1.2.1 | MIT | |
| 1.2.0 | MIT | |
| 1.1.0 | MIT | |
| 1.0.4 | MIT | |
| 1.0.3 | MIT | |
| 1.0.2 | MIT | |
| 1.0.1 | MIT |
Showing the latest 30 of 42. See every release on npm
Pre-releases (10)
| Version | Released | License |
|---|---|---|
| 2.0.0-alpha.2 | MIT | |
| 2.0.0-alpha.1 | MIT | |
| 1.0.0-rc.6 | MIT | |
| 1.0.0-rc.5 | MIT | |
| 1.0.0-rc.4 | MIT | |
| 1.0.0-rc.3 | MIT | |
| 1.0.0-rc.2 | MIT | |
| 1.0.0-rc.1 | MIT | |
| 1.0.0-alpha.2 | MIT | |
| 1.0.0-alpha.1 | MIT |
