mirror of https://github.com/AMT-Cheif/drift.git
Finish custom constraints implementation
This commit is contained in:
parent
f3a0f5f230
commit
9490cd22fe
|
@ -27,8 +27,15 @@ abstract class GeneratedColumn<T, S extends SqlType<T>> extends Column<T, S> {
|
||||||
/// [here](https://www.sqlite.org/syntax/column-def.html), into the given
|
/// [here](https://www.sqlite.org/syntax/column-def.html), into the given
|
||||||
/// buffer.
|
/// buffer.
|
||||||
void writeColumnDefinition(StringBuffer into) {
|
void writeColumnDefinition(StringBuffer into) {
|
||||||
into..write('${$name} $typeName ')..write($nullable ? 'NULL' : 'NOT NULL');
|
into.write('${$name} $typeName ');
|
||||||
writeCustomConstraints(into);
|
|
||||||
|
if ($customConstraints == null) {
|
||||||
|
into.write($nullable ? 'NULL' : 'NOT NULL');
|
||||||
|
// these custom constraints refer to builtin constraints from moor
|
||||||
|
writeCustomConstraints(into);
|
||||||
|
} else {
|
||||||
|
into.write($customConstraints);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@visibleForOverriding
|
@visibleForOverriding
|
||||||
|
|
|
@ -26,7 +26,8 @@ class Users extends Table {
|
||||||
@DataClassName('Category')
|
@DataClassName('Category')
|
||||||
class Categories extends Table {
|
class Categories extends Table {
|
||||||
IntColumn get id => integer().autoIncrement()();
|
IntColumn get id => integer().autoIncrement()();
|
||||||
TextColumn get description => text().named('desc')();
|
TextColumn get description =>
|
||||||
|
text().named('desc').customConstraint('NOT NULL UNIQUE')();
|
||||||
}
|
}
|
||||||
|
|
||||||
class SharedTodos extends Table {
|
class SharedTodos extends Table {
|
||||||
|
|
|
@ -217,10 +217,9 @@ class $CategoriesTable extends Categories
|
||||||
_id ??= GeneratedIntColumn('id', false, hasAutoIncrement: true);
|
_id ??= GeneratedIntColumn('id', false, hasAutoIncrement: true);
|
||||||
GeneratedTextColumn _description;
|
GeneratedTextColumn _description;
|
||||||
@override
|
@override
|
||||||
GeneratedTextColumn get description => _description ??= GeneratedTextColumn(
|
GeneratedTextColumn get description =>
|
||||||
'`desc`',
|
_description ??= GeneratedTextColumn('`desc`', false,
|
||||||
false,
|
$customConstraints: 'NOT NULL UNIQUE');
|
||||||
);
|
|
||||||
@override
|
@override
|
||||||
List<GeneratedColumn> get $columns => [id, description];
|
List<GeneratedColumn> get $columns => [id, description];
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -24,7 +24,7 @@ void main() {
|
||||||
'category INTEGER NULL);'));
|
'category INTEGER NULL);'));
|
||||||
|
|
||||||
verify(mockQueryExecutor.call('CREATE TABLE IF NOT EXISTS categories '
|
verify(mockQueryExecutor.call('CREATE TABLE IF NOT EXISTS categories '
|
||||||
'(id INTEGER PRIMARY KEY AUTOINCREMENT, `desc` VARCHAR NOT NULL);'));
|
'(id INTEGER PRIMARY KEY AUTOINCREMENT, `desc` VARCHAR NOT NULL UNIQUE);'));
|
||||||
|
|
||||||
verify(mockQueryExecutor.call('CREATE TABLE IF NOT EXISTS users '
|
verify(mockQueryExecutor.call('CREATE TABLE IF NOT EXISTS users '
|
||||||
'(id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR NOT NULL, '
|
'(id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR NOT NULL, '
|
||||||
|
|
|
@ -98,6 +98,11 @@ class TableWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (column.customConstraints != null) {
|
||||||
|
// todo should we worry about escaping this string?
|
||||||
|
additionalParams['\$customConstraints'] = "'${column.customConstraints}'";
|
||||||
|
}
|
||||||
|
|
||||||
// GeneratedIntColumn('sql_name', isNullable, additionalField: true)
|
// GeneratedIntColumn('sql_name', isNullable, additionalField: true)
|
||||||
final expressionBuffer = StringBuffer()
|
final expressionBuffer = StringBuffer()
|
||||||
..write(column.implColumnTypeName)
|
..write(column.implColumnTypeName)
|
||||||
|
|
Loading…
Reference in New Issue