angel3_orm_service 8.2.2 copy "angel3_orm_service: ^8.2.2" to clipboard
angel3_orm_service: ^8.2.2 copied to clipboard

Service implementation that wraps over Angel3 ORM Query classes.

example/main.dart

import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_framework/http.dart';
import 'package:angel3_orm_service/angel3_orm_service.dart';
import 'package:logging/logging.dart';
import 'connect.dart';
import 'todo.dart';

void main() async {
  // Logging, connection setup.
  hierarchicalLoggingEnabled = true;
  var app = Angel(logger: Logger.detached('orm_service'));
  var http = AngelHttp(app);
  var executor = await connect();
  app.logger.onRecord.listen((rec) {
    print(rec);
    if (rec.error != null) print(rec.error);
    if (rec.stackTrace != null) print(rec.stackTrace);
  });

  // 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` ID's (this is the case when using `angel_orm_generator` and `Model`).
  // **
  app.use<int, Todo, OrmService<int, Todo, TodoQuery>>(
      '/api/todos', todoService);

  // Clean up when we are done.
  app.shutdownHooks.add((_) => executor.close());

  await http.startServer('127.0.0.1', 3000);
  print('Listening at ${http.uri}');
  print('Todos API: ${http.uri}/api/todos');
}
0
likes
160
points
177
downloads

Publisher

verified publisherdukefirehawk.com

Weekly Downloads

Service implementation that wraps over Angel3 ORM Query classes.

Homepage
Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

angel3_framework, angel3_orm, optional, postgres

More

Packages that depend on angel3_orm_service