Skip to content

Instantly share code, notes, and snippets.

@zs-dima
Last active May 31, 2021 12:42
Show Gist options
  • Save zs-dima/2d81b7151690b0d167baeeb898a93c2e to your computer and use it in GitHub Desktop.
Save zs-dima/2d81b7151690b0d167baeeb898a93c2e to your computer and use it in GitHub Desktop.
Future<void> save<T>(String type, int id, String field, T? value) async {
if (value == null) {
await customStatement(
'DELETE FROM cache'
' WHERE id_type=\'$type\''
' AND id_object=$id'
' AND field=\'$field\'',
);
} else {
String v;
switch (value.runtimeType){
case String: v = '\'$value\''; break;
default: v = '$value';
}
await customStatement(
'INSERT INTO cache (id_type,id_object,field,value) VALUES '
'(\'$type\',$id,\'$field\',$v) '
'ON CONFLICT DO UPDATE SET '
'value=\'$value\'',
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment