Skip to content

add isRaw to Query annotation - #315

Draft
joshuatam wants to merge 14 commits into
pinchbv:developfrom
joshuatam:develop
Draft

joshuatam wants to merge 14 commits into
pinchbv:developfrom
joshuatam:develop

Conversation

@joshuatam

Copy link
Copy Markdown
Contributor

Can achieve raw query like this:

@Query('SELECT * FROM Person WHERE :condition', isRaw: true)
Future<Person> findByCondition(String condition);

and condition like:

String condition = "isDeleted = 0 AND name = '$name'";

@codecov

codecov Bot commented Apr 17, 2020

Copy link
Copy Markdown

Codecov Report

Merging #315 (ac05afb) into develop (41f148d) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head ac05afb differs from pull request most recent head 3ea31e6. Consider uploading reports for the commit 3ea31e6 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #315      +/-   ##
===========================================
- Coverage    90.08%   90.07%   -0.01%     
===========================================
  Files           74       64      -10     
  Lines         1855     1673     -182     
===========================================
- Hits          1671     1507     -164     
+ Misses         184      166      -18     
Flag Coverage Δ
floor ?
floor_generator 90.07% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
floor_generator/lib/value_object/query_method.dart 63.33% <ø> (ø)
...enerator/lib/processor/query_method_processor.dart 100.00% <100.00%> (ø)
...loor_generator/lib/writer/query_method_writer.dart 100.00% <100.00%> (ø)
...r_generator/lib/processor/queryable_processor.dart 96.15% <0.00%> (-0.21%) ⬇️
floor_generator/lib/writer/database_writer.dart 100.00% <0.00%> (ø)
...generator/lib/misc/extension/string_extension.dart 100.00% <0.00%> (ø)
floor/lib/src/util/primary_key_helper.dart
floor/lib/src/callback.dart
floor/lib/src/migration.dart
floor/lib/src/sqflite_database_factory.dart
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 41f148d...3ea31e6. Read the comment docs.

@mqus

mqus commented Apr 23, 2020

Copy link
Copy Markdown
Collaborator

Are you finished already and want a review or is this WIP? If its a work in progress, please convert this PR into a draft for now(The option should be somewhere on the right).
If not, please add some test(s) and I will review.

@joshuatam
joshuatam marked this pull request as draft April 24, 2020 18:27
@joshuatam

Copy link
Copy Markdown
Contributor Author

@mqus Any better ideas to accomplish this feature?
This feature is useful if I need to build the query directly and dynamically.

@mqus

mqus commented Apr 24, 2020

Copy link
Copy Markdown
Collaborator

I think the architecture of floor (or room for that matter) is not well-suited for dynamic querying or query-building, but your approach can definitely work and be a middle ground/workaround for that.

We could try to move to a more complex and powerful RawQuery like room has in the future (when the other building blocks for that are ready) but I think this is sufficient for now .

What are your thoughts, @vitusortner ?

@mqus mqus mentioned this pull request Jun 1, 2020
@required final T Function(Map<String, dynamic>) mapper,
}) async {
final rows = await _database.rawQuery(sql, arguments);
final rows = await (isRaw ? _database.rawQuery(sql.replaceAll('?', arguments[0])) : _database.rawQuery(sql, arguments));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour (using multiple arguments with multiple ? in a query will insert the first argument in all of them) can be pretty unexpected. please use all arguments for replacing and check if the number of ? and arguments match up.

@required final T Function(Map<String, dynamic>) mapper,
}) async {
final rows = await _database.rawQuery(sql, arguments);
final rows = await (isRaw ? _database.rawQuery(sql.replaceAll('?', arguments[0])) : _database.rawQuery(sql, arguments));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

@mqus mqus linked an issue Jul 12, 2020 that may be closed by this pull request
# Conflicts:
#	floor_generator/lib/misc/constants.dart
#	floor_generator/lib/processor/query_method_processor.dart
#	floor_generator/lib/value_object/query_method.dart
@TalebRafiepour

Copy link
Copy Markdown

I need this feature now, How can use your commit in my project?

# Conflicts:
#	floor/lib/src/adapter/query_adapter.dart
#	floor_generator/lib/processor/query_method_processor.dart
#	floor_generator/lib/writer/database_writer.dart
#	floor_generator/lib/writer/query_method_writer.dart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

information

4 participants