Something went wrong. Try again.
(READ ONLY) Margin is an open annotation layer for the internet. Powered by the AT Protocol.
margin.at
extension web atproto comments
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681// Code generated by sqlc. DO NOT EDIT.// versions:// sqlc v1.31.1// source: recommendations.sql
package sqlcdb
import ( "context" "time")
const deleteAnnotationEmbedding = `-- name: DeleteAnnotationEmbedding :execDELETE FROM annotation_embeddings WHERE annotation_uri = $1`
func (q *Queries) DeleteAnnotationEmbedding(ctx context.Context, annotationUri string) error { _, err := q.db.Exec(ctx, deleteAnnotationEmbedding, annotationUri) return err}
const deleteDocument = `-- name: DeleteDocument :execDELETE FROM documents WHERE uri = $1`
func (q *Queries) DeleteDocument(ctx context.Context, uri string) error { _, err := q.db.Exec(ctx, deleteDocument, uri) return err}
const deletePublication = `-- name: DeletePublication :execDELETE FROM publications WHERE uri = $1`
func (q *Queries) DeletePublication(ctx context.Context, uri string) error { _, err := q.db.Exec(ctx, deletePublication, uri) return err}
const getAnnotationEmbeddingsByAuthor = `-- name: GetAnnotationEmbeddingsByAuthor :manySELECT annotation_uri, author_did, document_uri, embedding, updated_at FROM annotation_embeddings WHERE author_did = $1`
func (q *Queries) GetAnnotationEmbeddingsByAuthor(ctx context.Context, authorDid string) ([]AnnotationEmbedding, error) { rows, err := q.db.Query(ctx, getAnnotationEmbeddingsByAuthor, authorDid) if err != nil { return nil, err } defer rows.Close() var items []AnnotationEmbedding for rows.Next() { var i AnnotationEmbedding if err := rows.Scan( &i.AnnotationUri, &i.AuthorDid, &i.DocumentUri, &i.Embedding, &i.UpdatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil}
const getAnnotationsWithoutEmbeddings = `-- name: GetAnnotationsWithoutEmbeddings :manySELECT a.uri, a.author_did, a.motivation, a.body_value, a.body_format, a.body_uri, a.target_source, a.target_hash, a.target_title, a.selector_json, a.tags_json, a.created_at, a.indexed_at, a.cidFROM annotations aLEFT JOIN annotation_embeddings ae ON a.uri = ae.annotation_uriWHERE ae.annotation_uri IS NULL AND a.motivation IN ('commenting', 'highlighting')ORDER BY a.created_at DESCLIMIT $1`
func (q *Queries) GetAnnotationsWithoutEmbeddings(ctx context.Context, limit int32) ([]Annotation, error) { rows, err := q.db.Query(ctx, getAnnotationsWithoutEmbeddings, limit) if err != nil { return nil, err } defer rows.Close() var items []Annotation for rows.Next() { var i Annotation if err := rows.Scan( &i.Uri, &i.AuthorDid, &i.Motivation, &i.BodyValue, &i.BodyFormat, &i.BodyUri, &i.TargetSource, &i.TargetHash, &i.TargetTitle, &i.SelectorJson, &i.TagsJson, &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 getCandidateDocuments = `-- name: GetCandidateDocuments :manySELECT d.uri, d.author_did, d.site, d.path, d.title, d.description, d.tags_json, d.canonical_url, d.published_at, de.embedding, COALESCE(eng.cnt, 0) AS engagementFROM documents dJOIN document_embeddings de ON d.uri = de.document_uriLEFT JOIN ( SELECT document_uri, COUNT(DISTINCT author_did) AS cnt FROM annotation_embeddings WHERE document_uri IS NOT NULL GROUP BY document_uri) eng ON eng.document_uri = d.uriLEFT JOIN publications p ON d.site = p.uri OR d.site = p.urlWHERE d.author_did != $1 AND (p.show_in_discover IS NULL OR p.show_in_discover = true) AND LENGTH(d.title) > 15 AND (LENGTH(COALESCE(d.description, '')) >= 30 OR LENGTH(COALESCE(d.text_content, '')) >= 100) AND LOWER(d.title) NOT LIKE '%test%' AND LOWER(d.title) NOT LIKE '%testing%' AND LOWER(d.title) NOT LIKE '%hello world%' AND LOWER(d.title) NOT LIKE '%untitled%' AND LOWER(d.title) NOT LIKE '%draft%' AND LOWER(d.title) NOT LIKE '%asdf%' AND LOWER(d.title) NOT LIKE '%lorem%' AND LOWER(d.title) NOT LIKE '%placeholder%' AND d.uri NOT IN ( SELECT DISTINCT ae2.document_uri FROM annotation_embeddings ae2 WHERE ae2.author_did = $2 AND ae2.document_uri IS NOT NULL )ORDER BY d.published_at DESCLIMIT $3`
type GetCandidateDocumentsParams struct { AuthorDid string `json:"authorDid"` AuthorDid_2 string `json:"authorDid2"` Limit int32 `json:"limit"`}
type GetCandidateDocumentsRow struct { Uri string `json:"uri"` AuthorDid string `json:"authorDid"` Site string `json:"site"` Path *string `json:"path"` Title string `json:"title"` Description *string `json:"description"` TagsJson *string `json:"tagsJson"` CanonicalUrl *string `json:"canonicalUrl"` PublishedAt time.Time `json:"publishedAt"` Embedding string `json:"embedding"` Engagement int64 `json:"engagement"`}
func (q *Queries) GetCandidateDocuments(ctx context.Context, arg GetCandidateDocumentsParams) ([]GetCandidateDocumentsRow, error) { rows, err := q.db.Query(ctx, getCandidateDocuments, arg.AuthorDid, arg.AuthorDid_2, arg.Limit) if err != nil { return nil, err } defer rows.Close() var items []GetCandidateDocumentsRow for rows.Next() { var i GetCandidateDocumentsRow if err := rows.Scan( &i.Uri, &i.AuthorDid, &i.Site, &i.Path, &i.Title, &i.Description, &i.TagsJson, &i.CanonicalUrl, &i.PublishedAt, &i.Embedding, &i.Engagement, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil}
const getDistinctAnnotationAuthors = `-- name: GetDistinctAnnotationAuthors :manySELECT DISTINCT author_did FROM annotation_embeddings`
func (q *Queries) GetDistinctAnnotationAuthors(ctx context.Context) ([]string, error) { rows, err := q.db.Query(ctx, getDistinctAnnotationAuthors) if err != nil { return nil, err } defer rows.Close() var items []string for rows.Next() { var author_did string if err := rows.Scan(&author_did); err != nil { return nil, err } items = append(items, author_did) } if err := rows.Err(); err != nil { return nil, err } return items, nil}
const getDocumentByCanonicalURL = `-- name: GetDocumentByCanonicalURL :oneSELECT uri, author_did, site, path, title, description, text_content, tags_json, canonical_url, published_at, indexed_atFROM documents WHERE canonical_url = $1`
func (q *Queries) GetDocumentByCanonicalURL(ctx context.Context, canonicalUrl *string) (Document, error) { row := q.db.QueryRow(ctx, getDocumentByCanonicalURL, canonicalUrl) var i Document err := row.Scan( &i.Uri, &i.AuthorDid, &i.Site, &i.Path, &i.Title, &i.Description, &i.TextContent, &i.TagsJson, &i.CanonicalUrl, &i.PublishedAt, &i.IndexedAt, ) return i, err}
const getDocumentByURI = `-- name: GetDocumentByURI :oneSELECT uri, author_did, site, path, title, description, text_content, tags_json, canonical_url, published_at, indexed_atFROM documents WHERE uri = $1`
func (q *Queries) GetDocumentByURI(ctx context.Context, uri string) (Document, error) { row := q.db.QueryRow(ctx, getDocumentByURI, uri) var i Document err := row.Scan( &i.Uri, &i.AuthorDid, &i.Site, &i.Path, &i.Title, &i.Description, &i.TextContent, &i.TagsJson, &i.CanonicalUrl, &i.PublishedAt, &i.IndexedAt, ) return i, err}
const getDocumentCount = `-- name: GetDocumentCount :oneSELECT COUNT(*) FROM documents`
func (q *Queries) GetDocumentCount(ctx context.Context) (int64, error) { row := q.db.QueryRow(ctx, getDocumentCount) var count int64 err := row.Scan(&count) return count, err}
const getDocumentsWithoutEmbeddings = `-- name: GetDocumentsWithoutEmbeddings :manySELECT d.uri, d.author_did, d.site, d.path, d.title, d.description, d.text_content, d.tags_json, d.canonical_url, d.published_at, d.indexed_atFROM documents dLEFT JOIN document_embeddings de ON d.uri = de.document_uriWHERE de.document_uri IS NULLORDER BY d.indexed_at DESCLIMIT $1`
func (q *Queries) GetDocumentsWithoutEmbeddings(ctx context.Context, limit int32) ([]Document, error) { rows, err := q.db.Query(ctx, getDocumentsWithoutEmbeddings, limit) if err != nil { return nil, err } defer rows.Close() var items []Document for rows.Next() { var i Document if err := rows.Scan( &i.Uri, &i.AuthorDid, &i.Site, &i.Path, &i.Title, &i.Description, &i.TextContent, &i.TagsJson, &i.CanonicalUrl, &i.PublishedAt, &i.IndexedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil}
const getHighlightsWithoutEmbeddings = `-- name: GetHighlightsWithoutEmbeddings :manySELECT h.uri, h.author_did, h.target_source, h.target_title, h.selector_json, h.tags_jsonFROM highlights hLEFT JOIN annotation_embeddings ae ON h.uri = ae.annotation_uriWHERE ae.annotation_uri IS NULLORDER BY h.created_at DESCLIMIT $1`
type GetHighlightsWithoutEmbeddingsRow struct { Uri string `json:"uri"` AuthorDid string `json:"authorDid"` TargetSource string `json:"targetSource"` TargetTitle *string `json:"targetTitle"` SelectorJson *string `json:"selectorJson"` TagsJson *string `json:"tagsJson"`}
func (q *Queries) GetHighlightsWithoutEmbeddings(ctx context.Context, limit int32) ([]GetHighlightsWithoutEmbeddingsRow, error) { rows, err := q.db.Query(ctx, getHighlightsWithoutEmbeddings, limit) if err != nil { return nil, err } defer rows.Close() var items []GetHighlightsWithoutEmbeddingsRow for rows.Next() { var i GetHighlightsWithoutEmbeddingsRow if err := rows.Scan( &i.Uri, &i.AuthorDid, &i.TargetSource, &i.TargetTitle, &i.SelectorJson, &i.TagsJson, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil}
const getPopularDocuments = `-- name: GetPopularDocuments :manySELECT d.uri, d.author_did, d.site, d.path, d.title, d.description, d.text_content, d.tags_json, d.canonical_url, d.published_at, d.indexed_atFROM documents dLEFT JOIN annotations a ON a.target_source = d.canonical_urlGROUP BY d.uriORDER BY COUNT(a.uri) DESC, d.published_at DESCLIMIT $1 OFFSET $2`
type GetPopularDocumentsParams struct { Limit int32 `json:"limit"` Offset int32 `json:"offset"`}
func (q *Queries) GetPopularDocuments(ctx context.Context, arg GetPopularDocumentsParams) ([]Document, error) { rows, err := q.db.Query(ctx, getPopularDocuments, arg.Limit, arg.Offset) if err != nil { return nil, err } defer rows.Close() var items []Document for rows.Next() { var i Document if err := rows.Scan( &i.Uri, &i.AuthorDid, &i.Site, &i.Path, &i.Title, &i.Description, &i.TextContent, &i.TagsJson, &i.CanonicalUrl, &i.PublishedAt, &i.IndexedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil}
const getPublicationByURL = `-- name: GetPublicationByURL :oneSELECT uri, author_did, url, name, description, show_in_discover, indexed_atFROM publications WHERE url = $1`
func (q *Queries) GetPublicationByURL(ctx context.Context, url string) (Publication, error) { row := q.db.QueryRow(ctx, getPublicationByURL, url) var i Publication err := row.Scan( &i.Uri, &i.AuthorDid, &i.Url, &i.Name, &i.Description, &i.ShowInDiscover, &i.IndexedAt, ) return i, err}
const getRecentAnnotationEmbeddingsByAuthor = `-- name: GetRecentAnnotationEmbeddingsByAuthor :manySELECT annotation_uri, author_did, document_uri, embedding, updated_at FROM annotation_embeddings WHERE author_did = $1 ORDER BY updated_at DESC LIMIT $2`
type GetRecentAnnotationEmbeddingsByAuthorParams struct { AuthorDid string `json:"authorDid"` Limit int32 `json:"limit"`}
func (q *Queries) GetRecentAnnotationEmbeddingsByAuthor(ctx context.Context, arg GetRecentAnnotationEmbeddingsByAuthorParams) ([]AnnotationEmbedding, error) { rows, err := q.db.Query(ctx, getRecentAnnotationEmbeddingsByAuthor, arg.AuthorDid, arg.Limit) if err != nil { return nil, err } defer rows.Close() var items []AnnotationEmbedding for rows.Next() { var i AnnotationEmbedding if err := rows.Scan( &i.AnnotationUri, &i.AuthorDid, &i.DocumentUri, &i.Embedding, &i.UpdatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil}
const getRecentDocuments = `-- name: GetRecentDocuments :manySELECT uri, author_did, site, path, title, description, text_content, tags_json, canonical_url, published_at, indexed_atFROM documentsORDER BY published_at DESCLIMIT $1 OFFSET $2`
type GetRecentDocumentsParams struct { Limit int32 `json:"limit"` Offset int32 `json:"offset"`}
func (q *Queries) GetRecentDocuments(ctx context.Context, arg GetRecentDocumentsParams) ([]Document, error) { rows, err := q.db.Query(ctx, getRecentDocuments, arg.Limit, arg.Offset) if err != nil { return nil, err } defer rows.Close() var items []Document for rows.Next() { var i Document if err := rows.Scan( &i.Uri, &i.AuthorDid, &i.Site, &i.Path, &i.Title, &i.Description, &i.TextContent, &i.TagsJson, &i.CanonicalUrl, &i.PublishedAt, &i.IndexedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil}
const getUserProfile = `-- name: GetUserProfile :oneSELECT author_did, embedding, tag_affinities, annotation_count, updated_at FROM user_profiles WHERE author_did = $1`
func (q *Queries) GetUserProfile(ctx context.Context, authorDid string) (UserProfile, error) { row := q.db.QueryRow(ctx, getUserProfile, authorDid) var i UserProfile err := row.Scan( &i.AuthorDid, &i.Embedding, &i.TagAffinities, &i.AnnotationCount, &i.UpdatedAt, ) return i, err}
const matchAnnotationToDocument = `-- name: MatchAnnotationToDocument :oneSELECT uri FROM documents WHERE canonical_url = $1`
func (q *Queries) MatchAnnotationToDocument(ctx context.Context, canonicalUrl *string) (string, error) { row := q.db.QueryRow(ctx, matchAnnotationToDocument, canonicalUrl) var uri string err := row.Scan(&uri) return uri, err}
const upsertAnnotationEmbedding = `-- name: UpsertAnnotationEmbedding :execINSERT INTO annotation_embeddings (annotation_uri, author_did, document_uri, embedding, updated_at) VALUES ($1, $2, $3, $4, $5)ON CONFLICT(annotation_uri) DO UPDATE SET embedding = EXCLUDED.embedding, document_uri = EXCLUDED.document_uri, updated_at = EXCLUDED.updated_at`
type UpsertAnnotationEmbeddingParams struct { AnnotationUri string `json:"annotationUri"` AuthorDid string `json:"authorDid"` DocumentUri *string `json:"documentUri"` Embedding string `json:"embedding"` UpdatedAt time.Time `json:"updatedAt"`}
func (q *Queries) UpsertAnnotationEmbedding(ctx context.Context, arg UpsertAnnotationEmbeddingParams) error { _, err := q.db.Exec(ctx, upsertAnnotationEmbedding, arg.AnnotationUri, arg.AuthorDid, arg.DocumentUri, arg.Embedding, arg.UpdatedAt, ) return err}
const upsertDocument = `-- name: UpsertDocument :execINSERT INTO documents (uri, author_did, site, path, title, description, text_content, tags_json, canonical_url, published_at, indexed_at)VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)ON CONFLICT(uri) DO UPDATE SET title = EXCLUDED.title, description = EXCLUDED.description, text_content = EXCLUDED.text_content, tags_json = EXCLUDED.tags_json, canonical_url = EXCLUDED.canonical_url, indexed_at = EXCLUDED.indexed_at`
type UpsertDocumentParams struct { Uri string `json:"uri"` AuthorDid string `json:"authorDid"` Site string `json:"site"` Path *string `json:"path"` Title string `json:"title"` Description *string `json:"description"` TextContent *string `json:"textContent"` TagsJson *string `json:"tagsJson"` CanonicalUrl *string `json:"canonicalUrl"` PublishedAt time.Time `json:"publishedAt"` IndexedAt time.Time `json:"indexedAt"`}
func (q *Queries) UpsertDocument(ctx context.Context, arg UpsertDocumentParams) error { _, err := q.db.Exec(ctx, upsertDocument, arg.Uri, arg.AuthorDid, arg.Site, arg.Path, arg.Title, arg.Description, arg.TextContent, arg.TagsJson, arg.CanonicalUrl, arg.PublishedAt, arg.IndexedAt, ) return err}
const upsertDocumentEmbedding = `-- name: UpsertDocumentEmbedding :execINSERT INTO document_embeddings (document_uri, embedding, updated_at) VALUES ($1, $2, $3)ON CONFLICT(document_uri) DO UPDATE SET embedding = EXCLUDED.embedding, updated_at = EXCLUDED.updated_at`
type UpsertDocumentEmbeddingParams struct { DocumentUri string `json:"documentUri"` Embedding string `json:"embedding"` UpdatedAt time.Time `json:"updatedAt"`}
func (q *Queries) UpsertDocumentEmbedding(ctx context.Context, arg UpsertDocumentEmbeddingParams) error { _, err := q.db.Exec(ctx, upsertDocumentEmbedding, arg.DocumentUri, arg.Embedding, arg.UpdatedAt) return err}
const upsertPublication = `-- name: UpsertPublication :execINSERT INTO publications (uri, author_did, url, name, description, show_in_discover, indexed_at)VALUES ($1, $2, $3, $4, $5, $6, $7)ON CONFLICT(uri) DO UPDATE SET name = EXCLUDED.name, description = EXCLUDED.description, show_in_discover = EXCLUDED.show_in_discover, indexed_at = EXCLUDED.indexed_at`
type UpsertPublicationParams struct { Uri string `json:"uri"` AuthorDid string `json:"authorDid"` Url string `json:"url"` Name string `json:"name"` Description *string `json:"description"` ShowInDiscover bool `json:"showInDiscover"` IndexedAt time.Time `json:"indexedAt"`}
func (q *Queries) UpsertPublication(ctx context.Context, arg UpsertPublicationParams) error { _, err := q.db.Exec(ctx, upsertPublication, arg.Uri, arg.AuthorDid, arg.Url, arg.Name, arg.Description, arg.ShowInDiscover, arg.IndexedAt, ) return err}
const upsertUserProfile = `-- name: UpsertUserProfile :execINSERT INTO user_profiles (author_did, embedding, tag_affinities, annotation_count, updated_at) VALUES ($1, $2, $3, $4, $5)ON CONFLICT(author_did) DO UPDATE SET embedding = EXCLUDED.embedding, tag_affinities = EXCLUDED.tag_affinities, annotation_count = EXCLUDED.annotation_count, updated_at = EXCLUDED.updated_at`
type UpsertUserProfileParams struct { AuthorDid string `json:"authorDid"` Embedding string `json:"embedding"` TagAffinities *string `json:"tagAffinities"` AnnotationCount int32 `json:"annotationCount"` UpdatedAt time.Time `json:"updatedAt"`}
func (q *Queries) UpsertUserProfile(ctx context.Context, arg UpsertUserProfileParams) error { _, err := q.db.Exec(ctx, upsertUserProfile, arg.AuthorDid, arg.Embedding, arg.TagAffinities, arg.AnnotationCount, arg.UpdatedAt, ) return err}