Skip to content

Kalama-Tech/torm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TORM - ToonStore Object-Relational Mapper

License: MIT

Mongoose-style ORM for ToonStore - Type-safe, schemaless models with validation, queries, and relationships across Rust, Node.js, Python, Go, and PHP.


🎯 What is TORM?

TORM is an Object-Relational Mapper (ORM) for ToonStore, inspired by Mongoose (MongoDB's ORM). Just as MongoDB is schemaless but Mongoose provides application-level schemas, ToonStore is schemaless but TORM provides type-safe models.

Key Features

  • βœ… Schemaless Storage - ToonStore stores data in efficient TOON format without rigid schemas
  • βœ… Application-Level Schemas - Type-safe models with validation in your code
  • βœ… Type Safety - Rust derive macros & type checking across all languages
  • βœ… Validation - Built-in validators (email, URL, length, range, pattern)
  • βœ… Query Builder - Fluent API for filtering, sorting, and pagination
  • βœ… Relationships - Reference other models like traditional ORMs
  • βœ… Migrations - Track and manage schema changes over time
  • βœ… TORM Studio - Visual database management (like Drizzle Studio)
  • βœ… Multi-Language - Rust, Node.js, Python, Go, PHP support via REST API

πŸ“¦ What is the TOON Format?

TOON (Token-Oriented Object Notation) is a compact, human-readable data format designed for the age of AI and LLMs. ToonStore uses TOON format for efficient data storage.

Why TOON in the AI Era?

  • πŸ€– LLM-Optimized: 74% accuracy vs JSON's 70% in LLM comprehension benchmarks
  • πŸ’° Cost-Efficient: ~40-60% fewer tokens = lower API costs for AI applications
  • πŸ“Š Schema-Aware: Explicit [N] lengths and {fields} help LLMs parse reliably
  • πŸ”„ JSON-Compatible: Lossless round-trips with same objects/arrays/primitives
  • πŸ‘οΈ Human-Readable: YAML-like readability with CSV-style compactness

TOON vs JSON Example

JSON (22,250 tokens):

{
  "users": [
    {"id": "1", "name": "Alice", "email": "alice@example.com", "age": 30},
    {"id": "2", "name": "Bob", "email": "bob@example.com", "age": 25}
  ]
}

TOON (9,120 tokens - 59% reduction):

users[2]{id,name,email,age}:
  1,Alice,alice@example.com,30
  2,Bob,bob@example.com,25

Learn More: TOON Format Repository


πŸ€” Why TORM?

The Problem: Schemaless Needs Structure

While schemaless databases offer flexibility, applications need:

  • Type safety to prevent bugs
  • Validation to ensure data quality
  • Relationships to model real-world data
  • Consistent APIs across languages

The Solution: Application-Level Schemas

Like MongoDB + Mongoose, TORM combines the best of both:

Layer Technology Purpose
Storage ToonStore (schemaless TOON format) Fast, flexible, token-efficient storage
Application TORM (schemas) Type safety, validation, relationships

Benefits:

  • πŸš€ Performance - ToonStore's speed (5.28M ops/sec)
  • πŸ›‘οΈ Safety - Type checking and validation at application level
  • πŸ”„ Flexibility - Add fields without database migrations
  • πŸ’° Efficiency - TOON format saves ~40% tokens (perfect for AI/LLM apps)
  • πŸ’ͺ Power - Rich query APIs and relationship support

πŸ“¦ Components

1. TORM Library (crates/torm)

Rust library for defining models and interacting with ToonStore

2. TORM Server (crates/torm-server)

REST API server for multi-language support (Node.js, Python, Go, PHP)

3. TORM Derive (crates/torm-derive)

Proc macros for deriving Model trait


πŸš€ Quick Start (Rust)

use torm::{Model, TormDb};
use serde::{Deserialize, Serialize};

#[derive(Model, Serialize, Deserialize, Debug)]
struct User {
    #[id]
    id: String,
    name: String,
    email: String,
    age: Option<u32>,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Connect to ToonStore
    let db = TormDb::connect("redis://localhost:6379").await?;
    
    // Create user
    let user = User {
        id: "user:1".into(),
        name: "John Doe".into(),
        email: "john@example.com".into(),
        age: Some(30),
    };
    
    user.save(&db).await?;
    
    // Find user
    let found = User::find_by_id(&db, "user:1").await?;
    println!("Found: {:?}", found);
    
    Ok(())
}

🌍 Multi-Language Support

TORM Server provides REST API for any language:

Node.js

const { TormClient, Model } = require('@toonstore/torm');
const torm = new TormClient('http://localhost:3001');

const User = Model.define('User', { /* schema */ });
await user.save();

Python

from toonstore import TormClient, Model
torm = TormClient('http://localhost:3001')

class User(Model):
    name: str
    email: str

await user.save()

Go

import "github.com/toonstore/torm-go"

type User struct { /* fields */ }
client.Model("users").Create(&user)

πŸ“š Documentation

πŸš€ Quick Start

πŸ“– Core Guides

🎨 Tools

🌍 Multi-Language

πŸ“¦ Publishing & Development


πŸ› οΈ Development

# Build all crates
cargo build

# Run tests
cargo test

# Start TORM server
cargo run --bin torm-server

# Build release
cargo build --release

πŸ“‚ Project Structure

torm/
β”œβ”€β”€ Cargo.toml              # Workspace config
β”œβ”€β”€ crates/
β”‚   β”œβ”€β”€ torm/               # Core ORM library
β”‚   β”œβ”€β”€ torm-server/        # REST API server
β”‚   └── torm-derive/        # Proc macros
β”œβ”€β”€ sdks/                   # Language SDKs
β”‚   β”œβ”€β”€ nodejs/
β”‚   β”œβ”€β”€ python/
β”‚   β”œβ”€β”€ go/
β”‚   └── php/
└── examples/               # Example projects
    β”œβ”€β”€ basic-crud/
    β”œβ”€β”€ relationships/
    └── validation/

πŸ“„ License

MIT License - see LICENSE for details


Built with ❀️ for ToonStore

Releases

No releases published

Packages

 
 
 

Contributors