add type literals for individual dialect in SqlDialect used in sqlTypeName

This commit is contained in:
BananaMasterz 2023-07-19 11:31:58 +03:00
parent 125325b9f0
commit 910e063ab8
2 changed files with 52 additions and 29 deletions

View File

@ -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,
});
}

View File

@ -321,40 +321,23 @@ enum DriftSqlType<T extends Object> implements _InternalDriftSqlType<T> {
// ignore: unnecessary_cast
switch (this as DriftSqlType<Object>) {
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';
}