mirror of https://github.com/AMT-Cheif/drift.git
add type literals for individual dialect in SqlDialect used in sqlTypeName
This commit is contained in:
parent
125325b9f0
commit
910e063ab8
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue