Skip to content
/ prisma Public

Native Perry implementation of Prisma ORM. Drop-in replacement for @prisma/client backed by sqlx + MySQL via Rust FFI.

Notifications You must be signed in to change notification settings

PerryTS/prisma

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

perry-prisma

Native Perry implementation of Prisma ORM. Drop-in replacement for @prisma/client backed by sqlx + MySQL via Rust FFI.

Compiles your Prisma schema and TypeScript into a single native binary -- no Node.js, no Prisma engine, no runtime dependencies.

Features

  • Full Prisma client API: findMany, findFirst, findUnique, create, createMany, update, updateMany, upsert, delete, deleteMany, count
  • WHERE filters: equals, not, gt, gte, lt, lte, in, notIn, contains, startsWith, endsWith, AND, OR, NOT
  • Pagination & ordering: take, skip, orderBy, select
  • Transactions: $transaction with commit/rollback
  • Raw SQL: $executeRaw, $queryRaw
  • Reads schema.prisma at build time -- zero runtime schema parsing

Usage

import { createPrismaClient } from "perry-prisma";

var prisma = createPrismaClient({
  datasourceUrl: "mysql://user:pass@localhost:3306/mydb"
});

prisma.$connect();

// CRUD
var user = prisma.user.create({
  data: { id: "1", email: "alice@example.com", ... }
});

var users = prisma.user.findMany({
  where: { email: { contains: "alice" } },
  orderBy: { createdAt: "desc" },
  take: 10
});

// Transactions
prisma.$transaction(function (tx) {
  prisma.user.create({ data: { ... } });
  prisma.post.create({ data: { ... } });
  // auto-commits on success, rolls back on throw
});

// Raw SQL
var rows = prisma.$queryRaw("SELECT * FROM User WHERE id = '1'");
prisma.$executeRaw("UPDATE User SET name = 'Bob' WHERE id = '1'");

prisma.$disconnect();

Setup

  1. Add your schema.prisma and set PRISMA_SCHEMA_PATH (or place it at the default path)
  2. Install as a Perry native package:
    npm install perry-prisma
    
  3. Compile with Perry:
    perry compile src/main.ts
    

Architecture

src/index.ts          TypeScript API (PrismaClient, ModelClient, types)
native/src/lib.rs     Rust FFI: SQL generation, query execution, transactions
native/build.rs       Schema parser: reads schema.prisma at compile time

All FFI calls are synchronous. The Rust layer uses sqlx with a MySQL connection pool, spawning threads with block_on to bridge sync FFI with async sqlx.

Testing

Run the full integration test suite against a MySQL database:

DATABASE_URL=mysql://user:pass@host:3306/db ./test/run_all.sh

7 test suites, 110 assertions covering CRUD, filters, bulk ops, pagination, transactions, raw SQL, and error handling.

License

MIT

About

Native Perry implementation of Prisma ORM. Drop-in replacement for @prisma/client backed by sqlx + MySQL via Rust FFI.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors