Skip to content

Commit

Permalink
Use on conflict in kavita insert
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha committed Nov 11, 2024
1 parent 94a1685 commit 63f2013
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/src/repository/kavita.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ class KavitaRepository {
..addNamedInsert("auth_token")
..addNamedInsert("api_key")
..addNamedInsert("kavita_config_id")
..onConflict('kavita_user_configs_user_id_unique', {
'auth_token': '@auth_token',
'api_key': '@api_key',
}, [
'${KavitaUserConfig.tableName}.user_id = @user_id',
'${KavitaUserConfig.tableName}.kavita_config_id = @kavita_config_id'
])
..addReturning('id');

final result = await _database.executeQuery(query, parameters: {
Expand Down
3 changes: 2 additions & 1 deletion test/query_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ void main() {
..onConflict("test_constraint", {'model': "@model"}, ['id = @id'])
..addReturning("id");

expect(query.build().asString(), "INSERT INTO test (name,model) VALUES (moron,@model) ON CONFLICT ON CONSTRAINT test_constraint DO UPDATE SET model = @model WHERE id = @id RETURNING id;");
expect(query.build().asString(),
"INSERT INTO test (name,model) VALUES (moron,@model) ON CONFLICT ON CONSTRAINT test_constraint DO UPDATE SET model = @model WHERE id = @id RETURNING id;");
});
});

Expand Down

0 comments on commit 63f2013

Please sign in to comment.