Skip to content

PHORM

PHORM

PHORM (Predictable Harmonious ORM) is a lightweight, type-safe, driver-agnostic ORM for Dart and Flutter.

It separates query building and relationship mapping from database-specific SQL grammar using a pluggable Dialect system — the same declarative models and generated service APIs work across SQL backends, starting with SQLite (via phorm_sqlite).

Highlights

  • 🚀 Performance — relationship trees load in exactly one SQL query via native JSON aggregation; all SQLite work runs off the UI thread in a background isolate
  • 🛡️ Type safety — generated typed columns and conditions: Users.age.gt(18) & (Users.city.eq('Sofia') | Users.city.eq('Plovdiv'))
  • 🔄 Automatic migrationsDB(autoMigrate: true) applies safe additive schema changes on open, no version bumps needed
  • 🗑️ Soft deletes, 📦 batches & nested transactions (savepoints), 👁️ reactive watchers, 🌐 Flutter Web (WASM + IndexedDB)

Installation

dependencies:
  phorm_sqlite: ^1.10.0 # SQLite driver — includes the phorm core

dev_dependencies:
  phorm_generator: ^1.5.0 # code generation
  build_runner: ^2.4.0

Quick start

import 'package:phorm_sqlite/phorm_sqlite.dart';

final appDb = DB.autoVersion(
  databaseName: 'app.db',
  tables: [usersTable], // generated by phorm_generator
  autoMigrate: true,
);

await Users.insert(user);

final adults = await Users
    .where(Users.age.gt(18))
    .orderBy(Users.name)
    .get();

Where to go next

Section What's inside
Overview Architecture, packages, core concepts
Schema Definition @Schema, @Column, @ID, validators
CRUD Operations Insert/read/update/delete, transactions, observability
Relationships HasOne/HasMany/BelongsTo/ManyToMany, eager loading
DB & Migrations Versioning, explicit and automatic migrations
Query Builder Fluent API: filtering, sorting, pagination
Reactivity watchOne / watchAll streams
Flutter Web WASM backend, IndexedDB persistence