dart-bridge / trestle

Database Gateway and ORM for Dart
MIT License
26 stars 12 forks source link

Usage of raw SQL statements. #4

Closed Bzik closed 8 years ago

Bzik commented 8 years ago

It would be great if we could use SQL commands. In the case of complex commands or lack of support from the library.

emilniklas commented 8 years ago

Hello!

There are a few drivers provided by the library. Most of them inherit from the common SqlDriver class. If you get the driver directly (not through the Gateway), you can access the execute method on the SqlDriver. That will let you execute any SQL query, returning a Stream<Map<String, dynamic>>.

Example:

final driver = new PostgreSqlDriver( ... );
final gateway = new Gateway(driver);

main() {
  gateway
    .table('users')
    .where((user) => user.age > 18)
    .get()
    .listen(print);

  driver.execute('SELECT * FROM "users" WHERE "age" > 18')
    .listen(print);
}