orm 6.0.0-beta.1 copy "orm: ^6.0.0-beta.1" to clipboard
orm: ^6.0.0-beta.1 copied to clipboard

Typed relational data access for Dart, from declaration to migration.

example/main.dart

import 'package:orm/migrate.dart';
import 'package:orm/sqlite.dart';

import 'schema.orm.dart';

Future<void> main() async {
  final db = await sqlite(const SqliteOptions.memory());
  try {
    await Migrator(
      db.sql,
    ).apply([Migration.create('0001_initial', appSchema, dialect: db.dialect)]);
    final User user = await db.transaction((tx) async {
      final User user = await tx.users.create(email: 'seven@example.com');
      await tx.posts.create(
        authorId: user.id,
        title: 'Hello Dart',
        createdAt: DateTime.now(),
      );
      return user;
    });
    await db.users.byId(user.id).patch(nickname: .set('Seven'));
    final cards = await db.users
        .select(
          (u) => (
            u.email,
            u.posts
                .orderBy((p) => [p.createdAt.desc(), p.id.desc()])
                .take(3)
                .select((p) => p.title)
                .many(),
          ).map((email, titles) => (email: email, titles: titles)),
        )
        .get();
    print(cards);
  } finally {
    await db.close();
  }
}
240
likes
0
points
1.36k
downloads

Documentation

Documentation

Publisher

verified publisherodroe.dev

Weekly Downloads

Typed relational data access for Dart, from declaration to migration.

Repository (GitHub)
View/report issues

Topics

#orm #database #sqlite #postgresql #mysql

License

unknown (license)

Dependencies

analyzer, build, crypto, dart_style, mysql_client_plus, path, postgres, sqlite3, web

More

Packages that depend on orm