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

Feature: Add support for @DatabaseView annotations #262

Merged
merged 7 commits into from Mar 15, 2020

Conversation

mqus
Copy link
Collaborator

@mqus mqus commented Feb 15, 2020

This adds support for @DatabaseView annotations known from room. One test was added, further testing is needed. Implements #130. I tried to do minimal adjustments to the codebase while copying the handling of entities. I took over the Field handling from there and then just ignored the nullable property by implementing the createStatement function differently.

As I already said in #259, I may have no idea what I'm doing, so please tell me if I did something wrong or if I can do something better.

I'll try to add some more tests before this is ready to merge. Are there some specific things you would like to see tested?

@mqus
Copy link
Collaborator Author

mqus commented Feb 16, 2020

The test that's currently failing is the same as in #259 and as far as I can tell, this fails even on the current develop branch. I assume that some underlying framework (dart?) got changed but I couldn't find the issue with my very limited knowledge of Streams.

@vitusortner
Copy link
Collaborator

At a first glance, this looks great 🎉 Thanks for your contribution! I'll review the full PR as soon as possible.

@mqus
Copy link
Collaborator Author

mqus commented Feb 19, 2020

Some remarks about hacks I did and shouldn't change back myself right now:

  • floor_generator relies on floor_annotation via path: ../floor_annotation because it needs the new annotations. This has to be changed before the next release but can't be changed right now because nothing would work anymore.
  • the same for floor, which relies on floor_generator and floor_annotation.

I also messed up my branches a bit when starting out so view_processor.dart already checks for Uint8List, even if the whole rest of the code can't do anything with it. If you want to merge this PR before #259, I'll remove it. If #259 comes first, I'll rebase and use the proper getter there.

@vitusortner
Copy link
Collaborator

  • floor_generator relies on floor_annotation via path: ../floor_annotation because it needs the new annotations. This has to be changed before the next release but can't be changed right now because nothing would work anymore.
  • the same for floor, which relies on floor_generator and floor_annotation.

No problem. Normally, I only change the paths of the library's packages to point to the versions available on pub while creating a release. I must have forgotten to revert it to referring the local version. You can leave it as it is.

I also messed up my branches a bit when starting out so view_processor.dart already checks for Uint8List, even if the whole rest of the code can't do anything with it. If you want to merge this PR before #259, I'll remove it. If #259 comes first, I'll rebase and use the proper getter there.

Let's merge #259 before.

@mqus
Copy link
Collaborator Author

mqus commented Feb 23, 2020

I rebased the PR onto the current develop branch and altered view_processor.dart as written before.
I know that an integration test for the Views is still missing and maybe more, do you have any suggestions on what/how should be tested?

@codecov
Copy link

codecov bot commented Mar 11, 2020

Codecov Report

Merging #262 into develop will decrease coverage by 0.61%.
The diff coverage is 82.80%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #262      +/-   ##
===========================================
- Coverage    81.27%   80.66%   -0.62%     
===========================================
  Files           51       48       -3     
  Lines         1383     1298      -85     
===========================================
- Hits          1124     1047      -77     
+ Misses         259      251       -8     
Flag Coverage Δ
#floor ?
#floor_generator 80.66% <82.80%> (+0.06%) ⬆️
Impacted Files Coverage Δ
floor_generator/lib/misc/constants.dart 100.00% <ø> (ø)
floor_generator/lib/value_object/database.dart 5.26% <0.00%> (-0.62%) ⬇️
...ator/lib/processor/error/view_processor_error.dart 20.00% <20.00%> (ø)
floor_generator/lib/value_object/query_method.dart 64.28% <33.33%> (ø)
floor_generator/lib/value_object/view.dart 74.19% <74.19%> (ø)
...or_generator/lib/processor/database_processor.dart 76.27% <82.35%> (+1.27%) ⬆️
...r_generator/lib/processor/queryable_processor.dart 88.23% <88.23%> (ø)
floor_generator/lib/processor/view_processor.dart 95.65% <95.65%> (ø)
floor_generator/lib/processor/dao_processor.dart 100.00% <100.00%> (ø)
...loor_generator/lib/processor/entity_processor.dart 75.47% <100.00%> (-2.79%) ⬇️
... and 20 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 d0727f8...465389d. Read the comment docs.

@mqus
Copy link
Collaborator Author

mqus commented Mar 11, 2020

So, I rebased to the current develop and added some more tests (CodeCov seems to work even for PRs now, nice :) )

There is only one open question for me now: Streams will not work as expected for views right now. Should this also be done in this PR? If so, then there are three ways to get the tables/entities we have to watch for a specific DatabaseView:

  1. We try to detect them in the select query for the view (Seems pretty impossible with all the possibilities to include table names and naming things similarly)
  2. Users have to provide the Entities on which a view depends in the @DatabaseView annotation. (easy but could lead to an unsafe/leaky way of using the library, since we can't check or guarantee the relation)
  3. SQLite/sqflite somehow provides this (I'm not aware of that)
  4. Any other Ideas?

PS: Ah, right, I should document the DatabaseView usage in the README, or do you want to do it yourself?

Edit: I meant Streams. Fixed the comment to make more sense.

Copy link
Collaborator

@vitusortner vitusortner left a comment

Choose a reason for hiding this comment

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

I've started a review a couple days ago. I'll just post the current progress now and will end the review sometime soon.

floor_annotation/lib/src/database.dart Outdated Show resolved Hide resolved
floor_annotation/lib/src/database_view.dart Outdated Show resolved Hide resolved
floor_generator/lib/value_object/database.dart Outdated Show resolved Hide resolved
floor_generator/lib/processor/database_processor.dart Outdated Show resolved Hide resolved
floor_generator/lib/processor/database_processor.dart Outdated Show resolved Hide resolved
@mqus
Copy link
Collaborator Author

mqus commented Mar 11, 2020

Thank you! I wont disrupt you then ;). Regarding Streams: Afaict Room seems to take the first option and includes a whole sqlite parser...

Copy link
Collaborator

@vitusortner vitusortner left a comment

Choose a reason for hiding this comment

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

Looking pretty good! I've left some comments and I'm excited for your input.

floor/test/integration/database_test.dart Outdated Show resolved Hide resolved
floor/test/integration/database_test.dart Outdated Show resolved Hide resolved
floor/test/integration/database_test.dart Outdated Show resolved Hide resolved
floor/test/integration/database_test.dart Outdated Show resolved Hide resolved
floor/test/integration/dao/name_dao.dart Show resolved Hide resolved
floor_generator/lib/processor/dao_processor.dart Outdated Show resolved Hide resolved
floor_generator/lib/processor/query_method_processor.dart Outdated Show resolved Hide resolved
floor_generator/lib/processor/query_method_processor.dart Outdated Show resolved Hide resolved
floor_generator/lib/value_object/dao.dart Outdated Show resolved Hide resolved
floor_generator/test/processor/view_processor_test.dart Outdated Show resolved Hide resolved
This adds initial support for @DatabaseView annotations known from room. One test was added, further testing is needed. Implements pinchbv#130.

fix linting error
- Do not allow queries from views to be streamed
	- throw error if a user tries to do that and test that error
	- remove Stream<> queries from DAO in integration test
	- getStreamEntities will only return entities again

- Create new Superclass for EntityProcessor and ViewProcessor named QueryableProcessor to deduplicate common functions

- Code cleanup
	- clean up integration tests
	- improve code layout and comment wording in annotations, DatabaseProcessor, QueryMethodProcessor
	- fix toString and hashCode methods in Database (value object)
	- improve error message wording in DatabaseViewError
@mqus
Copy link
Collaborator Author

mqus commented Mar 14, 2020

I rebased, integrated most of the suggestions and added an exception if a library user will try to use a Dao method which will stream the results of a query on a database view.

floor/test/integration/view_test/view_test.dart Outdated Show resolved Hide resolved
floor/test/integration/view_test/view_test.dart Outdated Show resolved Hide resolved
floor_generator/lib/processor/queryable_processor.dart Outdated Show resolved Hide resolved
floor_generator/lib/value_object/database.dart Outdated Show resolved Hide resolved
Comment on lines 2 to 8
import 'package:floor_generator/value_object/deletion_method.dart';
import 'package:floor_generator/value_object/entity.dart';
import 'package:floor_generator/value_object/insertion_method.dart';
import 'package:floor_generator/value_object/query_method.dart';
import 'package:floor_generator/value_object/transaction_method.dart';
import 'package:floor_generator/value_object/update_method.dart';

import 'entity.dart';
Copy link
Collaborator

Choose a reason for hiding this comment

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

💡We could get rid of all the unnecessary import qualifiers.

import 'deletion_method.dart';
import 'entity.dart';
import 'insertion_method.dart';
import 'query_method.dart';
import 'transaction_method.dart';
import 'update_method.dart';

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Then we should do it everywhere... but I think this should be part of another PR... I'll just put the entity import back where it was for now to make int consistent with the other statements...

- Clean up small details in code, according to the review

- Improve tests
 - Simplify integration tests
 - split off and merge common QueryableProcessor tests into a separate file
 - move createClassElement function, which is now used in three test files to testutils

- Add documentation to README.md
@mqus
Copy link
Collaborator Author

mqus commented Mar 14, 2020

I adopted the suggestions from the review and added some documentation to the README files.

Copy link
Collaborator

@vitusortner vitusortner left a comment

Choose a reason for hiding this comment

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

LGTM 👍Thanks for this contribution!

@vitusortner vitusortner merged commit 56a2763 into pinchbv:develop Mar 15, 2020
@tulioccalazans
Copy link

@vitusortner When this feature will be available as a release?

@vitusortner
Copy link
Collaborator

We've just created a new release with the version 0.12.0, which makes database views available and includes other features, fixes and improvements.

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.

None yet

3 participants