Files
lincodex/backend/db/queries/holdings.sql
T

21 lines
648 B
SQL

-- Stores the holding of a founder account unless the account already has one.
-- A concurrent creation of the same account waits on the founder key until the
-- other transaction ends; then this insert does nothing, and the caller reads
-- the stored holding with GetHoldingIDByFounder.
-- name: InsertHoldingIfAbsent :exec
INSERT INTO holdings (
id,
founder_account_id,
created_at
) VALUES (
sqlc.arg(id),
sqlc.arg(founder_account_id),
sqlc.arg(created_at)
)
ON CONFLICT (founder_account_id) DO NOTHING;
-- name: GetHoldingIDByFounder :one
SELECT id
FROM holdings
WHERE founder_account_id = sqlc.arg(founder_account_id);