Before starting with the ORM, it is highly recommended to familiar one’s self withpackage:angel_serialize, as it is the foundation for package:angel_orm:

    https://github.com/angel-dart/serialize

    To enable the ORM for a given model, simply add the @orm annotation to its definition:

    1. @orm
    2. @serializable
    3. abstract class _Todo {
    4. bool get isComplete;
    5. String get text;
    6. @Column(type: ColumnType.long)
    7. int get score;
    8. }

    The generator will produce a TodoQuery class, which contains fields corresponding to each field declared in _Todo.Each of TodoQuery‘s fields is a subclass of SqlExpressionBuilder, corresponding to the given type. For example, TodoQuerywould look something like:

    1. class TodoQuery extends Query<Todo, TodoQueryWhere> {
    2. BooleanSqlExpressionBuilder get isComplete;
    3. StringSqlExpressionBuilder get text;
    4. NumericSqlExpressionBuilder<int> get score;
    5. }

    Thus, you can query the database using plain-old-Dart-objects (PODO’s):

    1. Future<List<Todo>> leftToDo(QueryExecutor executor) async {
    2. var query = TodoQuery()..where.isComplete.isFalse;
    3. return await query.get(executor);
    4. }
    5. Future<void> markAsComplete(Todo todo, QueryExecutor executor) async {
    6. var query = TodoQuery()
    7. ..where.id.equals(todo.idAsInt)
    8. ..values.isComplete = true;
    9. await query.updateOne(executor);
    10. }

    The glue holding everything together is the QueryExecutor interface. To support the ORMfor any arbitrary database, simply extend the class and implement its abstract methods.

    Consumers of a QueryExecutor typically inject it into the app’sdependency injection container:

    1. app.container.registerSingleton<QueryExecutor>(PostgresExecutor(...));

    At the time of this writing, there is only support for PostgreSQL, though more databases maybe added eventually.