pinchbv / floor

The typesafe, reactive, and lightweight SQLite abstraction for your Flutter applications
https://pinchbv.github.io/floor/
Apache License 2.0
977 stars 191 forks source link

information #348

Open daniloadorno opened 4 years ago

daniloadorno commented 4 years ago

how to do?

@Query(sql) Future findBySql(String sql);

in .g.dart

@override Future findBySql(String sql) async { return _queryAdapter.query(sql, mapper: _tMapper); }

mqus commented 4 years ago

Sadly we don't allow completely dynamic queries like yours. Your use-case might be an exception but generally this is also not a good idea because of sql-injections and other issues.

It might be possible to use @rawQuery/isRaw for this once it is implemented (see #315), but you will miss auto-updated Streams and static type validation, which can only be done on queries which are known at compile time.

daniloadorno commented 4 years ago

is that in some cases it is necessary to take only one field, in other cases it is necessary to make a count, in other cases it is necessary to do sum, the dynamic query would greatly decrease the creation of methods.

daniloadorno commented 4 years ago

I made this implementation to give me this power:

ex:

Future<List> findListBySql(String sql) async { final rows = await dbHelper.database.rawQuery(sql); return rows.map((row) => Account.fromJson(row)).toList(); }