mirror of https://github.com/AMT-Cheif/drift.git
Implement deletion api
This commit is contained in:
parent
3b815839b6
commit
e66fb0702c
|
@ -4,7 +4,7 @@ part 'example.g.dart';
|
|||
|
||||
class Products extends Table {
|
||||
|
||||
IntColumn get id => integer().named("products_id").autoIncrement()();
|
||||
IntColumn get id => integer().named('products_id').autoIncrement()();
|
||||
TextColumn get name => text()();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:sally/sally.dart';
|
||||
import 'package:sally/src/runtime/executor/type_system.dart';
|
||||
import 'package:sally/src/runtime/statements/delete.dart';
|
||||
import 'package:sally/src/runtime/statements/select.dart';
|
||||
|
||||
/// A base class for all generated databases.
|
||||
|
@ -13,6 +14,9 @@ abstract class GeneratedDatabase {
|
|||
TableInfo<Table, ReturnType> table) {
|
||||
return SelectStatement<Table, ReturnType>(this, table);
|
||||
}
|
||||
|
||||
DeleteStatement<Table> delete<Table>(TableInfo<Table, dynamic> table) =>
|
||||
DeleteStatement<Table>(this, table);
|
||||
}
|
||||
|
||||
abstract class QueryExecutor {
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
import 'package:sally/src/runtime/components/component.dart';
|
||||
import 'package:sally/src/runtime/executor/executor.dart';
|
||||
import 'package:sally/src/runtime/statements/query.dart';
|
||||
import 'package:sally/src/runtime/structure/table_info.dart';
|
||||
|
||||
class DeleteStatement<UserTable> extends Query<UserTable> {
|
||||
DeleteStatement(
|
||||
GeneratedDatabase database, TableInfo<UserTable, dynamic> table)
|
||||
: super(database, table);
|
||||
|
||||
@override
|
||||
void writeStartPart(GenerationContext ctx) {
|
||||
ctx.buffer.write('DELETE FROM ${table.$tableName}');
|
||||
}
|
||||
|
||||
Future<int> go() async {
|
||||
final ctx = constructQuery();
|
||||
|
||||
return await ctx.database.executor.runDelete(ctx.sql, ctx.boundVariables);
|
||||
}
|
||||
}
|
|
@ -54,12 +54,12 @@ void main() {
|
|||
});
|
||||
});
|
||||
|
||||
/*
|
||||
group("Generates DELETE statements", () {
|
||||
test("without any constraints", () {
|
||||
users.delete().performDelete();
|
||||
|
||||
verify(executor.executeDelete("DELETE FROM users ", argThat(isEmpty)));
|
||||
group('Generates DELETE statements', () {
|
||||
test('without any constraints', () {
|
||||
db.delete(db.users).go();
|
||||
|
||||
verify(executor.runDelete('DELETE FROM users;', argThat(isEmpty)));
|
||||
});
|
||||
});*/
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue