next-orm-eloquent
v0.1.0
Published
Eloquent-like ORM with auto-generated CRUD server actions for Next.js
Maintainers
Readme
next-orm-eloquent
Eloquent-like ORM with auto-generated CRUD server actions for Next.js.
Features
- 🚀 Eloquent-like query builder with chainable methods
- ⚡ Auto-generated CRUD server actions
- 🔄 Laravel-style seeder system with tracking
- 🎨 CMS admin panel for all models
- 🪝 Comprehensive hook system (validation, before/after, transform)
- 📦 Type-safe with full TypeScript support
- ✅ Comprehensive test suite
Installation
npm install next-orm-eloquent mongodbQuick Start
1. Initialize ORM
import { initializeORM } from 'next-orm-eloquent';
import { registerModels } from './models';
await initializeORM({
connection: {
uri: process.env.MONGODB_URI!,
database: process.env.MONGODB_DATABASE_NAME || 'myapp',
},
models: registerModels,
});2. Define a Model
import { Model, Field } from 'next-orm-eloquent';
export class User extends Model {
static collection = 'users';
static fields = {
email: Field.string().required().email(),
name: Field.string().required().min(2),
};
}3. Register Models
import { registerModel } from 'next-orm-eloquent';
import { User } from './user.model';
registerModel(User);4. Use in Server Actions
'use server';
import { getModelServerAction, postModelServerAction } from 'next-orm-eloquent/server-actions';
export async function listUsersAction(page: number, pageSize: number) {
return getModelServerAction('User', {
query: {
pagination: { page, pageSize },
},
});
}Testing
Run Tests
# Run all tests
npm test
# Run with UI
npm run test:ui
# Run with coverage
npm run test:coverage
# Run once (CI mode)
npm run test:runTest Models
The package includes test models (User, Magazine, Subscription) in tests/models/ for comprehensive testing.
Environment Variables
Set MONGODB_URI for tests:
export MONGODB_URI="mongodb://localhost:27017"Documentation
Development
Build
npm run buildType Check
npm run type-checkPublishing
Before publishing to npm:
- Update version:
npm version patch|minor|major - Build:
npm run build - Test:
npm run test:run - Publish:
npm publish
License
MIT
