@@ -28,15 +28,31 @@ impl Record for Receipt {
28
28
{
29
29
let db_item = ReceiptDbItem :: try_from ( packet) ?;
30
30
let record = sqlx:: query_as :: < _ , ReceiptDbItem > (
31
- "INSERT INTO receipts (
32
- subject, value, block_height, tx_id, tx_index, receipt_index,
33
- receipt_type, from_contract_id, to_contract_id, to_address,
34
- asset_id, contract_id, sub_id, sender_address, recipient_address
31
+ "WITH upsert AS (
32
+ INSERT INTO receipts (
33
+ subject, value, block_height, tx_id, tx_index, receipt_index,
34
+ receipt_type, from_contract_id, to_contract_id, to_address,
35
+ asset_id, contract_id, sub_id, sender_address, recipient_address
36
+ )
37
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
38
+ ON CONFLICT (subject) DO UPDATE SET
39
+ value = EXCLUDED.value,
40
+ block_height = EXCLUDED.block_height,
41
+ tx_id = EXCLUDED.tx_id,
42
+ tx_index = EXCLUDED.tx_index,
43
+ receipt_index = EXCLUDED.receipt_index,
44
+ receipt_type = EXCLUDED.receipt_type,
45
+ from_contract_id = EXCLUDED.from_contract_id,
46
+ to_contract_id = EXCLUDED.to_contract_id,
47
+ to_address = EXCLUDED.to_address,
48
+ asset_id = EXCLUDED.asset_id,
49
+ contract_id = EXCLUDED.contract_id,
50
+ sub_id = EXCLUDED.sub_id,
51
+ sender_address = EXCLUDED.sender_address,
52
+ recipient_address = EXCLUDED.recipient_address
53
+ RETURNING *
35
54
)
36
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
37
- RETURNING subject, value, block_height, tx_id, tx_index, receipt_index,
38
- receipt_type, from_contract_id, to_contract_id, to_address,
39
- asset_id, contract_id, sub_id, sender_address, recipient_address"
55
+ SELECT * FROM upsert"
40
56
)
41
57
. bind ( db_item. subject )
42
58
. bind ( db_item. value )
0 commit comments