redi-orm

module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2025 License: MIT

README ΒΆ

RediORM

A modern, AI-native ORM for Go with Prisma-like JavaScript interface. RediORM bridges the gap between traditional database access and modern AI applications through sophisticated schema management and the Model Context Protocol (MCP).

✨ Key Features

  • πŸ€– AI-Native Design - First-class MCP support for seamless AI assistant integration
  • πŸ”„ Dual API - Type-safe Go API + Prisma-like JavaScript interface
  • πŸ—„οΈ Multi-Database - SQLite, MySQL, PostgreSQL, MongoDB with unified API
  • πŸ“Š Auto-Generated APIs - GraphQL and REST servers from your schema
  • πŸ”— Smart Relations - Eager loading, nested queries, relation management
  • πŸš€ Production Ready - Migrations, transactions, connection pooling, logging
  • πŸ“‹ Schema Management - Prisma-compatible schemas with auto-generation from databases
  • 🎨 Developer Experience - Color-coded logging, helpful error messages, consistent API

πŸš€ Quick Start

Installation
# Install CLI tool
go install github.com/rediwo/redi-orm/cmd/redi-orm@latest

# Or download pre-built binary
wget https://github.com/rediwo/redi-orm/releases/latest/download/redi-orm-linux-amd64.tar.gz
Define Your Schema
// schema.prisma
model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String
  posts Post[]
}

model Post {
  id      Int    @id @default(autoincrement())
  title   String
  content String?
  userId  Int
  user    User   @relation(fields: [userId], references: [id])
}
Go API
package main

import (
    "context"
    "github.com/rediwo/redi-orm/database"
    "github.com/rediwo/redi-orm/orm"
    _ "github.com/rediwo/redi-orm/drivers/sqlite"
)

func main() {
    ctx := context.Background()
    
    // Connect and load schema
    db, _ := database.NewFromURI("sqlite://./app.db")
    db.Connect(ctx)
    db.LoadSchemaFrom(ctx, "./schema.prisma")
    db.SyncSchemas(ctx)
    
    // Use ORM
    client := orm.NewClient(db)
    
    // Create user
    user, _ := client.Model("User").Create(`{
        "data": {
            "name": "Alice",
            "email": "alice@example.com"
        }
    }`)
    
    // Find many with complex queries
    users, _ := client.Model("User").FindMany(`{
        "where": {
            "email": { "contains": "@example.com" }
        },
        "include": { "posts": true },
        "orderBy": { "name": "asc" }
    }`)
    
    // Advanced query with OR conditions
    adminsOr25, _ := client.Model("User").FindMany(`{
        "where": {
            "OR": [
                {"age": 25},
                {"role": "admin"}
            ]
        }
    }`)
    
    // Query with operators
    products, _ := client.Model("Product").FindMany(`{
        "where": {
            "AND": [
                {"price": {"gte": 100, "lte": 500}},
                {"name": {"startsWith": "Pro"}}
            ]
        },
        "orderBy": {"price": "desc"},
        "take": 10
    }`)
}
JavaScript API
const { fromUri } = require('redi/orm');

async function main() {
    const db = fromUri('sqlite://./app.db');
    await db.connect();
    await db.loadSchemaFrom('./schema.prisma');
    await db.syncSchemas();
    
    // Create user with posts
    const user = await db.models.User.create({
        data: {
            name: "Alice",
            email: "alice@example.com",
            posts: {
                create: [
                    { title: "Hello World", content: "My first post!" }
                ]
            }
        }
    });
    
    // Query with relations
    const users = await db.models.User.findMany({
        where: { email: { contains: "@example.com" } },
        include: { posts: true },
        orderBy: { name: "asc" }
    });
    
    // Advanced query with OR conditions
    const adminsOr25 = await db.models.User.findMany({
        where: {
            OR: [
                { age: 25 },
                { role: "admin" }
            ]
        }
    });
    
    // Complex query with operators
    const products = await db.models.Product.findMany({
        where: {
            AND: [
                { price: { gte: 100, lte: 500 } },
                { name: { startsWith: "Pro" } }
            ]
        },
        orderBy: { price: "desc" },
        take: 10
    });
}
Query Operators

RediORM supports a rich set of query operators:

  • Comparison: equals, gt, gte, lt, lte
  • List: in, notIn
  • String: contains, startsWith, endsWith
  • Logical: AND, OR, NOT
  • Pagination: take, skip
  • Sorting: orderBy (with asc/desc)
  • Relations: include (with nested support)

πŸ€– AI Integration (MCP)

RediORM provides comprehensive Model Context Protocol support, enabling AI assistants to understand and manipulate your database through intelligent, schema-aware operations:

# Start MCP server for AI assistants
redi-orm mcp --db=sqlite://./app.db --schema=./schema.prisma

# With security for production
redi-orm mcp \
  --db=postgresql://readonly:pass@localhost/db \
  --enable-auth \
  --read-only \
  --allowed-tables=users,posts

AI Can Now:

  • πŸ” Discover Models - "What models do I have in my database?"
  • πŸ”¨ Create Models - "I need a model for tracking orders"
  • πŸ”Ž Smart Queries - "Find all users who have published posts"
  • ⚑ Optimize Performance - "This query is slow, how can I improve it?"

🌐 Auto-Generated APIs

GraphQL Server
# Start GraphQL + REST API server
redi-orm server --db=sqlite://./app.db --schema=./schema.prisma
# GraphQL: http://localhost:4000/graphql
# REST API: http://localhost:4000/api
Example GraphQL Query
query {
  findManyUser(
    where: { email: { contains: "@example.com" } }
    include: { posts: true }
  ) {
    id
    name
    email
    posts {
      title
      content
    }
  }
}

πŸ—„οΈ Multi-Database Support

Feature SQLite MySQL PostgreSQL MongoDB
CRUD Operations βœ… βœ… βœ… βœ…
Relations βœ… βœ… βœ… βœ…
Transactions βœ… βœ… βœ… βœ…
Migrations βœ… βœ… βœ… ❌
Aggregations βœ… βœ… βœ… βœ…
Raw Queries βœ… βœ… βœ… βœ… + MongoDB commands

πŸ”§ CLI Commands

# Run JavaScript with ORM
redi-orm run script.js

# Database migrations
redi-orm migrate --db=sqlite://./app.db --schema=./schema.prisma

# Start servers
redi-orm server --db=sqlite://./app.db --schema=./schema.prisma    # GraphQL + REST
redi-mcp --db=sqlite://./app.db --schema=./schema.prisma           # MCP for AI

πŸ€– AI Integration with MCP

Model Context Protocol (MCP) Server

RediORM includes a built-in MCP server that enables AI assistants to understand and interact with your database through natural language.

# Install and run MCP server
go install github.com/rediwo/redi-orm/cmd/redi-mcp@latest

# Stdio mode (for Claude Desktop)
redi-mcp --db=sqlite://./app.db --schema=./schema.prisma

# HTTP streaming mode (for Cursor, Windsurf, web apps)
redi-mcp --db=sqlite://./app.db --schema=./schema.prisma --port=8080

# Production configuration with security
redi-mcp --db=postgresql://readonly:pass@localhost/myapp --schema=./prisma \
  --port=8080 \
  --log-level=info \
  --read-only=true \
  --rate-limit=100
MCP Features
  • Natural Language Queries - AI can understand requests like "find all users who posted this week"
  • Schema Understanding - AI comprehends your data model relationships and constraints
  • Safe Operations - Read-only mode by default, with granular permission control
  • Tool Integration - Works with Claude, GitHub Copilot, and other MCP-compatible AI assistants
MCP Server Modes
1. Stdio Mode (Default)

Best for desktop AI applications like Claude Desktop:

// Claude Desktop config (~/.claude/claude_desktop_config.json)
{
  "mcpServers": {
    "database": {
      "command": "redi-mcp",
      "args": ["--db=postgresql://localhost/myapp", "--schema=./prisma"]
    }
  }
}
2. HTTP Streaming Mode

For web-based AI tools like Cursor, Windsurf, and remote access. HTTP mode uses streaming by default:

# Start HTTP server (streaming mode by default)
redi-mcp --db=postgresql://localhost/myapp --schema=./prisma --port=8080

Configure in Cursor/Windsurf:

// .cursor/config.json or .windsurf/config.json
{
  "mcpServers": {
    "orm-mcp": {
      "url": "http://localhost:8080"
    }
  }
}

HTTP endpoints:

  • / - Streaming MCP protocol endpoint
  • /sse - Server-Sent Events endpoint
What AI Assistants Can Do

Now your AI assistant can:

  • Query data using natural language - "Show me users who signed up this month"
  • Generate reports and analytics - "Create a weekly sales summary"
  • Suggest schema improvements - "What indexes would improve performance?"
  • Help debug data issues - "Why are some orders missing user references?"

πŸ“š Documentation

Getting Started
Advanced Usage

🎯 Why RediORM?

Traditional ORMs focus on mapping objects to database tables.

RediORM is designed for the AI era - where databases need to be understandable and manipulable by AI systems, while maintaining full type safety and performance for human developers.

  • Schema-Aware AI - AI understands your data models, not just SQL tables
  • Unified Interface - Same API across all databases (SQL + NoSQL)
  • Production Ready - Built-in servers, security, monitoring
  • Developer Friendly - Prisma-like syntax developers already know

πŸ“„ License

MIT License - see LICENSE file for details.


Ready to build AI-native applications? Start with our Getting Started Guide or explore the MCP Guide for AI integration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL