package store import ( "context" "database/sql" "errors" ) // Oficina ID links are connect's rows (home_identity_links). connect checks // them, and Base reads and removes them only as connect asks an app to: // removing a member removes their links (RemoveMember), and a link connect // no longer resolves is removed before the member links again // (web.oficina.dropDeadLink). Nothing here writes one. // OficinaLinkSubject is the Oficina account (subject at issuer) linked to // member number n; ok is false when there is none. func OficinaLinkSubject(ctx context.Context, q QueryRower, issuer string, n int64) (subject string, ok bool, err error) { err = q.QueryRowContext(ctx, `SELECT subject FROM home_identity_links WHERE issuer = ? AND person_id = ?`, issuer, n).Scan(&subject) if errors.Is(err, sql.ErrNoRows) { return "", false, nil } return subject, err == nil, err } // DeleteOficinaLink removes the link between subject at issuer and member // number n, if it is still that link. func DeleteOficinaLink(ctx context.Context, tx *sql.Tx, issuer, subject string, n int64) error { _, err := tx.ExecContext(ctx, `DELETE FROM home_identity_links WHERE issuer = ? AND subject = ? AND person_id = ?`, issuer, subject, n) return err }