42 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			SQL
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			SQL
		
	
	
	
	
	
| -- name: CreateCustomer :one
 | |
| INSERT INTO customers (id, name, category, source, address, contact_name, contact_phone, created_by)
 | |
| VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
 | |
| RETURNING *;
 | |
| 
 | |
| -- name: UpdateCustomer :one
 | |
| UPDATE customers
 | |
| SET
 | |
|     name = COALESCE(sqlc.narg(name), name),
 | |
|     category = COALESCE(sqlc.narg(category), category),
 | |
|     source = COALESCE(sqlc.narg(source), source),
 | |
|     address = COALESCE(sqlc.narg(address), address),
 | |
|     contact_name = COALESCE(sqlc.narg(contact_name), contact_name),
 | |
|     contact_phone = COALESCE(sqlc.narg(contact_phone), contact_phone),
 | |
|     status = COALESCE(sqlc.narg(status), status),
 | |
|     updated_by = COALESCE(sqlc.narg(updated_by), updated_by),
 | |
|     updated_at = NOW()
 | |
| WHERE id = $1
 | |
| RETURNING *;
 | |
| 
 | |
| -- name: GetCustomer :one
 | |
| SELECT * 
 | |
| FROM customers 
 | |
| WHERE id = $1
 | |
| LIMIT 1;
 | |
| 
 | |
| -- name: AllCustomers :many
 | |
| SELECT * FROM customers
 | |
| WHERE status = 0
 | |
| ORDER BY id DESC;
 | |
| 
 | |
| -- name: CountCustomers :one
 | |
| SELECT COUNT(1)
 | |
| FROM customers
 | |
| WHERE status = 0;
 | |
| 
 | |
| -- name: ListCustomers :many
 | |
| SELECT * 
 | |
| FROM customers
 | |
| WHERE status = 0
 | |
| ORDER BY id DESC
 | |
| LIMIT $1 OFFSET $2; |