From f40578663011a924d269626d14231d19aaa3d25c Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Wed, 24 Apr 2024 15:14:16 +0800 Subject: [PATCH] on replace block --- src/cache/postgres.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cache/postgres.ts b/src/cache/postgres.ts index 0398cde..a5bd4d4 100644 --- a/src/cache/postgres.ts +++ b/src/cache/postgres.ts @@ -99,7 +99,13 @@ export function createPostgresCache(args: { await client.query( `INSERT INTO ${tableName( "blocks" - )} (chainId, blockNumber, blockHash, timestamp) VALUES ($1, $2, $3, $4)`, + )} (chainId, blockNumber, blockHash, timestamp) VALUES ($1, $2, $3, $4) + ON CONFLICT (chainId, blockhash) DO UPDATE SET + blockHash = EXCLUDED.blockHash, + timestamp = EXCLUDED.timestamp, + blockNumber = EXCLUDED.blocknumber, + chainId = EXCLUDED.chainId + `, [ args.chainId, args.blockNumber.toString(),