Skip to content

Commit

Permalink
Merge pull request #44 from flashburst/update/product-info
Browse files Browse the repository at this point in the history
Refactor `get_product_info()` to include product_updated table
  • Loading branch information
rudolfnep committed Feb 7, 2024
2 parents c299329 + e14ac4a commit 8bdefe8
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions sql/base/003-functions/get_product_info.sql
Expand Up @@ -11,19 +11,37 @@ AS
$$
BEGIN
RETURN QUERY
SELECT
cover.product_created.info,
config_known_ipfs_hashes_view.ipfs_details
FROM cover.product_created
INNER JOIN config_known_ipfs_hashes_view
ON config_known_ipfs_hashes_view.ipfs_hash = cover.product_created.info
WHERE cover.product_created.chain_id = _chain_id
AND cover.product_created.cover_key = _cover_key
AND cover.product_created.product_key = _product_key;
WITH result AS (
SELECT
cover.product_updated.info,
config_known_ipfs_hashes_view.ipfs_details,
cover.product_updated.block_timestamp
FROM cover.product_updated
INNER JOIN config_known_ipfs_hashes_view
ON config_known_ipfs_hashes_view.ipfs_hash = cover.product_updated.info
WHERE cover.product_updated.chain_id = _chain_id
AND cover.product_updated.cover_key = _cover_key
AND cover.product_updated.product_key = _product_key
UNION
SELECT
cover.product_created.info,
config_known_ipfs_hashes_view.ipfs_details,
cover.product_created.block_timestamp
FROM cover.product_created
INNER JOIN config_known_ipfs_hashes_view
ON config_known_ipfs_hashes_view.ipfs_hash = cover.product_created.info
WHERE cover.product_created.chain_id = _chain_id
AND cover.product_created.cover_key = _cover_key
AND cover.product_created.product_key = _product_key
)
SELECT
info,
ipfs_details
FROM result
ORDER BY block_timestamp DESC
LIMIT 1;
END
$$
LANGUAGE plpgsql;

--SELECT * FROM get_product_info(1, string_to_bytes32('popular-defi-apps'), string_to_bytes32('compound-v2'));


0 comments on commit 8bdefe8

Please sign in to comment.