upsert_donau_keys.c (2317B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2024 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file src/backenddb/upsert_donau_keys.c 18 * @brief Implementation of the upsert_donau_keys function for Postgres 19 * @author Bohdan Potuzhnyi 20 * @author Vlada Svirsh 21 */ 22 #include "platform.h" 23 #include <taler/taler_pq_lib.h> 24 #include "donau/donau_service.h" 25 #include "merchant-database/upsert_donau_keys.h" 26 #include "helper.h" 27 28 29 enum GNUNET_DB_QueryStatus 30 TALER_MERCHANTDB_upsert_donau_keys ( 31 struct TALER_MERCHANTDB_PostgresContext *pg, 32 const struct DONAU_Keys *keys, 33 struct GNUNET_TIME_Absolute first_retry) 34 { 35 enum GNUNET_DB_QueryStatus qs; 36 json_t *jkeys = DONAU_keys_to_json (keys); 37 38 if (NULL == jkeys) 39 return GNUNET_DB_STATUS_HARD_ERROR; 40 41 { 42 struct GNUNET_PQ_QueryParam params[] = { 43 TALER_PQ_query_param_json (jkeys), 44 GNUNET_PQ_query_param_absolute_time (&first_retry), 45 GNUNET_PQ_query_param_string (keys->donau_url), 46 GNUNET_PQ_query_param_end 47 }; 48 49 check_connection (pg); 50 PREPARE (pg, 51 "insert_donau_keys", 52 "INSERT INTO merchant.merchant_donau_keys" 53 " (keys_json" 54 " ,first_retry" 55 " ,donau_url" 56 " ) VALUES (" 57 " $1::TEXT::JSONB" 58 " ,$2" 59 " ,$3)" 60 " ON CONFLICT (donau_url)" 61 " DO UPDATE SET" 62 " keys_json=EXCLUDED.keys_json," 63 " first_retry=EXCLUDED.first_retry;"); 64 qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, 65 "insert_donau_keys", 66 params); 67 } 68 69 json_decref (jkeys); 70 return qs; 71 }