nexusorm
v0.1.7
Published
NexusORM - A type-safe SQL ORM for Postgres and MySQL.
Maintainers
Readme
NexusORM 🚀
A modern, type-safe SQL ORM for PostgreSQL and MySQL — fast to adopt, powerful to scale.
Built with ❤️ by flenco.in
✨ Features
🔌 Zero Configuration
- Just set
DATABASE_URLand you're ready - Auto-detects PostgreSQL and MySQL
- Automatic connection pooling
🛠️ Developer Experience
- Built-in CLI for code generation
- Complete TypeScript support
- Auto-generated type definitions
⚡ Production Ready
- Connection pooling & retries
- Transaction support with savepoints
- Comprehensive error handling
📊 Smart Features
- Schema introspection
- Relation mapping
- Date/time query helpers
🚀 Quick Start
Installation
npm install nexusormSetup
1. Configure Environment
# .env file in your project root
DATABASE_URL="postgres://user:pass@localhost:5432/mydb"
# or
DATABASE_URL="mysql://user:pass@localhost:3306/mydb"2. Generate Types & Models
npx nexusorm generate3. Start Coding
import { Users, Posts } from './nexusorm/models.js';
// Ready to use - no additional setup required
const users = await Users.findMany({ limit: 10 });
const user = await Users.create({
email: '[email protected]',
name: 'John Doe'
});💡 Usage Examples
CRUD Operations
import { Users } from './nexusorm/models.js';
// Create
const user = await Users.create({
email: '[email protected]',
name: 'John Doe',
active: true
});
// Read with conditions
const activeUsers = await Users.findMany({
where: { active: true },
order: 'created_at',
limit: 50
});
// Update
await Users.update(
{ id: user.id },
{ name: 'John Smith' }
);
// Delete
await Users.delete({ id: user.id });Advanced Queries
import { cond } from 'nexusorm';
// Complex conditions
const recentActiveUsers = await Users.findMany({
where: cond.and(
cond.gt('created_at', cond.daysAgo(30)),
cond.eq('active', true),
cond.contains('email', '@company.com')
),
order: 'created_at',
limit: 100
});
// Date/time queries
const thisWeekUsers = await Users.findMany({
where: cond.thisWeek('created_at')
});Relations & Includes
// Fetch user with related posts
const userWithPosts = await Users.findFirst({
where: { id: 1 },
include: {
posts: {
where: { published: true },
limit: 5,
order: 'created_at'
}
}
});Transactions
import { NexusORMClient } from 'nexusorm';
const db = await NexusORMClient.initFromEnv();
await db.$transaction(async (tx) => {
const user = await tx.model('users').create({
email: '[email protected]',
name: 'New User'
});
await tx.model('profiles').create({
userId: user.id,
bio: 'User profile'
});
});🛠️ CLI Commands
| Command | Description |
|---------|-------------|
| npx nexusorm generate | Generate types and models from database schema |
| npx nexusorm db:push | Push schema changes to database |
| npx nexusorm migrate:up | Run database migrations |
🔧 Configuration
Environment Variables
# Primary (required)
DATABASE_URL="postgres://user:pass@localhost:5432/db"
# Alternative formats
MYSQL_URL="mysql://user:pass@localhost:3306/db"
POSTGRES_URL="postgres://user:pass@localhost:5432/db"Supported Databases
| Database | URL Format | Default Port |
|----------|------------|--------------|
| PostgreSQL | postgres://user:pass@host:port/db | 5432 |
| MySQL | mysql://user:pass@host:port/db | 3306 |
📚 Documentation
📖 Local Documentation
Included with every installation
📋 Advanced Topics
📖 Complete Online Documentation
🤝 Community & Support
| 🐛 Issues | 💬 Discussions | ☕ Support | |:-------------:|:------------------:|:--------------:| | Report Bug | Join Discussion | Buy Me Coffee |
📄 License
Apache 2.0 - see LICENSE for details.
🚀 Ready to get started? Install NexusORM today!
npm install nexusormMade with ❤️ by flenco.in
