forked from tangled.org/core
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677package db
import ( "fmt" "strings" "time"
"github.com/bluesky-social/indigo/atproto/syntax")
type Collaborator struct { // identifiers for the record Id int64 Did syntax.DID Rkey string
// content SubjectDid syntax.DID RepoAt syntax.ATURI
// meta Created time.Time}
func AddCollaborator(e Execer, c Collaborator) error { _, err := e.Exec( `insert into collaborators (did, rkey, subject_did, repo_at) values (?, ?, ?, ?);`, c.Did, c.Rkey, c.SubjectDid, c.RepoAt, ) return err}
func DeleteCollaborator(e Execer, filters ...filter) error { var conditions []string var args []any for _, filter := range filters { conditions = append(conditions, filter.Condition()) args = append(args, filter.Arg()...) }
whereClause := "" if conditions != nil { whereClause = " where " + strings.Join(conditions, " and ") }
query := fmt.Sprintf(`delete from collaborators %s`, whereClause)
_, err := e.Exec(query, args...) return err}
func CollaboratingIn(e Execer, collaborator string) ([]Repo, error) { rows, err := e.Query(`select repo_at from collaborators where subject_did = ?`, collaborator) if err != nil { return nil, err } defer rows.Close()
var repoAts []string for rows.Next() { var aturi string err := rows.Scan(&aturi) if err != nil { return nil, err } repoAts = append(repoAts, aturi) } if err := rows.Err(); err != nil { return nil, err } if repoAts == nil { return nil, nil }
return GetRepos(e, 0, FilterIn("at_uri", repoAts))}