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 support for geopoly Interface #2946

Merged
merged 13 commits into from
Apr 23, 2024
Merged

Conversation

nikitadol
Copy link
Contributor

Solves #2892

Questions and suggestions regarding implementation are welcome

More tests and perhaps an example will be added soon

Copy link
Owner

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

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

Awesome work with the sqlparser extension! I think we should consider moving the runtime mapping away from the core library to reflect that this is not something all databases support. The rest of this look great!

drift_dev/lib/src/analysis/results/types.dart Show resolved Hide resolved
drift/lib/src/runtime/types/mapping.dart Outdated Show resolved Hide resolved
@nikitadol
Copy link
Contributor Author

Regarding all your comments:
I tried doing this via CustomSqlType, which I put in package:drift/extensions/geopoly.dart, but there are a few problems:

I'm still thinking about a solution, I will be glad if you have any suggestions, since sqlparser cannot depend on drift_dev

Perhaps a mechanism is needed to allow modules to define types

@simolus3
Copy link
Owner

The only place where I can specify a different type of function columns and arguments is here:

I'm using the KnownDriftTypes utility to solve this. package:drift/src/drift_dev_helper.dart exports a bunch of classes which we'd like to resolve in drift_dev, we can then pick them up from there and turn them into InterfaceTypes. That library could also export the geopoly types.

I'm still thinking about a solution, I will be glad if you have any suggestions, since sqlparser cannot depend on drift_dev

But we only need to inject the actual custom type in drift_dev, right? Once the type hint is there it should be preserved by sqlparser.

@nikitadol
Copy link
Contributor Author

I had to slightly change the use of KnownDriftTypes so as not to change many synchronous methods to asynchronous

Or is this not an option?

@simolus3
Copy link
Owner

I had to slightly change the use of KnownDriftTypes so as not to change many synchronous methods to asynchronous

I think this shouldn't be a problem. We need the known types for almost everything involving the driver, so we might as well preload it.

The failing test worries me a bit as loading more assets may degrade build performance, but since this is all coming from external packages that would invalidate the entire build either way, it shouldn't be a problem.
You can apply this patch to fix the test

diff --git a/drift_dev/test/backends/build/build_integration_test.dart b/drift_dev/test/backends/build/build_integration_test.dart
index d81f397f..e1828132 100644
--- a/drift_dev/test/backends/build/build_integration_test.dart
+++ b/drift_dev/test/backends/build/build_integration_test.dart
@@ -583,6 +583,8 @@ class MyDatabase {
       return everyElement(
         anyOf(
           isA<AssetId>().having((e) => e.extension, 'extension', '.json'),
+          // Allow reading SDK or other package assets to set up the analyzer.
+          isA<AssetId>().having((e) => e.package, 'package', isNot('a')),
           other,
         ),
       );

Copy link
Owner

@simolus3 simolus3 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 added a simple test to drift to make sure the type is roughly doing what it's supposed to. This looks good to me now, but I want to merge #2939 first.

@nikitadol
Copy link
Contributor Author

Thanks for helping
I also fixed some tests and added clarification to the documentation, since by default geopoly is not in the sqlite3_flutter_libs package

@simolus3
Copy link
Owner

LGTM, thanks! 👍

@simolus3 simolus3 merged commit 8865e93 into simolus3:develop Apr 23, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants