angel3_orm_service 10.0.0
angel3_orm_service: ^10.0.0 copied to clipboard
Service implementation that wraps over Angel3 ORM Query classes.
Angel3 ORM Service #
Service implementation that wraps over Angel3 ORM Query classes.
Installation #
In your pubspec.yaml:
dependencies:
angel3_orm_service: ^10.0.0
Usage #
Brief snippet (check example/main.dart for setup, etc.):
// Create an ORM-backed service.
var todoService = OrmService<int, Todo, TodoQuery>(
executor,
() => TodoQuery(),
readData: (req, res) => todoSerializer.decode(req.bodyAsMap),
);
// Because we provided `readData`, the todoService can face the Web.
// **IMPORTANT:** Providing the type arguments is an ABSOLUTE MUST if your
// model has `int` IDs (this is the case when using `angel3_orm_generator`
// and `Model`).
app.use<int, Todo, OrmService<int, Todo, TodoQuery>>(
'/api/todos',
todoService,
);
Querying #
A REST client can filter and sort the records of index and the other methods with query parameters:
?level=100matches the records whoselevelcolumn is100. The value is converted to the column's type (a number, a boolean or a date). A parameter that names no column, or a value that cannot be converted, is a400 Bad Request.?$sort=namesorts by a column. Only the query's own columns are accepted, as the name is written into the SQL; any other is a400 Bad Request. On the server,$sortcan also be a map of columns to1or-1, such as{'name': -1}for descending order.
On the server, params['query'] can also be a callback that is given the query, such as (TodoQuery q) => q.where!.isComplete.isFalse.
Updates #
modify (PATCH) changes only the fields it is given, and update (PUT) replaces every field of the record. Both change one record, by its id.