fasty-orm
v0.0.6
Published
A blazing fast, type-safe ORM for Node.js and TypeScript, powered by a native Rust engine. Inspired by Drizzle ORM, with a focus on performance, safety, a fluent query builder API, and a powerful native query cache.
Readme
fasty-orm
A blazing fast, type-safe ORM for Node.js and TypeScript, powered by a native Rust engine. Inspired by Drizzle ORM, with a focus on performance, safety, a fluent query builder API, and a powerful native query cache.
Features
- ⚡️ Native Rust backend for maximum performance (via N-API)
- 🛡️ Type-safe schema and query builder (TypeScript-first)
- 🧩 Drizzle-like fluent API for building SQL queries
- 🔒 Prevents SQL injection with parameterized queries
- 🗄️ Built-in native query caching (configurable TTL and capacity)
- 🔁 Advanced join and transformation utilities
- 🐬 MySQL support (other databases planned)
- 🧪 Easy to test and extend
Architecture
TypeScript (Query Builder)
↓
Generates SQL string + params
↓
Native Rust addon (N-API)
↓
MySQL databaseInstallation
npm install fasty-orm
# or, if using your local build:
npm install ./fasty-orm-0.0.1.tgzNote: Requires Node.js and a Rust toolchain for native builds.
Quick Start
import { FastyORM, table, eq } from 'fasty-orm';
// Define your schema
const users = table('users', {
id: integer('id').primaryKey().autoIncrement(),
name: text('name').notNull(),
age: integer('age'),
});
// Connect to the database
const db = await FastyORM.connect('mysql://user:pass@localhost:3306/mydb');
// Enable and configure the native cache (optional but recommended)
FastyORM.initCache(1000, 5000); // 1000 entries, 5s default TTL
// Query data with cache
const result = await db.select().from(users).where(eq(users.id, 1)).cache({ ttl: 10000 });
// The above query will be cached natively for 10 seconds
// Insert data
await db.insert(users).values({ name: 'Alice', age: 30 });
// Update data
await db.update(users).set({ age: 31 }).where(eq(users.name, 'Alice'));
// Delete data
await db.delete(users).where(eq(users.id, 1));Native Query Cache
- Native cache is implemented in Rust for maximum speed.
- You can globally initialize the cache:
FastyORM.initCache(1000, 5000); // 1000 entries, 5s default TTL - Per-query cache TTL is supported:
db.select().from(users).where(...).cache({ ttl: 10000 }) - All cache logic is handled natively, so cache hits are extremely fast and do not hit the database.
Schema Definition
Define tables and columns in a type-safe way:
const users = table('users', {
id: integer('id').primaryKey().autoIncrement(),
name: text('name').notNull(),
email: text('email').notNull(),
created_at: datetime('created_at').default('CURRENT_TIMESTAMP'),
});primaryKey(),notNull(),default(value),autoIncrement(), andforeignKey()are supported.- TypeScript infers types for selects and inserts.
Query Builder
Fluent, composable API for building SQL:
select().from(table).where(...)insert(table).values({...})update(table).set({...}).where(...)delete(table).where(...)
All queries are parameterized to prevent SQL injection.
SQL Operators
Type-safe SQL operators for WHERE clauses:
eq(column, value)— equalsne(column, value)— not equalsgt,lt,gte,lte— comparisonsand(...),or(...)— logical composition
Example:
where(and(eq(users.name, 'Alice'), gt(users.age, 18)))Advanced Features
- Join and Relationship Utilities: Built-in helpers for key mapping, relationship parsing, and result transformation, with internal caching for performance.
- Raw Queries:
Execute raw SQL with
db.raw<T>(sql, params)and get typed results. - Type Inference: All builders and schema definitions are fully type-safe, with TypeScript inferring result and insert types.
- Extensible: Utilities and types are exported for advanced usage and extension.
Native Engine
- The Rust backend is loaded via N-API as a
.nodeor.dylibfile. - If the native module is missing, run:
cargo build --release cp target/release/libfasty_orm.dylib fasty_orm.node - The engine exposes connection, query, cache, and version APIs.
Scripts
npm run build-native— Builds the Rust engine and copies the binary.npm run build— Compiles TypeScript todist/.npm run prepublishOnly— Runs both before publishing.
Project Structure
src/— TypeScript source (query builder, schema, operators, etc.)fasty_orm.node— Native Rust engine (built artifact)dist/— Compiled JS output
Requirements
- Node.js 16+
- Rust toolchain (for native builds)
- MySQL database
License
MIT
Contributing
PRs and issues are welcome! See the roadmap and docs for future plans.
