comon_orm 0.0.1-alpha.1
comon_orm: ^0.0.1-alpha.1 copied to clipboard
Prisma-inspired schema-first ORM core for Dart with schema parsing, code generation, and an in-memory runtime.
English | Русский
comon_orm #
comon_orm is the provider-agnostic core of the package family: schema parsing, validation, formatting, code generation, query models, and the in-memory runtime.
Use this package when you want to work with schema.prisma, generate a typed Dart client, or run fast schema-driven tests without starting a real database.
✨ What This Package Gives You #
- schema AST, parser, validator, and workflow helpers
- schema formatting and generator output resolution
- generated client code emission
- provider-agnostic query models and
DatabaseAdaptercontracts InMemoryDatabaseAdapterfor tests and local workflows- migration artifacts and risk-analysis helpers that are not tied to a SQL dialect
Use comon_orm_postgresql or comon_orm_sqlite when you need a real database adapter, introspection, or migration execution.
🚀 Quick Start #
Add the dependency:
dependencies:
comon_orm: ^0.0.1-alpha.1
Validate, format, and generate from a schema:
dart run comon_orm check schema.prisma
dart run comon_orm format schema.prisma
dart run comon_orm generate schema.prisma
validate is still available as an alias for check.
Minimal generated-client-first example:
import 'package:comon_orm/comon_orm.dart';
import 'generated/comon_orm_client.dart';
Future<void> main() async {
final db = GeneratedComonOrmClient.openInMemory();
final user = await db.user.create(
data: const UserCreateInput(
email: 'alice@example.com',
name: 'Alice',
),
);
final users = await db.user.findMany();
print(user.email);
print(users.length);
}
If the example schema changes, regenerate the client with:
dart run comon_orm generate example/schema.prisma
🎯 Key Features #
🧬 Schema Workflow #
schema.prismaparsing, validation, and canonical formatting- generator output resolution from
generator client { output = ... } - explicit SQLite helper target selection from
generator client { sqliteHelper = "vm" | "flutter" } - file-aware validation diagnostics through
SchemaWorkflow - unified CLI for
check,format, andgenerate
🤖 Generated Client Surface #
- typed models, inputs, and delegates
findUnique,findFirst,findMany,countcreate,update,updateMany,delete,deleteManyupsert,createMany, andcreateMany(skipDuplicates: true)transactionselect,include, nested relation create inputs, and generated nestedconnect,disconnect,set, andconnectOrCreatewhere relation semantics allow themdistinct,orderBy,skip, andtakeaggregateandgroupBy- scalar and compound
WhereUniqueInput
The advanced generated surface remains intentionally generated-layer first today:
createMany(...)andupdateMany(...)are transactional delegate conveniences over the existing runtime primitives, which keeps behavior aligned across in-memory and SQL providers instead of splitting semantics by backend.findMany(cursor: ...)andfindFirst(cursor: ...)currently implement cursor slicing in the generated delegate layer rather than claiming adapter-native cursor pushdown.
Short advanced example using the package example schema:
await db.user.createMany(
data: const [
UserCreateInput(email: 'alice@example.com', name: 'Alice'),
UserCreateInput(email: 'alice@example.com', name: 'Alice duplicate'),
UserCreateInput(email: 'bob@example.com', name: 'Bob'),
],
skipDuplicates: true,
);
final firstPage = await db.user.findMany(
orderBy: const [UserOrderByInput(id: SortOrder.asc)],
take: 2,
);
final nextUser = await db.user.findFirst(
cursor: UserWhereUniqueInput(id: firstPage.last.id!),
orderBy: const [UserOrderByInput(id: SortOrder.asc)],
);
🧪 In-Memory Runtime #
- fast tests without a real database
- schema-driven runtime semantics when created from generated metadata or
schema: - useful for validating generated client behavior and query workflows
🧱 Shared Building Blocks #
- provider-agnostic query models
DatabaseAdaptercontracts for custom backends- migration artifact and risk-analysis helpers shared by provider packages
- web-safe schema parsing, validation, and formatting from in-memory source text
📚 Typical Workflows #
- validate and format
schema.prismabefore committing generator or migration changes - generate a typed client file from your schema
- run tests against
InMemoryDatabaseAdapter - implement a custom adapter against
DatabaseAdapterif your backend is not covered by the provider packages
📱 Platform Notes #
| Platform / scenario | Status | Notes |
|---|---|---|
| Dart CLI / server / backend | ✅ Primary target | Main supported use case |
| Flutter mobile / desktop | ✅ Core package works | Query models, parser, validator, codegen types, and in-memory runtime are usable; file-based tooling still assumes VM filesystem access |
| Dart Web / Flutter Web | ✅ Core package import is supported | Use source-based workflow APIs such as loadValidatedSchemaSource(...); file-backed workflow and migration artifact loading remain unavailable on web |
🧱 Scope #
- This package does not ship a production SQL adapter by itself.
- Real database migrations and schema introspection live in the provider packages.
comon_orm_postgresqland the currentcomon_orm_sqlitepackage remain VM-oriented runtime adapters; browser runtimes need separate adapter packages.- The project is Prisma-inspired and does not claim full Prisma parity.