// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: monitor_groups.sql package store import ( "context" "github.com/google/uuid" ) const createGroup = `-- name: CreateGroup :one INSERT INTO monitor_groups (org_id, parent_id, name) VALUES ($1, $2, $3) RETURNING id, org_id, parent_id, name, created_at, updated_at ` type CreateGroupParams struct { OrgID uuid.UUID ParentID *uuid.UUID Name string } func (q *Queries) CreateGroup(ctx context.Context, arg CreateGroupParams) (MonitorGroup, error) { row := q.db.QueryRow(ctx, createGroup, arg.OrgID, arg.ParentID, arg.Name) var i MonitorGroup err := row.Scan( &i.ID, &i.OrgID, &i.ParentID, &i.Name, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const deleteAssignmentsForResource = `-- name: DeleteAssignmentsForResource :exec DELETE FROM role_assignments WHERE resource_type = $1 AND resource_id = $2 ` type DeleteAssignmentsForResourceParams struct { ResourceType *string ResourceID *uuid.UUID } func (q *Queries) DeleteAssignmentsForResource(ctx context.Context, arg DeleteAssignmentsForResourceParams) error { _, err := q.db.Exec(ctx, deleteAssignmentsForResource, arg.ResourceType, arg.ResourceID) return err } const deleteGroup = `-- name: DeleteGroup :execrows DELETE FROM monitor_groups WHERE id = $1 ` func (q *Queries) DeleteGroup(ctx context.Context, id uuid.UUID) (int64, error) { result, err := q.db.Exec(ctx, deleteGroup, id) if err != nil { return 0, err } return result.RowsAffected(), nil } const getGroup = `-- name: GetGroup :one SELECT id, org_id, parent_id, name, created_at, updated_at FROM monitor_groups WHERE id = $1 ` func (q *Queries) GetGroup(ctx context.Context, id uuid.UUID) (MonitorGroup, error) { row := q.db.QueryRow(ctx, getGroup, id) var i MonitorGroup err := row.Scan( &i.ID, &i.OrgID, &i.ParentID, &i.Name, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const listGroups = `-- name: ListGroups :many SELECT id, org_id, parent_id, name, created_at, updated_at FROM monitor_groups ORDER BY name ` func (q *Queries) ListGroups(ctx context.Context) ([]MonitorGroup, error) { rows, err := q.db.Query(ctx, listGroups) if err != nil { return nil, err } defer rows.Close() items := []MonitorGroup{} for rows.Next() { var i MonitorGroup if err := rows.Scan( &i.ID, &i.OrgID, &i.ParentID, &i.Name, &i.CreatedAt, &i.UpdatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const regroupMonitors = `-- name: RegroupMonitors :exec UPDATE monitors SET group_id = $1, updated_at = now() WHERE group_id = $2 ` type RegroupMonitorsParams struct { NewGroup *uuid.UUID OldGroup *uuid.UUID } func (q *Queries) RegroupMonitors(ctx context.Context, arg RegroupMonitorsParams) error { _, err := q.db.Exec(ctx, regroupMonitors, arg.NewGroup, arg.OldGroup) return err } const reparentGroups = `-- name: ReparentGroups :exec UPDATE monitor_groups SET parent_id = $1, updated_at = now() WHERE parent_id = $2 ` type ReparentGroupsParams struct { NewParent *uuid.UUID OldParent *uuid.UUID } // Moves the subgroups of a group that is about to be deleted. func (q *Queries) ReparentGroups(ctx context.Context, arg ReparentGroupsParams) error { _, err := q.db.Exec(ctx, reparentGroups, arg.NewParent, arg.OldParent) return err } const updateGroup = `-- name: UpdateGroup :one UPDATE monitor_groups SET name = $2, parent_id = $3, updated_at = now() WHERE id = $1 RETURNING id, org_id, parent_id, name, created_at, updated_at ` type UpdateGroupParams struct { ID uuid.UUID Name string ParentID *uuid.UUID } func (q *Queries) UpdateGroup(ctx context.Context, arg UpdateGroupParams) (MonitorGroup, error) { row := q.db.QueryRow(ctx, updateGroup, arg.ID, arg.Name, arg.ParentID) var i MonitorGroup err := row.Scan( &i.ID, &i.OrgID, &i.ParentID, &i.Name, &i.CreatedAt, &i.UpdatedAt, ) return i, err }