2025-01-18 17:22:08 -05:00
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
|
|
// versions:
|
|
|
|
// sqlc v1.27.0
|
|
|
|
// source: share.sql
|
|
|
|
|
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
|
|
)
|
|
|
|
|
|
|
|
const createShare = `-- name: CreateShare :exec
|
|
|
|
INSERT INTO shares (
|
|
|
|
id,
|
|
|
|
entity_type,
|
|
|
|
entity_id,
|
2025-01-19 21:51:39 -05:00
|
|
|
entity_date,
|
2025-01-18 17:22:08 -05:00
|
|
|
owner,
|
|
|
|
expiration
|
2025-01-19 21:51:39 -05:00
|
|
|
) VALUES ($1, $2, $3, $4, $5, $6)
|
2025-01-18 17:22:08 -05:00
|
|
|
`
|
|
|
|
|
|
|
|
type CreateShareParams struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
EntityType string `json:"entity_type"`
|
|
|
|
EntityID uuid.UUID `json:"entity_id"`
|
2025-01-19 21:51:39 -05:00
|
|
|
EntityDate pgtype.Timestamptz `json:"entity_date"`
|
2025-01-18 17:22:08 -05:00
|
|
|
Owner int `json:"owner"`
|
|
|
|
Expiration pgtype.Timestamptz `json:"expiration"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CreateShare(ctx context.Context, arg CreateShareParams) error {
|
|
|
|
_, err := q.db.Exec(ctx, createShare,
|
|
|
|
arg.ID,
|
|
|
|
arg.EntityType,
|
|
|
|
arg.EntityID,
|
2025-01-19 21:51:39 -05:00
|
|
|
arg.EntityDate,
|
2025-01-18 17:22:08 -05:00
|
|
|
arg.Owner,
|
|
|
|
arg.Expiration,
|
|
|
|
)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const deleteShare = `-- name: DeleteShare :exec
|
|
|
|
DELETE FROM shares WHERE id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) DeleteShare(ctx context.Context, id string) error {
|
|
|
|
_, err := q.db.Exec(ctx, deleteShare, id)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2025-01-22 10:39:23 -05:00
|
|
|
const getIncidentTalkgroups = `-- name: GetIncidentTalkgroups :many
|
|
|
|
SELECT DISTINCT
|
|
|
|
c.system,
|
|
|
|
c.talkgroup
|
|
|
|
FROM incidents_calls ic
|
|
|
|
JOIN calls c ON (c.id = ic.call_id AND c.call_date = ic.call_date)
|
|
|
|
WHERE ic.incident_id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
type GetIncidentTalkgroupsRow struct {
|
|
|
|
System int `json:"system"`
|
|
|
|
Talkgroup int `json:"talkgroup"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) GetIncidentTalkgroups(ctx context.Context, incidentID uuid.UUID) ([]GetIncidentTalkgroupsRow, error) {
|
|
|
|
rows, err := q.db.Query(ctx, getIncidentTalkgroups, incidentID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []GetIncidentTalkgroupsRow
|
|
|
|
for rows.Next() {
|
|
|
|
var i GetIncidentTalkgroupsRow
|
|
|
|
if err := rows.Scan(&i.System, &i.Talkgroup); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
items = append(items, i)
|
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
|
|
|
|
2025-01-18 17:22:08 -05:00
|
|
|
const getShare = `-- name: GetShare :one
|
|
|
|
SELECT
|
|
|
|
id,
|
|
|
|
entity_type,
|
|
|
|
entity_id,
|
2025-01-19 21:51:39 -05:00
|
|
|
entity_date,
|
2025-01-18 17:22:08 -05:00
|
|
|
owner,
|
|
|
|
expiration
|
|
|
|
FROM shares
|
|
|
|
WHERE id = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetShare(ctx context.Context, id string) (Share, error) {
|
|
|
|
row := q.db.QueryRow(ctx, getShare, id)
|
|
|
|
var i Share
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.EntityType,
|
|
|
|
&i.EntityID,
|
2025-01-19 21:51:39 -05:00
|
|
|
&i.EntityDate,
|
2025-01-18 17:22:08 -05:00
|
|
|
&i.Owner,
|
|
|
|
&i.Expiration,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const pruneShares = `-- name: PruneShares :exec
|
|
|
|
DELETE FROM shares WHERE expiration < NOW()
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) PruneShares(ctx context.Context) error {
|
|
|
|
_, err := q.db.Exec(ctx, pruneShares)
|
|
|
|
return err
|
|
|
|
}
|