Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add isRaw to Query annotation #315

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
Draft

Conversation

joshuatam
Copy link
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
Copy link

codecov bot commented Apr 17, 2020

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
Copy link
Collaborator

mqus commented Apr 23, 2020

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
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
Copy link
Collaborator

mqus commented Apr 24, 2020

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
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
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

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