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

Always support Strings regardless of actual record type #69

Closed
knaeckeKami opened this issue Jul 9, 2019 · 0 comments
Closed

Always support Strings regardless of actual record type #69

knaeckeKami opened this issue Jul 9, 2019 · 0 comments

Comments

@knaeckeKami
Copy link
Contributor

SQLite has a rather weak type system, and does not enforce type affinity.
sqflite seems to ignore the type affinity of the column. It returns a Map<String, dynamic>, where the type of the values are Strings, Ints, doubles...

If you have an embedded db in your application, where a column has a mixed type (sometimes numeric, sometimes text), the application likely wants to treat this column as TextColumn.

This currently does not work with Moor, as the implementation of StringType tries to cast the dynamic value to String: String mapFromDatabaseResponse(response) => response as String;.

This fails of course if response is an int. Using IntColumn would fail for records that don't have a numeric value.
With raw sqflite, I could work around this issue by calling toString() on the value of the result.

I suggest changing the implementation to

String mapFromDatabaseResponse(response) => response.toString();

The performance impact should be negligible in case response is a String, as toString() just returns itself, but it would make TextColumn usable on columns with mixed types.

Alternatively, a method like .forceConvertToText() could be added to TextColumnBuilder, which would change the behaviour to calling .toString() instead of casting.

I am currently trying to migrate to moor from raw sqflite and this issue is blocking me from doing so.

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

No branches or pull requests

2 participants