mirror of
https://github.com/Dvorinka/Primora.git
synced 2026-06-04 12:33:01 +00:00
191 lines
4.4 KiB
Go
191 lines
4.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: buckets.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createBucket = `-- name: CreateBucket :one
|
|
INSERT INTO core.buckets (
|
|
project_id,
|
|
slug,
|
|
name,
|
|
visibility,
|
|
created_by_user_id
|
|
) VALUES ($1, $2, $3, $4, $5)
|
|
RETURNING id, project_id, slug, name, visibility, created_by_user_id, created_at
|
|
`
|
|
|
|
type CreateBucketParams struct {
|
|
ProjectID uuid.UUID `json:"project_id"`
|
|
Slug string `json:"slug"`
|
|
Name string `json:"name"`
|
|
Visibility string `json:"visibility"`
|
|
CreatedByUserID pgtype.UUID `json:"created_by_user_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateBucket(ctx context.Context, arg CreateBucketParams) (CoreBucket, error) {
|
|
row := q.db.QueryRow(ctx, createBucket,
|
|
arg.ProjectID,
|
|
arg.Slug,
|
|
arg.Name,
|
|
arg.Visibility,
|
|
arg.CreatedByUserID,
|
|
)
|
|
var i CoreBucket
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProjectID,
|
|
&i.Slug,
|
|
&i.Name,
|
|
&i.Visibility,
|
|
&i.CreatedByUserID,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteBucketByID = `-- name: DeleteBucketByID :one
|
|
DELETE FROM core.buckets
|
|
WHERE id = $1
|
|
RETURNING id, project_id, slug, name, visibility, created_by_user_id, created_at
|
|
`
|
|
|
|
func (q *Queries) DeleteBucketByID(ctx context.Context, id uuid.UUID) (CoreBucket, error) {
|
|
row := q.db.QueryRow(ctx, deleteBucketByID, id)
|
|
var i CoreBucket
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProjectID,
|
|
&i.Slug,
|
|
&i.Name,
|
|
&i.Visibility,
|
|
&i.CreatedByUserID,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getBucketByID = `-- name: GetBucketByID :one
|
|
SELECT
|
|
b.id, b.project_id, b.slug, b.name, b.visibility, b.created_by_user_id, b.created_at,
|
|
p.organization_id
|
|
FROM core.buckets b
|
|
JOIN core.projects p ON p.id = b.project_id
|
|
WHERE b.id = $1
|
|
`
|
|
|
|
type GetBucketByIDRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
ProjectID uuid.UUID `json:"project_id"`
|
|
Slug string `json:"slug"`
|
|
Name string `json:"name"`
|
|
Visibility string `json:"visibility"`
|
|
CreatedByUserID pgtype.UUID `json:"created_by_user_id"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
OrganizationID uuid.UUID `json:"organization_id"`
|
|
}
|
|
|
|
func (q *Queries) GetBucketByID(ctx context.Context, id uuid.UUID) (GetBucketByIDRow, error) {
|
|
row := q.db.QueryRow(ctx, getBucketByID, id)
|
|
var i GetBucketByIDRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProjectID,
|
|
&i.Slug,
|
|
&i.Name,
|
|
&i.Visibility,
|
|
&i.CreatedByUserID,
|
|
&i.CreatedAt,
|
|
&i.OrganizationID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listBucketsForProject = `-- name: ListBucketsForProject :many
|
|
SELECT id, project_id, slug, name, visibility, created_by_user_id, created_at FROM core.buckets
|
|
WHERE project_id = $1
|
|
AND (
|
|
btrim($2) = ''
|
|
OR slug ILIKE '%' || btrim($2) || '%'
|
|
OR name ILIKE '%' || btrim($2) || '%'
|
|
)
|
|
ORDER BY created_at ASC
|
|
`
|
|
|
|
type ListBucketsForProjectParams struct {
|
|
ProjectID uuid.UUID `json:"project_id"`
|
|
Btrim string `json:"btrim"`
|
|
}
|
|
|
|
func (q *Queries) ListBucketsForProject(ctx context.Context, arg ListBucketsForProjectParams) ([]CoreBucket, error) {
|
|
rows, err := q.db.Query(ctx, listBucketsForProject, arg.ProjectID, arg.Btrim)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []CoreBucket
|
|
for rows.Next() {
|
|
var i CoreBucket
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ProjectID,
|
|
&i.Slug,
|
|
&i.Name,
|
|
&i.Visibility,
|
|
&i.CreatedByUserID,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateBucketByID = `-- name: UpdateBucketByID :one
|
|
UPDATE core.buckets
|
|
SET slug = $2,
|
|
name = $3,
|
|
visibility = $4
|
|
WHERE id = $1
|
|
RETURNING id, project_id, slug, name, visibility, created_by_user_id, created_at
|
|
`
|
|
|
|
type UpdateBucketByIDParams struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Slug string `json:"slug"`
|
|
Name string `json:"name"`
|
|
Visibility string `json:"visibility"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBucketByID(ctx context.Context, arg UpdateBucketByIDParams) (CoreBucket, error) {
|
|
row := q.db.QueryRow(ctx, updateBucketByID,
|
|
arg.ID,
|
|
arg.Slug,
|
|
arg.Name,
|
|
arg.Visibility,
|
|
)
|
|
var i CoreBucket
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProjectID,
|
|
&i.Slug,
|
|
&i.Name,
|
|
&i.Visibility,
|
|
&i.CreatedByUserID,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|