145 lines
3.2 KiB
Go
145 lines
3.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: practices.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CreatePractice = `-- name: CreatePractice :one
|
|
INSERT INTO practices (
|
|
owner_type,
|
|
owner_id,
|
|
title,
|
|
description,
|
|
banner_image,
|
|
persona,
|
|
is_active
|
|
)
|
|
VALUES ($1, $2, $3, $4, $5, $6, COALESCE($7, true))
|
|
RETURNING id, owner_type, owner_id, title, description, banner_image, persona, is_active
|
|
`
|
|
|
|
type CreatePracticeParams struct {
|
|
OwnerType string `json:"owner_type"`
|
|
OwnerID int64 `json:"owner_id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
BannerImage pgtype.Text `json:"banner_image"`
|
|
Persona pgtype.Text `json:"persona"`
|
|
Column7 interface{} `json:"column_7"`
|
|
}
|
|
|
|
func (q *Queries) CreatePractice(ctx context.Context, arg CreatePracticeParams) (Practice, error) {
|
|
row := q.db.QueryRow(ctx, CreatePractice,
|
|
arg.OwnerType,
|
|
arg.OwnerID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.BannerImage,
|
|
arg.Persona,
|
|
arg.Column7,
|
|
)
|
|
var i Practice
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.OwnerType,
|
|
&i.OwnerID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.BannerImage,
|
|
&i.Persona,
|
|
&i.IsActive,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const DeletePractice = `-- name: DeletePractice :exec
|
|
DELETE FROM practices
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeletePractice(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeletePractice, id)
|
|
return err
|
|
}
|
|
|
|
const GetPracticesByOwner = `-- name: GetPracticesByOwner :many
|
|
SELECT id, owner_type, owner_id, title, description, banner_image, persona, is_active
|
|
FROM practices
|
|
WHERE owner_type = $1
|
|
AND owner_id = $2
|
|
AND is_active = true
|
|
`
|
|
|
|
type GetPracticesByOwnerParams struct {
|
|
OwnerType string `json:"owner_type"`
|
|
OwnerID int64 `json:"owner_id"`
|
|
}
|
|
|
|
func (q *Queries) GetPracticesByOwner(ctx context.Context, arg GetPracticesByOwnerParams) ([]Practice, error) {
|
|
rows, err := q.db.Query(ctx, GetPracticesByOwner, arg.OwnerType, arg.OwnerID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Practice
|
|
for rows.Next() {
|
|
var i Practice
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.OwnerType,
|
|
&i.OwnerID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.BannerImage,
|
|
&i.Persona,
|
|
&i.IsActive,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const UpdatePractice = `-- name: UpdatePractice :exec
|
|
UPDATE practices
|
|
SET
|
|
title = COALESCE($1, title),
|
|
description = COALESCE($2, description),
|
|
banner_image = COALESCE($3, banner_image),
|
|
persona = COALESCE($4, persona),
|
|
is_active = COALESCE($5, is_active)
|
|
WHERE id = $6
|
|
`
|
|
|
|
type UpdatePracticeParams struct {
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
BannerImage pgtype.Text `json:"banner_image"`
|
|
Persona pgtype.Text `json:"persona"`
|
|
IsActive bool `json:"is_active"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdatePractice(ctx context.Context, arg UpdatePracticeParams) error {
|
|
_, err := q.db.Exec(ctx, UpdatePractice,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.BannerImage,
|
|
arg.Persona,
|
|
arg.IsActive,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|