// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.29.0 // source: functions.sql package db import ( "context" "github.com/google/uuid" ) const createFunction = `-- name: CreateFunction :one INSERT INTO core.functions (project_id, name, code, runtime, event_pattern) VALUES ($1, $2, $3, $4, $5) RETURNING id, project_id, name, code, runtime, enabled, created_at, updated_at, event_pattern ` type CreateFunctionParams struct { ProjectID uuid.UUID `json:"project_id"` Name string `json:"name"` Code string `json:"code"` Runtime string `json:"runtime"` EventPattern string `json:"event_pattern"` } func (q *Queries) CreateFunction(ctx context.Context, arg CreateFunctionParams) (CoreFunction, error) { row := q.db.QueryRow(ctx, createFunction, arg.ProjectID, arg.Name, arg.Code, arg.Runtime, arg.EventPattern, ) var i CoreFunction err := row.Scan( &i.ID, &i.ProjectID, &i.Name, &i.Code, &i.Runtime, &i.Enabled, &i.CreatedAt, &i.UpdatedAt, &i.EventPattern, ) return i, err } const deleteFunction = `-- name: DeleteFunction :exec DELETE FROM core.functions WHERE id = $1 AND project_id = $2 ` type DeleteFunctionParams struct { ID uuid.UUID `json:"id"` ProjectID uuid.UUID `json:"project_id"` } func (q *Queries) DeleteFunction(ctx context.Context, arg DeleteFunctionParams) error { _, err := q.db.Exec(ctx, deleteFunction, arg.ID, arg.ProjectID) return err } const getFunction = `-- name: GetFunction :one SELECT id, project_id, name, code, runtime, enabled, created_at, updated_at, event_pattern FROM core.functions WHERE id = $1 ` func (q *Queries) GetFunction(ctx context.Context, id uuid.UUID) (CoreFunction, error) { row := q.db.QueryRow(ctx, getFunction, id) var i CoreFunction err := row.Scan( &i.ID, &i.ProjectID, &i.Name, &i.Code, &i.Runtime, &i.Enabled, &i.CreatedAt, &i.UpdatedAt, &i.EventPattern, ) return i, err } const getFunctionByName = `-- name: GetFunctionByName :one SELECT id, project_id, name, code, runtime, enabled, created_at, updated_at, event_pattern FROM core.functions WHERE project_id = $1 AND name = $2 ` type GetFunctionByNameParams struct { ProjectID uuid.UUID `json:"project_id"` Name string `json:"name"` } func (q *Queries) GetFunctionByName(ctx context.Context, arg GetFunctionByNameParams) (CoreFunction, error) { row := q.db.QueryRow(ctx, getFunctionByName, arg.ProjectID, arg.Name) var i CoreFunction err := row.Scan( &i.ID, &i.ProjectID, &i.Name, &i.Code, &i.Runtime, &i.Enabled, &i.CreatedAt, &i.UpdatedAt, &i.EventPattern, ) return i, err } const insertFunctionRun = `-- name: InsertFunctionRun :one INSERT INTO core.function_runs (function_id, trigger, status, exit_code, stdout, stderr, duration_ms) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id, function_id, trigger, status, exit_code, stdout, stderr, duration_ms, created_at ` type InsertFunctionRunParams struct { FunctionID uuid.UUID `json:"function_id"` Trigger string `json:"trigger"` Status string `json:"status"` ExitCode *int32 `json:"exit_code"` Stdout string `json:"stdout"` Stderr string `json:"stderr"` DurationMs int32 `json:"duration_ms"` } func (q *Queries) InsertFunctionRun(ctx context.Context, arg InsertFunctionRunParams) (CoreFunctionRun, error) { row := q.db.QueryRow(ctx, insertFunctionRun, arg.FunctionID, arg.Trigger, arg.Status, arg.ExitCode, arg.Stdout, arg.Stderr, arg.DurationMs, ) var i CoreFunctionRun err := row.Scan( &i.ID, &i.FunctionID, &i.Trigger, &i.Status, &i.ExitCode, &i.Stdout, &i.Stderr, &i.DurationMs, &i.CreatedAt, ) return i, err } const listFunctionRuns = `-- name: ListFunctionRuns :many SELECT id, function_id, trigger, status, exit_code, stdout, stderr, duration_ms, created_at FROM core.function_runs WHERE function_id = $1 ORDER BY created_at DESC LIMIT $2 ` type ListFunctionRunsParams struct { FunctionID uuid.UUID `json:"function_id"` Limit int32 `json:"limit"` } func (q *Queries) ListFunctionRuns(ctx context.Context, arg ListFunctionRunsParams) ([]CoreFunctionRun, error) { rows, err := q.db.Query(ctx, listFunctionRuns, arg.FunctionID, arg.Limit) if err != nil { return nil, err } defer rows.Close() var items []CoreFunctionRun for rows.Next() { var i CoreFunctionRun if err := rows.Scan( &i.ID, &i.FunctionID, &i.Trigger, &i.Status, &i.ExitCode, &i.Stdout, &i.Stderr, &i.DurationMs, &i.CreatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listFunctions = `-- name: ListFunctions :many SELECT id, project_id, name, code, runtime, enabled, created_at, updated_at, event_pattern FROM core.functions WHERE project_id = $1 ORDER BY name ` func (q *Queries) ListFunctions(ctx context.Context, projectID uuid.UUID) ([]CoreFunction, error) { rows, err := q.db.Query(ctx, listFunctions, projectID) if err != nil { return nil, err } defer rows.Close() var items []CoreFunction for rows.Next() { var i CoreFunction if err := rows.Scan( &i.ID, &i.ProjectID, &i.Name, &i.Code, &i.Runtime, &i.Enabled, &i.CreatedAt, &i.UpdatedAt, &i.EventPattern, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listFunctionsForEvent = `-- name: ListFunctionsForEvent :many SELECT id, project_id, name, code, runtime, enabled, created_at, updated_at, event_pattern FROM core.functions WHERE project_id = $1 AND enabled = TRUE AND event_pattern <> '' AND ($2 LIKE REPLACE(event_pattern, '*', '%') OR event_pattern = '*') ` type ListFunctionsForEventParams struct { ProjectID uuid.UUID `json:"project_id"` EventPattern string `json:"event_pattern"` } func (q *Queries) ListFunctionsForEvent(ctx context.Context, arg ListFunctionsForEventParams) ([]CoreFunction, error) { rows, err := q.db.Query(ctx, listFunctionsForEvent, arg.ProjectID, arg.EventPattern) if err != nil { return nil, err } defer rows.Close() var items []CoreFunction for rows.Next() { var i CoreFunction if err := rows.Scan( &i.ID, &i.ProjectID, &i.Name, &i.Code, &i.Runtime, &i.Enabled, &i.CreatedAt, &i.UpdatedAt, &i.EventPattern, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const updateFunction = `-- name: UpdateFunction :one UPDATE core.functions SET code = COALESCE($3, code), enabled = COALESCE($4, enabled), event_pattern = COALESCE($5, event_pattern), updated_at = NOW() WHERE id = $1 AND project_id = $2 RETURNING id, project_id, name, code, runtime, enabled, created_at, updated_at, event_pattern ` type UpdateFunctionParams struct { ID uuid.UUID `json:"id"` ProjectID uuid.UUID `json:"project_id"` Code *string `json:"code"` Enabled *bool `json:"enabled"` EventPattern *string `json:"event_pattern"` } func (q *Queries) UpdateFunction(ctx context.Context, arg UpdateFunctionParams) (CoreFunction, error) { row := q.db.QueryRow(ctx, updateFunction, arg.ID, arg.ProjectID, arg.Code, arg.Enabled, arg.EventPattern, ) var i CoreFunction err := row.Scan( &i.ID, &i.ProjectID, &i.Name, &i.Code, &i.Runtime, &i.Enabled, &i.CreatedAt, &i.UpdatedAt, &i.EventPattern, ) return i, err }