mirror of https://github.com/AMT-Cheif/drift.git
Remove drift_dev's ColumnType
This commit is contained in:
parent
4d9b505703
commit
867f8cbfed
|
@ -439,16 +439,16 @@ class ColumnParser {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnType _startMethodToColumnType(String name) {
|
DriftSqlType _startMethodToColumnType(String name) {
|
||||||
return const {
|
return const {
|
||||||
startBool: ColumnType.boolean,
|
startBool: DriftSqlType.bool,
|
||||||
startString: ColumnType.text,
|
startString: DriftSqlType.string,
|
||||||
startInt: ColumnType.integer,
|
startInt: DriftSqlType.int,
|
||||||
startInt64: ColumnType.bigInt,
|
startInt64: DriftSqlType.bigInt,
|
||||||
startEnum: ColumnType.integer,
|
startEnum: DriftSqlType.int,
|
||||||
startDateTime: ColumnType.datetime,
|
startDateTime: DriftSqlType.dateTime,
|
||||||
startBlob: ColumnType.blob,
|
startBlob: DriftSqlType.blob,
|
||||||
startReal: ColumnType.real,
|
startReal: DriftSqlType.double,
|
||||||
}[name]!;
|
}[name]!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,15 +166,15 @@ class ViewParser {
|
||||||
return results.whereType();
|
return results.whereType();
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnType? _dartTypeToColumnType(String name) {
|
DriftSqlType? _dartTypeToColumnType(String name) {
|
||||||
return const {
|
return const {
|
||||||
'bool': ColumnType.boolean,
|
'bool': DriftSqlType.bool,
|
||||||
'String': ColumnType.text,
|
'String': DriftSqlType.string,
|
||||||
'int': ColumnType.integer,
|
'int': DriftSqlType.int,
|
||||||
'BigInt': ColumnType.bigInt,
|
'BigInt': DriftSqlType.bigInt,
|
||||||
'DateTime': ColumnType.datetime,
|
'DateTime': DriftSqlType.dateTime,
|
||||||
'Uint8List': ColumnType.blob,
|
'Uint8List': DriftSqlType.blob,
|
||||||
'double': ColumnType.real,
|
'double': DriftSqlType.double,
|
||||||
}[name];
|
}[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ ExistingRowClass? validateExistingClass(
|
||||||
UsedTypeConverter? readTypeConverter(
|
UsedTypeConverter? readTypeConverter(
|
||||||
LibraryElement library,
|
LibraryElement library,
|
||||||
Expression dartExpression,
|
Expression dartExpression,
|
||||||
ColumnType columnType,
|
DriftSqlType columnType,
|
||||||
bool columnIsNullable,
|
bool columnIsNullable,
|
||||||
void Function(String) reportError,
|
void Function(String) reportError,
|
||||||
HelperLibrary helper, {
|
HelperLibrary helper, {
|
||||||
|
@ -206,7 +206,7 @@ void _checkParameterType(
|
||||||
}
|
}
|
||||||
|
|
||||||
void _checkType(
|
void _checkType(
|
||||||
ColumnType columnType,
|
DriftSqlType columnType,
|
||||||
bool columnIsNullable,
|
bool columnIsNullable,
|
||||||
UsedTypeConverter? typeConverter,
|
UsedTypeConverter? typeConverter,
|
||||||
DartType typeToCheck,
|
DartType typeToCheck,
|
||||||
|
@ -228,7 +228,7 @@ void _checkType(
|
||||||
// We don't get a Uint8List from the type provider unfortunately, but as it
|
// We don't get a Uint8List from the type provider unfortunately, but as it
|
||||||
// cannot be extended we can just check for that manually.
|
// cannot be extended we can just check for that manually.
|
||||||
final isAllowedUint8List = typeConverter == null &&
|
final isAllowedUint8List = typeConverter == null &&
|
||||||
columnType == ColumnType.blob &&
|
columnType == DriftSqlType.blob &&
|
||||||
typeToCheck is InterfaceType &&
|
typeToCheck is InterfaceType &&
|
||||||
typeToCheck.element.name == 'Uint8List' &&
|
typeToCheck.element.name == 'Uint8List' &&
|
||||||
typeToCheck.element.library.name == 'dart.typed_data';
|
typeToCheck.element.library.name == 'dart.typed_data';
|
||||||
|
@ -241,23 +241,23 @@ void _checkType(
|
||||||
}
|
}
|
||||||
|
|
||||||
extension on TypeProvider {
|
extension on TypeProvider {
|
||||||
DartType typeFor(ColumnType type) {
|
DartType typeFor(DriftSqlType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ColumnType.integer:
|
case DriftSqlType.int:
|
||||||
return intType;
|
return intType;
|
||||||
case ColumnType.bigInt:
|
case DriftSqlType.bigInt:
|
||||||
return intElement.library.getType('BigInt')!.instantiate(
|
return intElement.library.getType('BigInt')!.instantiate(
|
||||||
typeArguments: const [], nullabilitySuffix: NullabilitySuffix.none);
|
typeArguments: const [], nullabilitySuffix: NullabilitySuffix.none);
|
||||||
case ColumnType.text:
|
case DriftSqlType.string:
|
||||||
return stringType;
|
return stringType;
|
||||||
case ColumnType.boolean:
|
case DriftSqlType.bool:
|
||||||
return boolType;
|
return boolType;
|
||||||
case ColumnType.datetime:
|
case DriftSqlType.dateTime:
|
||||||
return intElement.library.getType('DateTime')!.instantiate(
|
return intElement.library.getType('DateTime')!.instantiate(
|
||||||
typeArguments: const [], nullabilitySuffix: NullabilitySuffix.none);
|
typeArguments: const [], nullabilitySuffix: NullabilitySuffix.none);
|
||||||
case ColumnType.blob:
|
case DriftSqlType.blob:
|
||||||
return listType(intType);
|
return listType(intType);
|
||||||
case ColumnType.real:
|
case DriftSqlType.double:
|
||||||
return doubleType;
|
return doubleType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,7 +245,7 @@ class CreateTableReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<UsedTypeConverter?> _readTypeConverter(
|
Future<UsedTypeConverter?> _readTypeConverter(
|
||||||
ColumnType sqlType, bool nullable, MappedBy mapper) async {
|
DriftSqlType sqlType, bool nullable, MappedBy mapper) async {
|
||||||
final code = mapper.mapper.dartCode;
|
final code = mapper.mapper.dartCode;
|
||||||
|
|
||||||
Expression expression;
|
Expression expression;
|
||||||
|
|
|
@ -49,52 +49,53 @@ class TypeMapper {
|
||||||
return engineTable;
|
return engineTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResolvedType resolveForColumnType(ColumnType type, {TypeHint? overrideHint}) {
|
ResolvedType resolveForColumnType(DriftSqlType type,
|
||||||
|
{TypeHint? overrideHint}) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ColumnType.integer:
|
case DriftSqlType.int:
|
||||||
return ResolvedType(type: BasicType.int, hint: overrideHint);
|
return ResolvedType(type: BasicType.int, hint: overrideHint);
|
||||||
case ColumnType.bigInt:
|
case DriftSqlType.bigInt:
|
||||||
return ResolvedType(
|
return ResolvedType(
|
||||||
type: BasicType.int, hint: overrideHint ?? const IsBigInt());
|
type: BasicType.int, hint: overrideHint ?? const IsBigInt());
|
||||||
case ColumnType.text:
|
case DriftSqlType.string:
|
||||||
return ResolvedType(type: BasicType.text, hint: overrideHint);
|
return ResolvedType(type: BasicType.text, hint: overrideHint);
|
||||||
case ColumnType.boolean:
|
case DriftSqlType.bool:
|
||||||
return ResolvedType(
|
return ResolvedType(
|
||||||
type: BasicType.int, hint: overrideHint ?? const IsBoolean());
|
type: BasicType.int, hint: overrideHint ?? const IsBoolean());
|
||||||
case ColumnType.datetime:
|
case DriftSqlType.dateTime:
|
||||||
return ResolvedType(
|
return ResolvedType(
|
||||||
type: BasicType.int, hint: overrideHint ?? const IsDateTime());
|
type: BasicType.int, hint: overrideHint ?? const IsDateTime());
|
||||||
case ColumnType.blob:
|
case DriftSqlType.blob:
|
||||||
return ResolvedType(type: BasicType.blob, hint: overrideHint);
|
return ResolvedType(type: BasicType.blob, hint: overrideHint);
|
||||||
case ColumnType.real:
|
case DriftSqlType.double:
|
||||||
return ResolvedType(type: BasicType.real, hint: overrideHint);
|
return ResolvedType(type: BasicType.real, hint: overrideHint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnType resolvedToMoor(ResolvedType? type) {
|
DriftSqlType resolvedToMoor(ResolvedType? type) {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
return ColumnType.text;
|
return DriftSqlType.string;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type.type) {
|
switch (type.type) {
|
||||||
case null:
|
case null:
|
||||||
case BasicType.nullType:
|
case BasicType.nullType:
|
||||||
return ColumnType.text;
|
return DriftSqlType.string;
|
||||||
case BasicType.int:
|
case BasicType.int:
|
||||||
if (type.hint is IsBoolean) {
|
if (type.hint is IsBoolean) {
|
||||||
return ColumnType.boolean;
|
return DriftSqlType.bool;
|
||||||
} else if (type.hint is IsDateTime) {
|
} else if (type.hint is IsDateTime) {
|
||||||
return ColumnType.datetime;
|
return DriftSqlType.dateTime;
|
||||||
} else if (type.hint is IsBigInt) {
|
} else if (type.hint is IsBigInt) {
|
||||||
return ColumnType.bigInt;
|
return DriftSqlType.bigInt;
|
||||||
}
|
}
|
||||||
return ColumnType.integer;
|
return DriftSqlType.int;
|
||||||
case BasicType.real:
|
case BasicType.real:
|
||||||
return ColumnType.real;
|
return DriftSqlType.double;
|
||||||
case BasicType.text:
|
case BasicType.text:
|
||||||
return ColumnType.text;
|
return DriftSqlType.string;
|
||||||
case BasicType.blob:
|
case BasicType.blob:
|
||||||
return ColumnType.blob;
|
return DriftSqlType.blob;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +280,7 @@ class TypeMapper {
|
||||||
final type = placeholder.when(
|
final type = placeholder.when(
|
||||||
isExpression: (e) {
|
isExpression: (e) {
|
||||||
final foundType = context.typeOf(e);
|
final foundType = context.typeOf(e);
|
||||||
ColumnType? columnType;
|
DriftSqlType? columnType;
|
||||||
if (foundType.type != null) {
|
if (foundType.type != null) {
|
||||||
columnType = resolvedToMoor(foundType.type);
|
columnType = resolvedToMoor(foundType.type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,7 @@ import 'package:analyzer/dart/element/element.dart';
|
||||||
import 'package:drift_dev/src/analyzer/options.dart';
|
import 'package:drift_dev/src/analyzer/options.dart';
|
||||||
import 'package:sqlparser/sqlparser.dart' show ReferenceAction;
|
import 'package:sqlparser/sqlparser.dart' show ReferenceAction;
|
||||||
|
|
||||||
import 'declarations/declaration.dart';
|
import 'model.dart';
|
||||||
import 'table.dart';
|
|
||||||
import 'types.dart';
|
|
||||||
import 'used_type_converter.dart';
|
|
||||||
|
|
||||||
/// The column types in sql.
|
|
||||||
enum ColumnType { integer, bigInt, text, boolean, datetime, blob, real }
|
|
||||||
|
|
||||||
/// Name of a column. Contains additional info on whether the name was chosen
|
/// Name of a column. Contains additional info on whether the name was chosen
|
||||||
/// implicitly (based on the dart getter name) or explicitly (via an named())
|
/// implicitly (based on the dart getter name) or explicitly (via an named())
|
||||||
|
@ -59,7 +53,7 @@ class DriftColumn implements HasDeclaration, HasType {
|
||||||
|
|
||||||
/// The sql type of this column
|
/// The sql type of this column
|
||||||
@override
|
@override
|
||||||
final ColumnType type;
|
final DriftSqlType type;
|
||||||
|
|
||||||
/// The name of this column, as chosen by the user
|
/// The name of this column, as chosen by the user
|
||||||
final ColumnName name;
|
final ColumnName name;
|
||||||
|
@ -112,20 +106,6 @@ class DriftColumn implements HasDeclaration, HasType {
|
||||||
/// Parent table
|
/// Parent table
|
||||||
DriftTable? table;
|
DriftTable? table;
|
||||||
|
|
||||||
/// The column type from the dsl library. For instance, if a table has
|
|
||||||
/// declared an `IntColumn`, the matching dsl column name would also be an
|
|
||||||
/// `IntColumn`.
|
|
||||||
@Deprecated('Use Column<innerColumnType()> instead')
|
|
||||||
String get dslColumnTypeName => const {
|
|
||||||
ColumnType.boolean: 'BoolColumn',
|
|
||||||
ColumnType.text: 'TextColumn',
|
|
||||||
ColumnType.integer: 'IntColumn',
|
|
||||||
ColumnType.bigInt: 'BigIntColumn',
|
|
||||||
ColumnType.datetime: 'DateTimeColumn',
|
|
||||||
ColumnType.blob: 'BlobColumn',
|
|
||||||
ColumnType.real: 'RealColumn',
|
|
||||||
}[type]!;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get isArray => false;
|
bool get isArray => false;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:recase/recase.dart';
|
import 'package:recase/recase.dart';
|
||||||
|
|
||||||
|
export 'package:drift/drift.dart' show DriftSqlType;
|
||||||
export 'base_entity.dart';
|
export 'base_entity.dart';
|
||||||
export 'column.dart';
|
export 'column.dart';
|
||||||
export 'database.dart';
|
export 'database.dart';
|
||||||
|
|
|
@ -99,7 +99,7 @@ abstract class SqlQuery {
|
||||||
/// The placeholders in this query which are bound and converted to sql at
|
/// The placeholders in this query which are bound and converted to sql at
|
||||||
/// runtime. For instance, in `SELECT * FROM tbl WHERE $expr`, the `expr` is
|
/// runtime. For instance, in `SELECT * FROM tbl WHERE $expr`, the `expr` is
|
||||||
/// going to be a [FoundDartPlaceholder] with the type
|
/// going to be a [FoundDartPlaceholder] with the type
|
||||||
/// [ExpressionDartPlaceholderType] and [ColumnType.boolean]. We will
|
/// [ExpressionDartPlaceholderType] and [DriftSqlType.bool]. We will
|
||||||
/// generate a method which has a `Expression<bool, BoolType> expr` parameter.
|
/// generate a method which has a `Expression<bool, BoolType> expr` parameter.
|
||||||
late List<FoundDartPlaceholder> placeholders;
|
late List<FoundDartPlaceholder> placeholders;
|
||||||
|
|
||||||
|
@ -453,7 +453,7 @@ class MatchingMoorTable {
|
||||||
class ResultColumn implements HasType {
|
class ResultColumn implements HasType {
|
||||||
final String name;
|
final String name;
|
||||||
@override
|
@override
|
||||||
final ColumnType type;
|
final DriftSqlType type;
|
||||||
@override
|
@override
|
||||||
final bool nullable;
|
final bool nullable;
|
||||||
|
|
||||||
|
@ -611,7 +611,7 @@ class FoundVariable extends FoundElement implements HasType {
|
||||||
|
|
||||||
/// The (inferred) type for this variable.
|
/// The (inferred) type for this variable.
|
||||||
@override
|
@override
|
||||||
final ColumnType type;
|
final DriftSqlType type;
|
||||||
|
|
||||||
/// The type converter to apply before writing this value.
|
/// The type converter to apply before writing this value.
|
||||||
@override
|
@override
|
||||||
|
@ -721,7 +721,7 @@ class SimpleDartPlaceholderType extends DartPlaceholderType {
|
||||||
|
|
||||||
class ExpressionDartPlaceholderType extends DartPlaceholderType {
|
class ExpressionDartPlaceholderType extends DartPlaceholderType {
|
||||||
/// The sql type of this expression.
|
/// The sql type of this expression.
|
||||||
final ColumnType? columnType;
|
final DriftSqlType? columnType;
|
||||||
final Expression? defaultValue;
|
final Expression? defaultValue;
|
||||||
|
|
||||||
ExpressionDartPlaceholderType(this.columnType, this.defaultValue);
|
ExpressionDartPlaceholderType(this.columnType, this.defaultValue);
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
import 'package:analyzer/dart/element/element.dart';
|
import 'package:analyzer/dart/element/element.dart';
|
||||||
import 'package:drift/drift.dart' show UpdateKind;
|
import 'package:drift/drift.dart' show UpdateKind;
|
||||||
import 'package:drift_dev/src/analyzer/options.dart';
|
import 'package:drift_dev/src/analyzer/options.dart';
|
||||||
import 'package:drift_dev/src/model/used_type_converter.dart';
|
|
||||||
import 'package:drift_dev/writer.dart';
|
import 'package:drift_dev/writer.dart';
|
||||||
import 'package:recase/recase.dart';
|
import 'package:recase/recase.dart';
|
||||||
import 'package:sqlparser/sqlparser.dart';
|
import 'package:sqlparser/sqlparser.dart';
|
||||||
|
|
||||||
import 'base_entity.dart';
|
import 'model.dart';
|
||||||
import 'column.dart';
|
|
||||||
import 'declarations/declaration.dart';
|
|
||||||
|
|
||||||
/// A parsed table, declared in code by extending `Table` and referencing that
|
/// A parsed table, declared in code by extending `Table` and referencing that
|
||||||
/// table in `@UseMoor` or `@UseDao`.
|
/// table in `@UseMoor` or `@UseDao`.
|
||||||
|
@ -194,7 +191,7 @@ class DriftTable extends DriftEntityWithResultSet {
|
||||||
final isWithoutRowId = overrideWithoutRowId ?? false;
|
final isWithoutRowId = overrideWithoutRowId ?? false;
|
||||||
final fullPk = fullPrimaryKey;
|
final fullPk = fullPrimaryKey;
|
||||||
final isAliasForRowId = !isWithoutRowId &&
|
final isAliasForRowId = !isWithoutRowId &&
|
||||||
column.type == ColumnType.integer &&
|
column.type == DriftSqlType.int &&
|
||||||
fullPk.length == 1 &&
|
fullPk.length == 1 &&
|
||||||
fullPk.single == column;
|
fullPk.single == column;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import 'package:analyzer/dart/element/nullability_suffix.dart';
|
import 'package:analyzer/dart/element/nullability_suffix.dart';
|
||||||
import 'package:analyzer/dart/element/type.dart';
|
import 'package:analyzer/dart/element/type.dart';
|
||||||
import 'package:drift/drift.dart';
|
|
||||||
import 'package:drift_dev/src/model/model.dart';
|
import 'package:drift_dev/src/model/model.dart';
|
||||||
import 'package:drift_dev/src/utils/type_utils.dart';
|
import 'package:drift_dev/src/utils/type_utils.dart';
|
||||||
import 'package:drift_dev/writer.dart';
|
import 'package:drift_dev/writer.dart';
|
||||||
|
@ -19,7 +18,7 @@ abstract class HasType {
|
||||||
bool get isArray;
|
bool get isArray;
|
||||||
|
|
||||||
/// The associated sql type.
|
/// The associated sql type.
|
||||||
ColumnType get type;
|
DriftSqlType get type;
|
||||||
|
|
||||||
/// The applied type converter, or null.
|
/// The applied type converter, or null.
|
||||||
UsedTypeConverter? get typeConverter;
|
UsedTypeConverter? get typeConverter;
|
||||||
|
@ -99,25 +98,25 @@ extension OperationOnTypes on HasType {
|
||||||
String code;
|
String code;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ColumnType.integer:
|
case DriftSqlType.int:
|
||||||
code = 'int';
|
code = 'int';
|
||||||
break;
|
break;
|
||||||
case ColumnType.bigInt:
|
case DriftSqlType.bigInt:
|
||||||
code = 'BigInt';
|
code = 'BigInt';
|
||||||
break;
|
break;
|
||||||
case ColumnType.text:
|
case DriftSqlType.string:
|
||||||
code = 'String';
|
code = 'String';
|
||||||
break;
|
break;
|
||||||
case ColumnType.boolean:
|
case DriftSqlType.bool:
|
||||||
code = 'bool';
|
code = 'bool';
|
||||||
break;
|
break;
|
||||||
case ColumnType.datetime:
|
case DriftSqlType.dateTime:
|
||||||
code = 'DateTime';
|
code = 'DateTime';
|
||||||
break;
|
break;
|
||||||
case ColumnType.blob:
|
case DriftSqlType.blob:
|
||||||
code = 'Uint8List';
|
code = 'Uint8List';
|
||||||
break;
|
break;
|
||||||
case ColumnType.real:
|
case DriftSqlType.double:
|
||||||
code = 'double';
|
code = 'double';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -138,46 +137,26 @@ extension OperationOnTypes on HasType {
|
||||||
|
|
||||||
return variableTypeCode();
|
return variableTypeCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
DriftSqlType sqlType() {
|
|
||||||
// todo: Just replace ColumnType with DriftSqlType now?
|
|
||||||
switch (type) {
|
|
||||||
case ColumnType.integer:
|
|
||||||
return DriftSqlType.int;
|
|
||||||
case ColumnType.bigInt:
|
|
||||||
return DriftSqlType.bigInt;
|
|
||||||
case ColumnType.boolean:
|
|
||||||
return DriftSqlType.bool;
|
|
||||||
case ColumnType.datetime:
|
|
||||||
return DriftSqlType.dateTime;
|
|
||||||
case ColumnType.text:
|
|
||||||
return DriftSqlType.string;
|
|
||||||
case ColumnType.blob:
|
|
||||||
return DriftSqlType.blob;
|
|
||||||
case ColumnType.real:
|
|
||||||
return DriftSqlType.double;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Map<ColumnType, String> dartTypeNames = {
|
const Map<DriftSqlType, String> dartTypeNames = {
|
||||||
ColumnType.boolean: 'bool',
|
DriftSqlType.bool: 'bool',
|
||||||
ColumnType.text: 'String',
|
DriftSqlType.string: 'String',
|
||||||
ColumnType.integer: 'int',
|
DriftSqlType.int: 'int',
|
||||||
ColumnType.bigInt: 'BigInt',
|
DriftSqlType.bigInt: 'BigInt',
|
||||||
ColumnType.datetime: 'DateTime',
|
DriftSqlType.dateTime: 'DateTime',
|
||||||
ColumnType.blob: 'Uint8List',
|
DriftSqlType.blob: 'Uint8List',
|
||||||
ColumnType.real: 'double',
|
DriftSqlType.double: 'double',
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Maps from a column type to code that can be used to create a variable of the
|
/// Maps from a column type to code that can be used to create a variable of the
|
||||||
/// respective type.
|
/// respective type.
|
||||||
const Map<ColumnType, String> createVariable = {
|
const Map<DriftSqlType, String> createVariable = {
|
||||||
ColumnType.boolean: 'Variable.withBool',
|
DriftSqlType.bool: 'Variable.withBool',
|
||||||
ColumnType.text: 'Variable.withString',
|
DriftSqlType.string: 'Variable.withString',
|
||||||
ColumnType.integer: 'Variable.withInt',
|
DriftSqlType.int: 'Variable.withInt',
|
||||||
ColumnType.bigInt: 'Variable.withBigInt',
|
DriftSqlType.bigInt: 'Variable.withBigInt',
|
||||||
ColumnType.datetime: 'Variable.withDateTime',
|
DriftSqlType.dateTime: 'Variable.withDateTime',
|
||||||
ColumnType.blob: 'Variable.withBlob',
|
DriftSqlType.blob: 'Variable.withBlob',
|
||||||
ColumnType.real: 'Variable.withReal',
|
DriftSqlType.double: 'Variable.withReal',
|
||||||
};
|
};
|
||||||
|
|
|
@ -118,7 +118,7 @@ class SchemaWriter {
|
||||||
return {
|
return {
|
||||||
'name': column.name.name,
|
'name': column.name.name,
|
||||||
'getter_name': column.dartGetterName,
|
'getter_name': column.dartGetterName,
|
||||||
'moor_type': column.type.toString(),
|
'moor_type': column.type.toSerializedString(),
|
||||||
'nullable': column.nullable,
|
'nullable': column.nullable,
|
||||||
'customConstraints': column.customConstraints,
|
'customConstraints': column.customConstraints,
|
||||||
if (constraints.isNotEmpty && column.customConstraints == null)
|
if (constraints.isNotEmpty && column.customConstraints == null)
|
||||||
|
@ -316,8 +316,8 @@ class SchemaReader {
|
||||||
|
|
||||||
DriftColumn _readColumn(Map<String, dynamic> data) {
|
DriftColumn _readColumn(Map<String, dynamic> data) {
|
||||||
final name = data['name'] as String;
|
final name = data['name'] as String;
|
||||||
final moorType = ColumnType.values
|
final columnType =
|
||||||
.firstWhere((type) => type.toString() == data['moor_type']);
|
_SerializeSqlType.deserialize(data['moor_type'] as String);
|
||||||
final nullable = data['nullable'] as bool;
|
final nullable = data['nullable'] as bool;
|
||||||
final customConstraints = data['customConstraints'] as String?;
|
final customConstraints = data['customConstraints'] as String?;
|
||||||
final defaultConstraints = data['defaultConstraints'] as String?;
|
final defaultConstraints = data['defaultConstraints'] as String?;
|
||||||
|
@ -334,7 +334,7 @@ class SchemaReader {
|
||||||
return DriftColumn(
|
return DriftColumn(
|
||||||
name: ColumnName.explicitly(name),
|
name: ColumnName.explicitly(name),
|
||||||
dartGetterName: getterName ?? ReCase(name).camelCase,
|
dartGetterName: getterName ?? ReCase(name).camelCase,
|
||||||
type: moorType,
|
type: columnType,
|
||||||
nullable: nullable,
|
nullable: nullable,
|
||||||
defaultArgument: data['default_dart'] as String?,
|
defaultArgument: data['default_dart'] as String?,
|
||||||
customConstraints: customConstraints,
|
customConstraints: customConstraints,
|
||||||
|
@ -357,3 +357,49 @@ class SchemaReader {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// There used to be another enum to represent columns that has since been
|
||||||
|
// replaced with DriftSqlType. We still need to reflect the old description in
|
||||||
|
// the serialized format.
|
||||||
|
extension _SerializeSqlType on DriftSqlType {
|
||||||
|
static DriftSqlType deserialize(String description) {
|
||||||
|
switch (description) {
|
||||||
|
case 'ColumnType.boolean':
|
||||||
|
return DriftSqlType.bool;
|
||||||
|
case 'ColumnType.text':
|
||||||
|
return DriftSqlType.string;
|
||||||
|
case 'ColumnType.bigInt':
|
||||||
|
return DriftSqlType.bigInt;
|
||||||
|
case 'ColumnType.integer':
|
||||||
|
return DriftSqlType.int;
|
||||||
|
case 'ColumnType.datetime':
|
||||||
|
return DriftSqlType.dateTime;
|
||||||
|
case 'ColumnType.blob':
|
||||||
|
return DriftSqlType.blob;
|
||||||
|
case 'ColumnType.real':
|
||||||
|
return DriftSqlType.double;
|
||||||
|
default:
|
||||||
|
throw ArgumentError.value(
|
||||||
|
description, 'description', 'Not a known column type');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String toSerializedString() {
|
||||||
|
switch (this) {
|
||||||
|
case DriftSqlType.bool:
|
||||||
|
return 'ColumnType.boolean';
|
||||||
|
case DriftSqlType.string:
|
||||||
|
return 'ColumnType.text';
|
||||||
|
case DriftSqlType.bigInt:
|
||||||
|
return 'ColumnType.bigInt';
|
||||||
|
case DriftSqlType.int:
|
||||||
|
return 'ColumnType.integer';
|
||||||
|
case DriftSqlType.dateTime:
|
||||||
|
return 'ColumnType.datetime';
|
||||||
|
case DriftSqlType.blob:
|
||||||
|
return 'ColumnType.blob';
|
||||||
|
case DriftSqlType.double:
|
||||||
|
return 'ColumnType.real';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -349,7 +349,7 @@ class RowMappingWriter {
|
||||||
final columnName = column.name.name;
|
final columnName = column.name.name;
|
||||||
final rawData = "data['\${effectivePrefix}$columnName']";
|
final rawData = "data['\${effectivePrefix}$columnName']";
|
||||||
|
|
||||||
final sqlType = column.sqlType();
|
final sqlType = column.type.toString();
|
||||||
var loadType = '$databaseGetter.options.types.read($sqlType, $rawData)';
|
var loadType = '$databaseGetter.options.types.read($sqlType, $rawData)';
|
||||||
|
|
||||||
if (!column.nullable) {
|
if (!column.nullable) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ abstract class TableOrViewWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
additionalParams['type'] = column.sqlType().toString();
|
additionalParams['type'] = column.type.toString();
|
||||||
|
|
||||||
if (tableOrView is DriftTable) {
|
if (tableOrView is DriftTable) {
|
||||||
additionalParams['requiredDuringInsert'] = (tableOrView as DriftTable)
|
additionalParams['requiredDuringInsert'] = (tableOrView as DriftTable)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:drift/sqlite_keywords.dart';
|
import 'package:drift/sqlite_keywords.dart';
|
||||||
import 'package:sqlparser/sqlparser.dart';
|
import 'package:sqlparser/sqlparser.dart';
|
||||||
|
|
||||||
import '../../model/column.dart';
|
import '../../model/model.dart';
|
||||||
|
|
||||||
String defaultConstraints(DriftColumn column) {
|
String defaultConstraints(DriftColumn column) {
|
||||||
final defaultConstraints = <String>[];
|
final defaultConstraints = <String>[];
|
||||||
|
@ -54,7 +54,7 @@ String defaultConstraints(DriftColumn column) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (column.type == ColumnType.boolean) {
|
if (column.type == DriftSqlType.bool) {
|
||||||
final name = escapeIfNeeded(column.name.name);
|
final name = escapeIfNeeded(column.name.name);
|
||||||
defaultConstraints.add('CHECK ($name IN (0, 1))');
|
defaultConstraints.add('CHECK ($name IN (0, 1))');
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ WITH alias("first", second) AS (SELECT * FROM foo) SELECT * FROM alias;
|
||||||
expect(resultSet.singleColumn, isTrue);
|
expect(resultSet.singleColumn, isTrue);
|
||||||
expect(resultSet.needsOwnClass, isFalse);
|
expect(resultSet.needsOwnClass, isFalse);
|
||||||
expect(resultSet.columns.map(resultSet.dartNameFor), ['x']);
|
expect(resultSet.columns.map(resultSet.dartNameFor), ['x']);
|
||||||
expect(resultSet.columns.map((c) => c.type), [ColumnType.integer]);
|
expect(resultSet.columns.map((c) => c.type), [DriftSqlType.int]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('finds the underlying table when aliased through CFE', () {
|
test('finds the underlying table when aliased through CFE', () {
|
||||||
|
|
|
@ -29,7 +29,7 @@ void main() {
|
||||||
|
|
||||||
state.close();
|
state.close();
|
||||||
|
|
||||||
expect(column.type, ColumnType.integer);
|
expect(column.type, DriftSqlType.int);
|
||||||
expect(
|
expect(
|
||||||
column.typeConverter,
|
column.typeConverter,
|
||||||
isA<UsedTypeConverter>()
|
isA<UsedTypeConverter>()
|
||||||
|
|
|
@ -111,7 +111,7 @@ wrongArgs: SELECT sin(oid, foo) FROM numbers;
|
||||||
expect(
|
expect(
|
||||||
queryInA.resultSet.columns.single,
|
queryInA.resultSet.columns.single,
|
||||||
const TypeMatcher<ResultColumn>()
|
const TypeMatcher<ResultColumn>()
|
||||||
.having((e) => e.type, 'type', ColumnType.real),
|
.having((e) => e.type, 'type', DriftSqlType.double),
|
||||||
);
|
);
|
||||||
|
|
||||||
final fileB = await state.analyze('package:foo/b.moor');
|
final fileB = await state.analyze('package:foo/b.moor');
|
||||||
|
|
|
@ -114,7 +114,7 @@ class ProgrammingLanguages extends Table {
|
||||||
|
|
||||||
final librariesQuery = database.queries!
|
final librariesQuery = database.queries!
|
||||||
.singleWhere((q) => q.name == 'findLibraries') as SqlSelectQuery;
|
.singleWhere((q) => q.name == 'findLibraries') as SqlSelectQuery;
|
||||||
expect(librariesQuery.variables.single.type, ColumnType.text);
|
expect(librariesQuery.variables.single.type, DriftSqlType.string);
|
||||||
expect(librariesQuery.declaredInMoorFile, isTrue);
|
expect(librariesQuery.declaredInMoorFile, isTrue);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,9 +49,9 @@ totalDurationByArtist:
|
||||||
expect(
|
expect(
|
||||||
totalDurationByArtist,
|
totalDurationByArtist,
|
||||||
returnsColumns({
|
returnsColumns({
|
||||||
'id': ColumnType.integer,
|
'id': DriftSqlType.int,
|
||||||
'name': ColumnType.text,
|
'name': DriftSqlType.string,
|
||||||
'duration': ColumnType.integer,
|
'duration': DriftSqlType.int,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -52,9 +52,9 @@ SELECT * FROM total_duration_by_artist_view;
|
||||||
expect(
|
expect(
|
||||||
totalDurationByArtist,
|
totalDurationByArtist,
|
||||||
returnsColumns({
|
returnsColumns({
|
||||||
'id': ColumnType.integer,
|
'id': DriftSqlType.int,
|
||||||
'name': ColumnType.text,
|
'name': DriftSqlType.string,
|
||||||
'duration': ColumnType.integer,
|
'duration': DriftSqlType.int,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -26,7 +26,7 @@ bar(?1 AS TEXT, :foo AS BOOLEAN): SELECT ?, :foo;
|
||||||
expect(resultSet.matchingTable, isNull);
|
expect(resultSet.matchingTable, isNull);
|
||||||
expect(resultSet.columns.map((c) => c.name), ['?', ':foo']);
|
expect(resultSet.columns.map((c) => c.name), ['?', ':foo']);
|
||||||
expect(resultSet.columns.map((c) => c.type),
|
expect(resultSet.columns.map((c) => c.type),
|
||||||
[ColumnType.text, ColumnType.boolean]);
|
[DriftSqlType.string, DriftSqlType.bool]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('reads REQUIRED syntax', () async {
|
test('reads REQUIRED syntax', () async {
|
||||||
|
|
|
@ -52,7 +52,7 @@ class TestState {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matchers
|
// Matchers
|
||||||
Matcher returnsColumns(Map<String, ColumnType> columns) {
|
Matcher returnsColumns(Map<String, DriftSqlType> columns) {
|
||||||
return _HasInferredColumnTypes(columns);
|
return _HasInferredColumnTypes(columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue