Replies: 4 comments 7 replies
-
The format used by drift can't be changed.
As long as you're still using the date times as text option, you could use a text type with a converter using the SQL Alchemy format. The trick is to use dartCast to reinterpret the text as a date time expression - that will make the builtin date time APIs available. It's still a little more verbose than the default option, but it doesn't require any custom queries. |
Beta Was this translation helpful? Give feedback.
-
Wait, there is actually a way. You can use custom SQL types for that: class SqlAlchemyCompatibleDateTime implements CustomSqlType<DateTime> {
const SqlAlchemyCompatibleDateTime();
@override
String mapToSqlLiteral(DateTime dartValue) {
return "'${mapToSqlParameter(dartValue)}'";
}
@override
String mapToSqlParameter(DateTime dartValue) {
// todo: Read date time from text representation
}
@override
DateTime read(Object fromSql) {
// todo: Read date time from text representation
}
@override
String sqlTypeName(GenerationContext context) {
return 'TEXT';
}
} And then, in a table: DateTimeColumn get date => customType(const SqlAlchemyCompatibleDateTime())(); |
Beta Was this translation helpful? Give feedback.
-
I get a similar behavior in queries with a where condition on a column with a for instance to store UUID v4 without the hyphen in the database I made a type converter
But when I send a select query with a |
Beta Was this translation helpful? Give feedback.
-
here an example that does not convert date to my custom type:
with
Here an example with uuid which does not convert the argument of the query to my desired type:
so I need to convert the uuid manually
|
Beta Was this translation helpful? Give feedback.
-
I'm building a flutter application that should be able to write and retrieve data on a database where also a python application which uses sqlAlchemy writes and read the database. Unfortunatly SQL alchemy default rendering is modified ISO-8601 rendering (i.e. ISO-8601 with the T converted to a space) https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html which makes date handling complicated.
Is there a way to have drift database to write the date in the database as "ISO-8601 without T" but while keeping the type of the column DateTime (changing it to text will make it harder to do queries on the date, say for instance I want to do a select distinct on the Date only without time using drift and not custom queries .)
Beta Was this translation helpful? Give feedback.
All reactions