Monorepo for Tangled tangled.org
2

Configure Feed

Select the types of activity you want to include in your feed.

knotmirror/db: use `DBTX` interface

Signed-off-by: Seongmin Lee <git@boltless.me>

author
Seongmin Lee
committer
Tangled
date (Jun 11, 2026, 10:52 AM +0300) commit be0ee5df parent 07299d86 change-id qzqrsmnm
+16 -10
+6
knotmirror/db/db.go
··· 10 10 "tangled.org/core/log" 11 11 ) 12 12 13 + type DBTX interface { 14 + ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) 15 + QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) 16 + QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row 17 + } 18 + 13 19 func Make(ctx context.Context, dbUrl string, maxConns int) (*sql.DB, error) { 14 20 db, err := sql.Open("pgx", dbUrl) 15 21 if err != nil {
+3 -3
knotmirror/db/hosts.go
··· 10 10 "tangled.org/core/knotmirror/models" 11 11 ) 12 12 13 - func UpsertHost(ctx context.Context, e *sql.DB, host *models.Host) error { 13 + func UpsertHost(ctx context.Context, e DBTX, host *models.Host) error { 14 14 if _, err := e.ExecContext(ctx, 15 15 `insert into hosts (hostname, no_ssl, status, last_seq) 16 16 values ($1, $2, $3, $4) ··· 29 29 return nil 30 30 } 31 31 32 - func GetHost(ctx context.Context, e *sql.DB, hostname string) (*models.Host, error) { 32 + func GetHost(ctx context.Context, e DBTX, hostname string) (*models.Host, error) { 33 33 var host models.Host 34 34 if err := e.QueryRowContext(ctx, 35 35 `select hostname, no_ssl, status, last_seq ··· 70 70 return tx.Commit() 71 71 } 72 72 73 - func ListHosts(ctx context.Context, e *sql.DB, status models.HostStatus) ([]models.Host, error) { 73 + func ListHosts(ctx context.Context, e DBTX, status models.HostStatus) ([]models.Host, error) { 74 74 rows, err := e.QueryContext(ctx, 75 75 `select hostname, no_ssl, status, last_seq 76 76 from hosts
+7 -7
knotmirror/db/repos.go
··· 11 11 "tangled.org/core/knotmirror/models" 12 12 ) 13 13 14 - func UpsertRepo(ctx context.Context, e *sql.DB, repo *models.Repo) error { 14 + func UpsertRepo(ctx context.Context, e DBTX, repo *models.Repo) error { 15 15 if repo.RepoDid == "" { 16 16 return fmt.Errorf("upsert repo: repo_did is required") 17 17 } ··· 48 48 return nil 49 49 } 50 50 51 - func UpdateRepoState(ctx context.Context, e *sql.DB, repoDid syntax.DID, state models.RepoState) error { 51 + func UpdateRepoState(ctx context.Context, e DBTX, repoDid syntax.DID, state models.RepoState) error { 52 52 if _, err := e.ExecContext(ctx, 53 53 `update repos 54 54 set state = $1 ··· 61 61 return nil 62 62 } 63 63 64 - func DeleteRepo(ctx context.Context, e *sql.DB, did syntax.DID, rkey syntax.RecordKey) error { 64 + func DeleteRepo(ctx context.Context, e DBTX, did syntax.DID, rkey syntax.RecordKey) error { 65 65 if _, err := e.ExecContext(ctx, 66 66 `delete from repos where did = $1 and rkey = $2`, 67 67 did, ··· 107 107 return &repo, nil 108 108 } 109 109 110 - func GetRepoByRepoDid(ctx context.Context, e *sql.DB, repoDid syntax.DID) (*models.Repo, error) { 110 + func GetRepoByRepoDid(ctx context.Context, e DBTX, repoDid syntax.DID) (*models.Repo, error) { 111 111 row := e.QueryRowContext(ctx, 112 112 `select`+repoColumns+` 113 113 from repos ··· 124 124 return repo, nil 125 125 } 126 126 127 - func GetRepoByAtUri(ctx context.Context, e *sql.DB, aturi syntax.ATURI) (*models.Repo, error) { 127 + func GetRepoByAtUri(ctx context.Context, e DBTX, aturi syntax.ATURI) (*models.Repo, error) { 128 128 row := e.QueryRowContext(ctx, 129 129 `select`+repoColumns+` 130 130 from repos ··· 141 141 return repo, nil 142 142 } 143 143 144 - func ListRepos(ctx context.Context, e *sql.DB, page pagination.Page, did, knot, state, name string) ([]models.Repo, error) { 144 + func ListRepos(ctx context.Context, e DBTX, page pagination.Page, did, knot, state, name string) ([]models.Repo, error) { 145 145 var conditions []string 146 146 var args []any 147 147 ··· 200 200 return repos, nil 201 201 } 202 202 203 - func GetRepoCountsByState(ctx context.Context, e *sql.DB) (map[models.RepoState]int64, error) { 203 + func GetRepoCountsByState(ctx context.Context, e DBTX) (map[models.RepoState]int64, error) { 204 204 const q = ` 205 205 SELECT state, COUNT(*) 206 206 FROM repos