-
Notifications
You must be signed in to change notification settings - Fork 354
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
Support CAST for special dart types and MAPPED BY in queries #2235
Comments
|
I'm getting an error here: I also tried to using it in a view and it didn't work there (though maybe thats more complicated)
|
Just tried with bc325dd and its working! |
Ah, spoke too soon. The converter isn't being generated (I'm using Generated View:
|
As of a6bede2, type converters for views should be generated. I've also added support for casts to drift-specific SQL types. |
Works mostly for me. Although I noticed this because something odd happened when I changed |
Yikes, that should be fixed in 4b83810. |
Never mind, that seemed to be a cache bug (I've had this a couple times recently). I was definitely on 4b8310 when I tested it previously, but its now consistently generating the correct code. |
@simolus3 @North101 Hopefully one of you could shed some light on my situation. My case strongly feels like the issue mentioned in your earlier comments. I have a CREATE VIEW my_view AS
SELECT
CAST(id AS INTEGER) AS id,
location.createdAt,
CAST(location.country AS ENUMNAME(COUNTRY)) AS country,
...
FROM x
INNER JOIN ...
LEFT JOIN ...
WHERE ... This generates a ViewData class: class ViewData extends DataClass {
final int id;
final String? createdAt;
final String country;
const ViewData() What I'm trying to achieve is that both Drift version:
|
That does indeed sound very similar to the previous problem. Nullable columns should never be made non-nullable and we have tests for the previous bug, but the analysis isn't exactly straightforward and I wonder whether the joins could trip it up for instance. Do you have a way to share fairly complete code that reproduces the issue? Then I can take a look at the intermediate analysis changes to see where wrong result is coming from. |
@simolus3 Morning. I've made a demo project that reproduces the issue, you can find it here. In the demo project I have: Enum class Drift Table
And a view via tables.drift CREATE VIEW drift_cast_view AS
SELECT
CAST(id AS INTEGER) AS id,
CAST(country AS ENUMNAME(COUNTRY)) AS country
FROM DriftCast; Which generates class DriftCastViewData extends DataClass {
final int id;
final String country;
const DriftCastViewData({required this.id, required this.country});
...
} |
After adding the necessary imports to the drift file (which also fixes the warnings emitted by import 'package:drift_cast/features/drift_cast/data/model/drift_cast.dart';
import 'package:drift_cast/core/constants/country.dart';
CREATE VIEW drift_cast_view AS
SELECT
CAST(id AS INTEGER) AS id,
CAST(country AS ENUMNAME(COUNTRY)) AS country
FROM drift_cast; You also need to replace Technically drift could have generated the columns as nullable before, but due to the unresolved table reference it had no idea about their types and essentially guessed their nullability. I think that's fine since the view had an inalid definition, so attempting to create it in the database would have failed as well. |
Nice! I've updated the drift file with your suggestions and everything clicked 👍 . Thanks for your quick responses, amazing library. |
It would be nice to support CAST for special dart types (e.g. ENUMNAME, BOOLEAN, DATETIME) and
MAPPED BY
in queries.(Not the best example)
The text was updated successfully, but these errors were encountered: