// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: replies.sql package sqlcdb import ( "context" "time" ) const createReply = `-- name: CreateReply :exec INSERT INTO replies (uri, author_did, parent_uri, root_uri, text, format, created_at, indexed_at, cid) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) ON CONFLICT(uri) DO UPDATE SET text = EXCLUDED.text, format = EXCLUDED.format, indexed_at = EXCLUDED.indexed_at, cid = EXCLUDED.cid ` type CreateReplyParams struct { Uri string `json:"uri"` AuthorDid string `json:"authorDid"` ParentUri string `json:"parentUri"` RootUri string `json:"rootUri"` Text string `json:"text"` Format *string `json:"format"` CreatedAt time.Time `json:"createdAt"` IndexedAt time.Time `json:"indexedAt"` Cid *string `json:"cid"` } func (q *Queries) CreateReply(ctx context.Context, arg CreateReplyParams) error { _, err := q.db.Exec(ctx, createReply, arg.Uri, arg.AuthorDid, arg.ParentUri, arg.RootUri, arg.Text, arg.Format, arg.CreatedAt, arg.IndexedAt, arg.Cid, ) return err } const deleteReply = `-- name: DeleteReply :exec DELETE FROM replies WHERE uri = $1 ` func (q *Queries) DeleteReply(ctx context.Context, uri string) error { _, err := q.db.Exec(ctx, deleteReply, uri) return err } const getOrphanedRepliesByAuthor = `-- name: GetOrphanedRepliesByAuthor :many SELECT r.uri, r.author_did, r.parent_uri, r.root_uri, r.text, r.format, r.created_at, r.indexed_at, r.cid FROM replies r LEFT JOIN annotations a ON r.root_uri = a.uri WHERE r.author_did = $1 AND a.uri IS NULL ` func (q *Queries) GetOrphanedRepliesByAuthor(ctx context.Context, authorDid string) ([]Reply, error) { rows, err := q.db.Query(ctx, getOrphanedRepliesByAuthor, authorDid) if err != nil { return nil, err } defer rows.Close() var items []Reply for rows.Next() { var i Reply if err := rows.Scan( &i.Uri, &i.AuthorDid, &i.ParentUri, &i.RootUri, &i.Text, &i.Format, &i.CreatedAt, &i.IndexedAt, &i.Cid, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const getRepliesByAuthor = `-- name: GetRepliesByAuthor :many SELECT uri, author_did, parent_uri, root_uri, text, format, created_at, indexed_at, cid FROM replies WHERE author_did = $1 ORDER BY created_at DESC ` func (q *Queries) GetRepliesByAuthor(ctx context.Context, authorDid string) ([]Reply, error) { rows, err := q.db.Query(ctx, getRepliesByAuthor, authorDid) if err != nil { return nil, err } defer rows.Close() var items []Reply for rows.Next() { var i Reply if err := rows.Scan( &i.Uri, &i.AuthorDid, &i.ParentUri, &i.RootUri, &i.Text, &i.Format, &i.CreatedAt, &i.IndexedAt, &i.Cid, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const getRepliesByRoot = `-- name: GetRepliesByRoot :many SELECT uri, author_did, parent_uri, root_uri, text, format, created_at, indexed_at, cid FROM replies WHERE root_uri = $1 ORDER BY created_at ASC ` func (q *Queries) GetRepliesByRoot(ctx context.Context, rootUri string) ([]Reply, error) { rows, err := q.db.Query(ctx, getRepliesByRoot, rootUri) if err != nil { return nil, err } defer rows.Close() var items []Reply for rows.Next() { var i Reply if err := rows.Scan( &i.Uri, &i.AuthorDid, &i.ParentUri, &i.RootUri, &i.Text, &i.Format, &i.CreatedAt, &i.IndexedAt, &i.Cid, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const getRepliesByURIs = `-- name: GetRepliesByURIs :many SELECT uri, author_did, parent_uri, root_uri, text, format, created_at, indexed_at, cid FROM replies WHERE uri = ANY($1::text[]) ` func (q *Queries) GetRepliesByURIs(ctx context.Context, dollar_1 []string) ([]Reply, error) { rows, err := q.db.Query(ctx, getRepliesByURIs, dollar_1) if err != nil { return nil, err } defer rows.Close() var items []Reply for rows.Next() { var i Reply if err := rows.Scan( &i.Uri, &i.AuthorDid, &i.ParentUri, &i.RootUri, &i.Text, &i.Format, &i.CreatedAt, &i.IndexedAt, &i.Cid, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const getReplyByURI = `-- name: GetReplyByURI :one SELECT uri, author_did, parent_uri, root_uri, text, format, created_at, indexed_at, cid FROM replies WHERE uri = $1 ` func (q *Queries) GetReplyByURI(ctx context.Context, uri string) (Reply, error) { row := q.db.QueryRow(ctx, getReplyByURI, uri) var i Reply err := row.Scan( &i.Uri, &i.AuthorDid, &i.ParentUri, &i.RootUri, &i.Text, &i.Format, &i.CreatedAt, &i.IndexedAt, &i.Cid, ) return i, err } const getReplyCount = `-- name: GetReplyCount :one SELECT COUNT(*) FROM replies WHERE root_uri = $1 ` func (q *Queries) GetReplyCount(ctx context.Context, rootUri string) (int64, error) { row := q.db.QueryRow(ctx, getReplyCount, rootUri) var count int64 err := row.Scan(&count) return count, err } const getReplyCounts = `-- name: GetReplyCounts :many SELECT root_uri, COUNT(*) FROM replies WHERE root_uri = ANY($1::text[]) GROUP BY root_uri ` type GetReplyCountsRow struct { RootUri string `json:"rootUri"` Count int64 `json:"count"` } func (q *Queries) GetReplyCounts(ctx context.Context, dollar_1 []string) ([]GetReplyCountsRow, error) { rows, err := q.db.Query(ctx, getReplyCounts, dollar_1) if err != nil { return nil, err } defer rows.Close() var items []GetReplyCountsRow for rows.Next() { var i GetReplyCountsRow if err := rows.Scan(&i.RootUri, &i.Count); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil }