Skip to main content

dox_orm 3.0.0-alpha.5 copy "dox_orm: ^3.0.0-alpha.5" to clipboard
dox_orm: ^3.0.0-alpha.5 copied to clipboard

PostgreSQL, MySQL, MariaDB and SQLite query builder, Support Model, Where, orWhere, Find, Join, softDeletes, Debugging and many mores.

example/example.md

dox_orm example #

A model, a migration and the common queries. The full guide is on dartondox.dev.

1. Config #

import 'package:dox_orm/dox_orm.dart';

DatabaseConfig databaseConfig = DatabaseConfig(
  connection: 'sqlite',
  connections: <String, ConnectionConfig>{
    'sqlite': ConnectionConfig(
      driver: Driver.sqlite,
      database: 'db/app.sqlite',
    ),
  },
);

2. Migration #

import 'package:dox_migration/dox_migration.dart';

class CreatePostsTable extends Migration {
  @override
  Future<void> up(Schema schema) async {
    await schema.create('posts', (Table table) {
      table.id();
      table.string('title');
      table.text('body');
      table.string('status').defaultTo('draft');
      table.timestamps();
    });
  }

  @override
  Future<void> down(Schema schema) async {
    await schema.dropIfExists('posts');
  }
}

3. Model #

import 'package:dox_orm/dox_orm.dart';

part 'post.model.g.dart';

@DoxModel(table: 'posts')
class Post extends PostGenerator {
  @Column()
  String? title;

  @Column()
  String? body;

  @Column()
  String? status;
}

Run dart run build_runner build to make post.model.g.dart.

4. Queries #

// create
Post post = Post()
  ..title = 'Hello'
  ..body = 'First post';
await post.save();

// read
Post? one = await Post().find(post.id);
List<Post> drafts = await Post()
    .where('status', 'draft')
    .orderBy('id', 'desc')
    .limit(10)
    .get();

// update
one?.title = 'Hello again';
await one?.save();

// delete
await one?.delete();
0
likes
160
points
0
downloads

Documentation

API reference

Publisher

verified publisherdartondox.dev

Weekly Downloads

PostgreSQL, MySQL, MariaDB and SQLite query builder, Support Model, Where, orWhere, Find, Join, softDeletes, Debugging and many mores.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

dox_annotation, dox_mysql_native, dox_postgres_native, dox_validation, mysql_dart, postgres, sqlite3

More

Packages that depend on dox_orm