diff --git a/drift/lib/src/runtime/query_builder/query_builder.dart b/drift/lib/src/runtime/query_builder/query_builder.dart index 2162c3ab..8269239c 100644 --- a/drift/lib/src/runtime/query_builder/query_builder.dart +++ b/drift/lib/src/runtime/query_builder/query_builder.dart @@ -93,14 +93,54 @@ void _writeCommaSeparated( enum SqlDialect { /// Use sqlite's sql dialect. This is the default option and the only /// officially supported dialect at the moment. - sqlite, + sqlite( + textType: 'TEXT', + integerType: 'INTEGER', + realType: 'REAL', + blobType: 'BLOB', + ), /// (currently unsupported) - mysql, + mysql( + booleanType: '', + textType: '', + integerType: '', + blobType: '', + realType: '', + ), /// PostgreSQL (currently supported in an experimental state) - postgres, + postgres( + booleanType: 'boolean', + textType: 'text', + integerType: 'bigint', + blobType: 'bytea', + realType: 'float8', + ), /// MariaDB (currently supported in an experimental state) - mariadb, + mariadb( + booleanType: 'BOOLEAN', + textType: 'TEXT', + bigIntType: 'BIGINT', + integerType: 'INT', + blobType: 'BLOB', + realType: 'DOUBLE', + ); + + final String? booleanType; + final String textType; + final String? bigIntType; + final String integerType; + final String realType; + final String blobType; + + const SqlDialect({ + required this.textType, + required this.integerType, + required this.realType, + required this.blobType, + this.booleanType, + this.bigIntType, + }); } diff --git a/drift/lib/src/runtime/types/mapping.dart b/drift/lib/src/runtime/types/mapping.dart index 94b34b35..955e1d21 100644 --- a/drift/lib/src/runtime/types/mapping.dart +++ b/drift/lib/src/runtime/types/mapping.dart @@ -321,40 +321,23 @@ enum DriftSqlType implements _InternalDriftSqlType { // ignore: unnecessary_cast switch (this as DriftSqlType) { case DriftSqlType.bool: - return dialect == SqlDialect.sqlite - ? 'INTEGER' - : dialect == SqlDialect.mariadb - ? 'BOOL' - : 'boolean'; + return dialect.booleanType ?? dialect.integerType; case DriftSqlType.string: - return dialect == SqlDialect.sqlite || dialect == SqlDialect.mariadb - ? 'TEXT' - : 'text'; + return dialect.textType; case DriftSqlType.bigInt: + return dialect.bigIntType ?? dialect.integerType; case DriftSqlType.int: - return dialect == SqlDialect.sqlite - ? 'INTEGER' - : dialect == SqlDialect.mariadb - ? 'INT' - : 'bigint'; + return dialect.integerType; case DriftSqlType.dateTime: if (context.typeMapping.storeDateTimesAsText) { - return dialect == SqlDialect.sqlite || dialect == SqlDialect.mariadb - ? 'TEXT' - : 'text'; + return dialect.textType; } else { - return dialect == SqlDialect.sqlite ? 'INTEGER' : 'bigint'; + return dialect.integerType; } case DriftSqlType.blob: - return dialect == SqlDialect.sqlite || dialect == SqlDialect.mariadb - ? 'BLOB' - : 'bytea'; + return dialect.blobType; case DriftSqlType.double: - return dialect == SqlDialect.sqlite - ? 'REAL' - : dialect == SqlDialect.mariadb - ? 'DOUBLE' - : 'float8'; + return dialect.realType; case DriftSqlType.any: return 'ANY'; }