Handle circular required keys
Use a dummy-value at first and update it later. Deferrable doesn't seem to work for NOT NULL - only for FOREIGN KEYs.
This commit is contained in:
@ -12,13 +12,18 @@ import (
|
||||
|
||||
const createBudget = `-- name: CreateBudget :one
|
||||
INSERT INTO budgets
|
||||
(name, last_modification)
|
||||
VALUES ($1, NOW())
|
||||
(name, income_category_id, last_modification)
|
||||
VALUES ($1, $2, NOW())
|
||||
RETURNING id, name, last_modification, income_category_id
|
||||
`
|
||||
|
||||
func (q *Queries) CreateBudget(ctx context.Context, name string) (Budget, error) {
|
||||
row := q.db.QueryRowContext(ctx, createBudget, name)
|
||||
type CreateBudgetParams struct {
|
||||
Name string
|
||||
IncomeCategoryID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) CreateBudget(ctx context.Context, arg CreateBudgetParams) (Budget, error) {
|
||||
row := q.db.QueryRowContext(ctx, createBudget, arg.Name, arg.IncomeCategoryID)
|
||||
var i Budget
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
|
Reference in New Issue
Block a user