The intuitive, type safe and flexible ORM for Pinia — normalize relational data in your stores and query it like with an ORM.
- 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
npm install pinia pinia-ormimport{createPinia}from'pinia'import{createORM}from'pinia-orm'constpinia=createPinia().use(createORM())import{Model,useRepo}from'pinia-orm'import{Attr,HasMany,Str,Uid}from'pinia-orm/decorators'classTodoextendsModel{staticentity='todos'
@Uid()id!: string
@Str('')text!: string
@Attr(null)userId!: string|null}classUserextendsModel{staticentity='users'
@Uid()id!: string
@Str('')name!: string
@HasMany(()=>Todo,'userId')todos!: Todo[]}constuserRepo=useRepo(User)userRepo.save({id: '1',name: 'John',todos: [{text: 'Read the docs'}]})constusersWithTodos=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.
| pinia-orm | pinia | Node | TypeScript |
|---|---|---|---|
| 2.x | >= 3 | >= 22.12 | >= 5.2 |
| 1.x | 2.x | >= 14 | >= 4.x |
- 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)
Made with ❤️
Published under MIT License.
