Registry / database / pinia-orm

pinia-orm

JSON →
library1.10.2jsnpmunverified

Pinia ORM is a plugin for Pinia that provides Object-Relational Mapping (ORM) capabilities for Vue 3 applications. Version 1.10.2 is the latest stable release with active development. It allows defining models with relationships (hasOne, hasMany, belongsTo, etc.) and provides a query builder for fluent data access. Key differentiators: seamless integration with Pinia's state management, support for reactive data, and TypeScript-first design. Released with a cadence of minor updates roughly every 2-3 months.

npm install pinia-orm
INSTALL
IMPORT
SIG · PINIA-ORM
P
pinia-orm
databasejavascriptv1.10.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useRepo
import { useRepo } from 'pinia-orm'
const { useRepo } = require('pinia-orm')
ESM-only package; useRepo is the main hook to interact with the repository.
Model
import { Model } from 'pinia-orm'
import Model from 'pinia-orm'
Model is a named export, not default. Extend it to define your data models.
PiniaOrmPlugin
import { PiniaOrmPlugin } from 'pinia-orm'
Plugin to install into Pinia. Use with pinia.use(PiniaOrmPlugin).

Shows setup of Pinia ORM with model definitions, relationships, and basic CRUD using useRepo.

import { createPinia } from 'pinia'; import { PiniaOrmPlugin, Model, useRepo, HasMany, BelongsTo } from 'pinia-orm'; import { createApp } from 'vue'; import App from './App.vue'; // Define models class User extends Model { static entity = 'users'; static fields() { return { id: this.attr(null), name: this.string(''), posts: this.hasMany(Post, 'user_id'), }; } } class Post extends Model { static entity = 'posts'; static fields() { return { id: this.attr(null), title: this.string(''), user_id: this.attr(null), user: this.belongsTo(User, 'user_id'), }; } } // Setup Vue app const pinia = createPinia(); pinia.use(PiniaOrmPlugin); const app = createApp(App); app.use(pinia); // Use repository const repo = useRepo(User); repo.save({ id: 1, name: 'Alice' }); const user = repo.find(1); console.log(user.name); // 'Alice'
Debug
Known issues
breakingVersion 1.0.0 removed the 'orm' property from Pinia stores; useRepo is now required.
fix
Migrate from store.$orm() to useRepo() hook.
affects: <1.0.0
deprecatedThe 'HasOne', 'HasMany', 'BelongsTo' decorators are deprecated in favor of static fields() method.
fix
Define relations inside static fields() using 'this.hasMany()', etc.
affects: >=0.9.0
gotchaModel fields must return plain objects, not arrays; otherwise reactivity may break.
fix
Ensure fields() returns an object literal with key-value pairs.
affects: *
breakingUpgrading from Pinia ORM v0.x to v1.x requires replacing '@pinia-orm/...' imports with 'pinia-orm'.
fix
Change all imports to 'pinia-orm'.
affects: <1.0.0
Errors
Common errors & fixes
Cannot find module 'pinia-orm' or its corresponding type declarations.
Missing package installation or incorrect import path.
fix
Run npm install pinia-orm pinia and ensure import is from 'pinia-orm'.
Must use import to load ES Module: require() of ES modules is not supported.
Using CommonJS require() with an ESM-only package.
fix
Change require to import or use dynamic import().
TypeError: Cannot read properties of undefined (reading 'state')
Using useRepo or repository methods before Pinia ORM plugin is installed.
fix
Ensure you call pinia.use(PiniaOrmPlugin) before any store or repo usage.
The target entity [entity] has not been registered.
Model class not imported or not registered into Pinia ORM.
fix
Import the model file at least once before using it (e.g., import './models/User').
Upgrade
Version history
1.10.2latest on npm
Audit
Dependencies
piniarequiredpeer dependency required for Pinia store integration
Agent activity
2 hits · last 30 days
node
2
Resources
pinia-orm — npm install pinia-orm · libregistry