Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Electric custom types (eg, Postgres date type) not generating correct SQL for query. #10

Closed
davidhole opened this issue Mar 4, 2024 · 3 comments

Comments

@davidhole
Copy link

All ElectricTypes custom types currently implement DialectAwareSqlType via CustomElectricTypeGeneric. Which is great, but there is currently a bug in drift which, when creating variables via query builders, it does not correctly pass through the electric type as the helper is checking against CustomSqlType and not UserDefinedSqlType.

See: https://github.com/SkillDevs/electric_dart/blob/master/packages/electricsql/lib/src/client/conversions/custom_types.dart

Helper:

/// Utilities to derive other expressions with a type compatible to `this`
/// expression.
extension WithTypes<T extends Object> on Expression<T> {
  /// Creates a variable with a matching [driftSqlType].
  Variable<T> variable(T? value) {
    return switch (driftSqlType) {
      CustomSqlType<T> custom => Variable(value, custom),
      _ => Variable(value),
    };
  }
}

I've currently opened a PR to type-check against UserDefinedSqlType instead of CustomSqlType as that is what the Variable constructor is expecting: simolus3/drift#2909

This is more of an FYI issue as queries on for example the Postgres date type are currently not working in Electric Dart.

@davidmartos96
Copy link
Contributor

Good catch! Thanks for the heads up. We'll keep this open until drift releases a hotfix.

@davidhole
Copy link
Author

Thanks @davidmartos96, doesn't look like the fix is far off :)

@davidmartos96
Copy link
Contributor

Fixed in version 2.17.0 of drift. Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants