chore: Rearrange methods.

This commit is contained in:
yohom 2019-04-23 15:05:53 +08:00
parent b442fe9d34
commit 0f3895b27b
1 changed files with 40 additions and 40 deletions

View File

@ -35,46 +35,6 @@ class InsertStatement<DataClass> {
});
}
GenerationContext _createContext(DataClass entry, bool replace) {
final map = table.entityToSql(entry)
..removeWhere((_, value) => value == null);
final ctx = GenerationContext(database);
ctx.buffer
..write('INSERT ')
..write(replace ? 'OR REPLACE ' : '')
..write('INTO ')
..write(table.$tableName)
..write(' (')
..write(map.keys.join(', '))
..write(') ')
..write('VALUES (');
var first = true;
for (var variable in map.values) {
if (!first) {
ctx.buffer.write(', ');
}
first = false;
variable.writeInto(ctx);
}
ctx.buffer.write(')');
return ctx;
}
void _validateIntegrity(DataClass d) {
if (d == null) {
throw InvalidDataException(
'Cannot writee null row into ${table.$tableName}');
}
if (!table.validateIntegrity(d, true)) {
throw InvalidDataException(
'Invalid data: $d cannot be written into ${table.$tableName}');
}
}
/// Inserts all [rows] into the table.
///
/// All fields in a row that don't have a default value or auto-increment
@ -118,4 +78,44 @@ class InsertStatement<DataClass> {
Future<void> insertOrReplace(DataClass entity) async {
return await insert(entity, orReplace: true);
}
GenerationContext _createContext(DataClass entry, bool replace) {
final map = table.entityToSql(entry)
..removeWhere((_, value) => value == null);
final ctx = GenerationContext(database);
ctx.buffer
..write('INSERT ')
..write(replace ? 'OR REPLACE ' : '')
..write('INTO ')
..write(table.$tableName)
..write(' (')
..write(map.keys.join(', '))
..write(') ')
..write('VALUES (');
var first = true;
for (var variable in map.values) {
if (!first) {
ctx.buffer.write(', ');
}
first = false;
variable.writeInto(ctx);
}
ctx.buffer.write(')');
return ctx;
}
void _validateIntegrity(DataClass d) {
if (d == null) {
throw InvalidDataException(
'Cannot writee null row into ${table.$tableName}');
}
if (!table.validateIntegrity(d, true)) {
throw InvalidDataException(
'Invalid data: $d cannot be written into ${table.$tableName}');
}
}
}