-- name: CreateBank :one INSERT INTO banks ( slug, swift, name, acct_length, country_id, is_mobilemoney, is_active, is_rtgs, active, is_24hrs, created_at, updated_at, currency, bank_logo ) VALUES ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, $11, $12 ) RETURNING *; -- name: GetBankByID :one SELECT * FROM banks WHERE id = $1; -- name: GetAllBanks :many SELECT * FROM banks WHERE ( country_id = sqlc.narg('country_id') OR sqlc.narg('country_id') IS NULL ) AND ( is_active = sqlc.narg('is_active') OR sqlc.narg('is_active') IS NULL ) AND ( name ILIKE '%' || sqlc.narg('search_term') || '%' OR sqlc.narg('search_term') IS NULL ) AND ( code ILIKE '%' || sqlc.narg('search_term') || '%' OR sqlc.narg('search_term') IS NULL ) ORDER BY name ASC LIMIT sqlc.narg('limit') OFFSET sqlc.narg('offset'); -- name: CountBanks :one SELECT COUNT(*) FROM banks WHERE ( country_id = $1 OR $1 IS NULL ) AND ( is_active = $2 OR $2 IS NULL ) AND ( name ILIKE '%' || $3 || '%' OR code ILIKE '%' || $3 || '%' OR $3 IS NULL ); -- name: UpdateBank :one UPDATE banks SET slug = COALESCE(sqlc.narg(slug), slug), swift = COALESCE(sqlc.narg(swift), swift), name = COALESCE(sqlc.narg(name), name), acct_length = COALESCE(sqlc.narg(acct_length), acct_length), country_id = COALESCE(sqlc.narg(country_id), country_id), is_mobilemoney = COALESCE(sqlc.narg(is_mobilemoney), is_mobilemoney), is_active = COALESCE(sqlc.narg(is_active), is_active), is_rtgs = COALESCE(sqlc.narg(is_rtgs), is_rtgs), active = COALESCE(sqlc.narg(active), active), is_24hrs = COALESCE(sqlc.narg(is_24hrs), is_24hrs), updated_at = CURRENT_TIMESTAMP, currency = COALESCE(sqlc.narg(currency), currency), bank_logo = COALESCE(sqlc.narg(bank_logo), bank_logo) WHERE id = $1 RETURNING *; -- name: DeleteBank :exec DELETE FROM banks WHERE id = $1;