Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ jobs:
persist-credentials: false
- uses: dart-lang/setup-dart@v1
with:
sdk: 3.13.3
sdk: 3.13.4
- name: Install dependencies
run: dart pub get --enforce-lockfile
- name: Check formatting
run: dart format --output=none --set-exit-if-changed bin lib test tool example
- name: Analyze Dart package and examples
# The Flutter example is a separate package with its own SDK dependency.
run: |
for target in bin lib test tool example/*.dart example/migrations example/teams; do
for target in bin lib test tool example/*.dart example/migrations example/teams example/company; do
dart analyze "$target"
done
- name: Check committed SQLite web assets
Expand All @@ -102,7 +102,7 @@ jobs:
persist-credentials: false
- uses: dart-lang/setup-dart@v1
with:
sdk: 3.13.3
sdk: 3.13.4
- name: Install dependencies
run: dart pub get --enforce-lockfile
- name: Locate Chrome
Expand Down
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Old code and upstream architecture are retired.
- Each migration history fixes one database engine. Save only that engine's SQL,
steps and frozen schema; reject mixed histories and mismatched connections.
- Prefer small Conventional Commits. Do not push without explicit authorization.
- Keep `doc/progress.md` accurate, including unfinished work and validation limits.
- Keep `doc/` focused on public usage, examples and compatibility limits.
Keep research notes and development/test-run records out of public documentation;
put reusable contributor workflows in `CONTRIBUTING.md`.
- Schema snapshots and saved migrations are Dart source. Retire the old JSON file
workflow directly; do not add compatibility readers or parallel output modes.
- Keep historical migration definitions independent of current application models.
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## 6.0.0-beta.3

Breaking schema authoring change: replace annotated entities and hand-written row
types with `model(...)`, then regenerate clients. Table and column names still
identify the physical schema; keep existing migration history unchanged.

- Add `model(...)` with named Record column declarations, generating nominal
rows and typed queries from one definition without annotations.
- Support model-local keys, indexes, checks and relationships, including self,
composite and alternate-key references; follow exported/cross-file models.
- Name relations with Record fields. Declare reverse navigation on its own model,
reject ambiguous references, and select target keys with named column mappings.
- Report Record schema errors with source locations and diagnostic codes. Keep
snapshots independent of application types and preserve migration histories.
- Replace entity declarations and storage annotations with `model(...)`; remove
the previous schema reader. Catalog import and project initialization emit the
same Record schema syntax.
- Declare named SQL result and parameter columns with the same helpers and
generate their result classes alongside query methods.

## 6.0.0-beta.2

- Replace shared `part` libraries with independent modules and explicit public
Expand Down
312 changes: 312 additions & 0 deletions CONTRIBUTING.md

Large diffs are not rendered by default.

54 changes: 36 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,45 @@ schema and migrations in Dart. SQLite, PostgreSQL, MySQL and MariaDB share a typ
query API, with explicit database capabilities and transaction boundaries.

[Get started](#get-started) · [Guides](https://github.com/medz/dart-orm/blob/main/doc/README.md) ·
[API reference](https://pub.dev/documentation/orm/6.0.0-beta.2/) ·
[Examples](https://github.com/medz/dart-orm/tree/main/example) · [pub.dev](https://pub.dev/packages/orm/versions/6.0.0-beta.2)
[API reference](https://pub.dev/documentation/orm/6.0.0-beta.3/) ·
[Examples](https://github.com/medz/dart-orm/tree/main/example) · [pub.dev](https://pub.dev/packages/orm/versions/6.0.0-beta.3)

> **6.0 beta:** a new implementation requiring Dart 3.13+. This is a breaking
> replacement for the Prisma-based 5.x client. Read the [release notes](https://github.com/medz/dart-orm/blob/main/CHANGELOG.md)
> before upgrading an existing application.

Upgrading from beta.1: `first()` now requires a row. Use `firstOrNull()` when an
empty result is expected. See the [beta.2 changes](https://github.com/medz/dart-orm/blob/main/CHANGELOG.md#600-beta2)
for export changes and the new `singleOrNull()` API.
Upgrading from beta.2: replace annotated entities and hand-written row types with
`model(...)` and regenerate your clients. Keep existing migration history; table
and column names continue to identify the physical schema. See the
[beta.3 changes](https://github.com/medz/dart-orm/blob/main/CHANGELOG.md#600-beta3).

## Record schemas

Record schemas define each model and table together, without annotations:

```dart
final task = model('tasks', (
id: identity(),
title: text(),
done: boolean(defaultValue: false),
));
```

Import `package:orm/schema.dart` in the definition. Generation produces the `Task`
row, `db.task` and a standalone migration snapshot. See [authoring](https://github.com/medz/dart-orm/blob/main/doc/authoring.md)
and the [complete company example](https://github.com/medz/dart-orm/blob/main/example/company/README.md).

## Get started

Create a Dart application and initialize SQLite:
Create a Dart application and add the package:

```sh
dart create -t console my_app
cd my_app
dart pub add orm:^6.0.0-beta.2
dart pub add orm:6.0.0-beta.3
```

```sh
dart run orm init --database sqlite
```

Expand All @@ -35,13 +55,11 @@ registry. The starter model in `lib/schema.dart` is ordinary Dart:
```dart
import 'package:orm/schema.dart';

final class Task({
@Id.generated() required final int id,
required final String title,
@Default.sql('false') required final bool done,
});

final tasks = entity<Task>();
final task = model('tasks', (
id: identity(),
title: text(),
done: boolean(defaultValue: false),
));
```

Create and review the first migration, then apply it:
Expand All @@ -61,17 +79,17 @@ import 'package:orm/sqlite.dart';
Future<void> main() async {
final db = await sqlite(const SqliteOptions.file('app.sqlite'));
try {
final Task task = await db.tasks.create(title: 'Ship something useful');
final Task task = await db.task.create(title: 'Ship something useful');

final List<(int, String)> pending = await db.tasks
final List<(int, String)> pending = await db.task
.where((t) => t.done.eq(false))
.orderBy((t) => [t.id.asc()])
.select((t) => (t.id, t.title).row)
.get();
print(pending);

await db.transaction((tx) async {
await tx.tasks.byId(task.id).patch(done: .set(true));
await tx.task.byId(task.id).patch(done: .set(true));
});
} finally {
await db.close();
Expand Down Expand Up @@ -157,6 +175,6 @@ migrations without importing today's application models. See [API boundaries](ht
- [Transactions and execution](https://github.com/medz/dart-orm/blob/main/doc/execution.md) · [Subscriptions](https://github.com/medz/dart-orm/blob/main/doc/watch.md)
- [CLI](https://github.com/medz/dart-orm/blob/main/doc/cli.md) · [build_runner](https://github.com/medz/dart-orm/blob/main/doc/generation.md) · [Existing databases](https://github.com/medz/dart-orm/blob/main/doc/importing.md)
- [SQL inspection](https://github.com/medz/dart-orm/blob/main/doc/observability.md) · [Named SQL](https://github.com/medz/dart-orm/blob/main/doc/named-sql.md)
- [Contributing and validation](https://github.com/medz/dart-orm/blob/main/doc/contributing.md)
- [Contributing and validation](https://github.com/medz/dart-orm/blob/main/CONTRIBUTING.md)

Licensed under the [BSD 3-Clause License](https://github.com/medz/dart-orm/blob/main/LICENSE).
Original file line number Diff line number Diff line change
Expand Up @@ -4889,7 +4889,7 @@ $S:21}
A.fO.prototype={
W(a6,a7){var s=0,r=A.aM(t.X),q,p=2,o=[],n=this,m,l,k,j,i,h,g,f,e,d,c,b,a,a0,a1,a2,a3,a4,a5
var $async$W=A.aN(function(a8,a9){if(a8===1){o.push(a9)
s=p}for(;;)A:switch(s){case 0:if(a6==="hello"){q=A.x([1,"811c9351ca7a8a06979b43b9b68aaf97fac2c0c721c506e574d7897eed0693d6"],t.f)
s=p}for(;;)A:switch(s){case 0:if(a6==="hello"){q=A.x([1,"1ffcc1c93a300242a8c4ca7badc270240d0550d23254799eda18232f8bd3312d"],t.f)
s=1
break}s=a6==="open"?3:4
break
Expand Down
45 changes: 28 additions & 17 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
# Dart ORM guides

Start with the [quickstart](https://github.com/medz/dart-orm/blob/main/README.md#get-started), then choose the guide for
the part of your application you are building.
Define a schema, generate typed models and queries, and evolve your database with
reviewed Dart migrations. Start with [schema declarations](https://github.com/medz/dart-orm/blob/main/doc/authoring.md)
and the [company example](https://github.com/medz/dart-orm/blob/main/example/company/README.md).

The [API reference](https://pub.dev/documentation/orm/6.0.0-beta.2/) documents the
beta.2 package. See the [release notes](https://github.com/medz/dart-orm/blob/main/CHANGELOG.md#600-beta2)
when upgrading from beta.1.
Run `dart doc --validate-links` in a checkout to generate the reference from the
current public library and member comments into `doc/api/`.
> **Version:** These guides describe `6.0.0-beta.3` and its Record schema API.
> When upgrading, replace annotated entities with `model(...)` and regenerate
> clients. Keep existing migration history unchanged.

## Define and query

| Task | Guide |
| --- | --- |
| Declare models, keys and relations | [Authoring](https://github.com/medz/dart-orm/blob/main/doc/authoring.md) |
| Understand imports and execution | [API and mental model](https://github.com/medz/dart-orm/blob/main/doc/api.md) |
| Define models, columns, keys and relationships | [Schema declarations](https://github.com/medz/dart-orm/blob/main/doc/authoring.md) |
| Generate a client and use build_runner | [Generation](https://github.com/medz/dart-orm/blob/main/doc/generation.md) |
| Choose imports and open a database | [Entrypoints](https://github.com/medz/dart-orm/blob/main/doc/api.md) |
| Filter, select, join and paginate | [Queries](https://github.com/medz/dart-orm/blob/main/doc/queries.md) |
| Load related data | [Relationships](https://github.com/medz/dart-orm/blob/main/doc/relations.md) |
| Work with domain values | [Types and codecs](https://github.com/medz/dart-orm/blob/main/doc/types.md), [Decimals](https://github.com/medz/dart-orm/blob/main/doc/decimals.md) |
| Define database behavior | [Defaults](https://github.com/medz/dart-orm/blob/main/doc/defaults.md), [Computed columns](https://github.com/medz/dart-orm/blob/main/doc/computed.md), [Checks](https://github.com/medz/dart-orm/blob/main/doc/checks.md) |
| Use domain values, enums and JSON | [Types and codecs](https://github.com/medz/dart-orm/blob/main/doc/types.md), [Decimals](https://github.com/medz/dart-orm/blob/main/doc/decimals.md) |
| Add defaults and database constraints | [Defaults](https://github.com/medz/dart-orm/blob/main/doc/defaults.md), [Computed columns](https://github.com/medz/dart-orm/blob/main/doc/computed.md), [Checks](https://github.com/medz/dart-orm/blob/main/doc/checks.md) |

## Run and maintain

| Task | Guide |
| --- | --- |
| Configure project commands | [CLI](https://github.com/medz/dart-orm/blob/main/doc/cli.md) |
| Evolve or adopt a database | [Migrations](https://github.com/medz/dart-orm/blob/main/doc/migrations.md), [Backfills](https://github.com/medz/dart-orm/blob/main/doc/backfills.md), [Importing](https://github.com/medz/dart-orm/blob/main/doc/importing.md) |
| Use transactions, streaming and timeouts | [Execution](https://github.com/medz/dart-orm/blob/main/doc/execution.md) |
| Subscribe to changes | [Query subscriptions](https://github.com/medz/dart-orm/blob/main/doc/watch.md) |
| Inspect SQL and execution costs | [Observability](https://github.com/medz/dart-orm/blob/main/doc/observability.md), [Performance](https://github.com/medz/dart-orm/blob/main/doc/performance.md) |
| Inspect SQL and query costs | [Observability](https://github.com/medz/dart-orm/blob/main/doc/observability.md), [Performance](https://github.com/medz/dart-orm/blob/main/doc/performance.md) |
| Use hand-written SQL | [Named SQL](https://github.com/medz/dart-orm/blob/main/doc/named-sql.md) |
| Configure generation and project commands | [CLI](https://github.com/medz/dart-orm/blob/main/doc/cli.md), [Generation](https://github.com/medz/dart-orm/blob/main/doc/generation.md) |

## Choose a platform

| Task | Guide |
| --- | --- |
| Check engine and platform limits | [Capabilities](https://github.com/medz/dart-orm/blob/main/doc/capabilities.md) |
| Build Flutter or browser applications | [Flutter](https://github.com/medz/dart-orm/blob/main/doc/flutter.md), [SQLite Web](https://github.com/medz/dart-orm/blob/main/doc/sqlite-web.md) |
| Use MySQL or MariaDB | [Drivers](https://github.com/medz/dart-orm/blob/main/doc/mysql.md), [Migration recovery](https://github.com/medz/dart-orm/blob/main/doc/mysql-migrations.md) |
| Check supported behavior | [Capabilities](https://github.com/medz/dart-orm/blob/main/doc/capabilities.md), [Acceptance](https://github.com/medz/dart-orm/blob/main/doc/acceptance.md) |
| Contribute or reproduce validation | [Contributing](https://github.com/medz/dart-orm/blob/main/doc/contributing.md), [Progress](https://github.com/medz/dart-orm/blob/main/doc/progress.md) |

The beta uses Dart declarations and engine-specific Dart migration histories.
The retired Prisma-based 5.x documentation does not describe this API.
For repository setup, tests and documentation changes, see
[Contributing](https://github.com/medz/dart-orm/blob/main/CONTRIBUTING.md).
85 changes: 0 additions & 85 deletions doc/acceptance.md

This file was deleted.

Loading