mirror of https://github.com/AMT-Cheif/drift.git
chore: Rearrange methods.
This commit is contained in:
parent
b442fe9d34
commit
0f3895b27b
|
@ -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.
|
/// Inserts all [rows] into the table.
|
||||||
///
|
///
|
||||||
/// All fields in a row that don't have a default value or auto-increment
|
/// 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 {
|
Future<void> insertOrReplace(DataClass entity) async {
|
||||||
return await insert(entity, orReplace: true);
|
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}');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue