ZhangZhihui's Blog  
-- name: ListAccounts :many
SELECT * FROM accounts
WHERE owner = $1
ORDER BY id
LIMIT $2
OFFSET $3;

-- name: UpdateAccount :one
UPDATE accounts
SET balance = $2
WHERE id = $1
RETURNING *;

-- name: DeleteAccount :exec
DELETE FROM accounts
WHERE id = $1;

-- name: AddAccountBalance :one
UPDATE accounts
SET balance = balance + sqlc.arg(amount)
WHERE id = sqlc.arg(id)
RETURNING *;

 

 

 

If not using sql.arg(), the parameter names would be Balance and ID.

posted on 2023-12-02 23:09  ZhangZhihuiAAA  阅读(16)  评论(0编辑  收藏  举报