| 1 | // Code generated by sqlc. DO NOT EDIT. |
| 2 | // versions: |
| 3 | // sqlc v1.31.1 |
| 4 | // source: repos.sql |
| 5 | |
| 6 | package reposdb |
| 7 | |
| 8 | import ( |
| 9 | "context" |
| 10 | |
| 11 | "github.com/jackc/pgx/v5/pgtype" |
| 12 | ) |
| 13 | |
| 14 | const countReposForOwnerUser = `-- name: CountReposForOwnerUser :one |
| 15 | SELECT count(*) FROM repos |
| 16 | WHERE owner_user_id = $1 AND deleted_at IS NULL |
| 17 | ` |
| 18 | |
| 19 | func (q *Queries) CountReposForOwnerUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) (int64, error) { |
| 20 | row := db.QueryRow(ctx, countReposForOwnerUser, ownerUserID) |
| 21 | var count int64 |
| 22 | err := row.Scan(&count) |
| 23 | return count, err |
| 24 | } |
| 25 | |
| 26 | const createRepo = `-- name: CreateRepo :one |
| 27 | |
| 28 | INSERT INTO repos ( |
| 29 | owner_user_id, owner_org_id, name, description, visibility, |
| 30 | default_branch, license_key, primary_language |
| 31 | ) VALUES ( |
| 32 | $1, $2, $3, $4, $5, $6, $7, $8 |
| 33 | ) |
| 34 | RETURNING id, owner_user_id, owner_org_id, name, description, visibility, |
| 35 | default_branch, is_archived, archived_at, deleted_at, |
| 36 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 37 | has_issues, has_pulls, created_at, updated_at, default_branch_oid |
| 38 | ` |
| 39 | |
| 40 | type CreateRepoParams struct { |
| 41 | OwnerUserID pgtype.Int8 |
| 42 | OwnerOrgID pgtype.Int8 |
| 43 | Name string |
| 44 | Description string |
| 45 | Visibility RepoVisibility |
| 46 | DefaultBranch string |
| 47 | LicenseKey pgtype.Text |
| 48 | PrimaryLanguage pgtype.Text |
| 49 | } |
| 50 | |
| 51 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 52 | func (q *Queries) CreateRepo(ctx context.Context, db DBTX, arg CreateRepoParams) (Repo, error) { |
| 53 | row := db.QueryRow(ctx, createRepo, |
| 54 | arg.OwnerUserID, |
| 55 | arg.OwnerOrgID, |
| 56 | arg.Name, |
| 57 | arg.Description, |
| 58 | arg.Visibility, |
| 59 | arg.DefaultBranch, |
| 60 | arg.LicenseKey, |
| 61 | arg.PrimaryLanguage, |
| 62 | ) |
| 63 | var i Repo |
| 64 | err := row.Scan( |
| 65 | &i.ID, |
| 66 | &i.OwnerUserID, |
| 67 | &i.OwnerOrgID, |
| 68 | &i.Name, |
| 69 | &i.Description, |
| 70 | &i.Visibility, |
| 71 | &i.DefaultBranch, |
| 72 | &i.IsArchived, |
| 73 | &i.ArchivedAt, |
| 74 | &i.DeletedAt, |
| 75 | &i.DiskUsedBytes, |
| 76 | &i.ForkOfRepoID, |
| 77 | &i.LicenseKey, |
| 78 | &i.PrimaryLanguage, |
| 79 | &i.HasIssues, |
| 80 | &i.HasPulls, |
| 81 | &i.CreatedAt, |
| 82 | &i.UpdatedAt, |
| 83 | &i.DefaultBranchOid, |
| 84 | ) |
| 85 | return i, err |
| 86 | } |
| 87 | |
| 88 | const existsRepoForOwnerUser = `-- name: ExistsRepoForOwnerUser :one |
| 89 | SELECT EXISTS( |
| 90 | SELECT 1 FROM repos |
| 91 | WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NULL |
| 92 | ) |
| 93 | ` |
| 94 | |
| 95 | type ExistsRepoForOwnerUserParams struct { |
| 96 | OwnerUserID pgtype.Int8 |
| 97 | Name string |
| 98 | } |
| 99 | |
| 100 | func (q *Queries) ExistsRepoForOwnerUser(ctx context.Context, db DBTX, arg ExistsRepoForOwnerUserParams) (bool, error) { |
| 101 | row := db.QueryRow(ctx, existsRepoForOwnerUser, arg.OwnerUserID, arg.Name) |
| 102 | var exists bool |
| 103 | err := row.Scan(&exists) |
| 104 | return exists, err |
| 105 | } |
| 106 | |
| 107 | const getRepoByID = `-- name: GetRepoByID :one |
| 108 | SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 109 | default_branch, is_archived, archived_at, deleted_at, |
| 110 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 111 | has_issues, has_pulls, created_at, updated_at, default_branch_oid |
| 112 | FROM repos |
| 113 | WHERE id = $1 |
| 114 | ` |
| 115 | |
| 116 | func (q *Queries) GetRepoByID(ctx context.Context, db DBTX, id int64) (Repo, error) { |
| 117 | row := db.QueryRow(ctx, getRepoByID, id) |
| 118 | var i Repo |
| 119 | err := row.Scan( |
| 120 | &i.ID, |
| 121 | &i.OwnerUserID, |
| 122 | &i.OwnerOrgID, |
| 123 | &i.Name, |
| 124 | &i.Description, |
| 125 | &i.Visibility, |
| 126 | &i.DefaultBranch, |
| 127 | &i.IsArchived, |
| 128 | &i.ArchivedAt, |
| 129 | &i.DeletedAt, |
| 130 | &i.DiskUsedBytes, |
| 131 | &i.ForkOfRepoID, |
| 132 | &i.LicenseKey, |
| 133 | &i.PrimaryLanguage, |
| 134 | &i.HasIssues, |
| 135 | &i.HasPulls, |
| 136 | &i.CreatedAt, |
| 137 | &i.UpdatedAt, |
| 138 | &i.DefaultBranchOid, |
| 139 | ) |
| 140 | return i, err |
| 141 | } |
| 142 | |
| 143 | const getRepoByOwnerUserAndName = `-- name: GetRepoByOwnerUserAndName :one |
| 144 | SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 145 | default_branch, is_archived, archived_at, deleted_at, |
| 146 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 147 | has_issues, has_pulls, created_at, updated_at, default_branch_oid |
| 148 | FROM repos |
| 149 | WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NULL |
| 150 | ` |
| 151 | |
| 152 | type GetRepoByOwnerUserAndNameParams struct { |
| 153 | OwnerUserID pgtype.Int8 |
| 154 | Name string |
| 155 | } |
| 156 | |
| 157 | func (q *Queries) GetRepoByOwnerUserAndName(ctx context.Context, db DBTX, arg GetRepoByOwnerUserAndNameParams) (Repo, error) { |
| 158 | row := db.QueryRow(ctx, getRepoByOwnerUserAndName, arg.OwnerUserID, arg.Name) |
| 159 | var i Repo |
| 160 | err := row.Scan( |
| 161 | &i.ID, |
| 162 | &i.OwnerUserID, |
| 163 | &i.OwnerOrgID, |
| 164 | &i.Name, |
| 165 | &i.Description, |
| 166 | &i.Visibility, |
| 167 | &i.DefaultBranch, |
| 168 | &i.IsArchived, |
| 169 | &i.ArchivedAt, |
| 170 | &i.DeletedAt, |
| 171 | &i.DiskUsedBytes, |
| 172 | &i.ForkOfRepoID, |
| 173 | &i.LicenseKey, |
| 174 | &i.PrimaryLanguage, |
| 175 | &i.HasIssues, |
| 176 | &i.HasPulls, |
| 177 | &i.CreatedAt, |
| 178 | &i.UpdatedAt, |
| 179 | &i.DefaultBranchOid, |
| 180 | ) |
| 181 | return i, err |
| 182 | } |
| 183 | |
| 184 | const getRepoOwnerUsernameByID = `-- name: GetRepoOwnerUsernameByID :one |
| 185 | SELECT u.username AS owner_username, r.name AS repo_name |
| 186 | FROM repos r |
| 187 | JOIN users u ON u.id = r.owner_user_id |
| 188 | WHERE r.id = $1 |
| 189 | ` |
| 190 | |
| 191 | type GetRepoOwnerUsernameByIDRow struct { |
| 192 | OwnerUsername string |
| 193 | RepoName string |
| 194 | } |
| 195 | |
| 196 | // Returns the owner_username for a repo. Used by size-recalc and other |
| 197 | // jobs that need to derive the bare-repo on-disk path without round- |
| 198 | // tripping through the full user row. |
| 199 | func (q *Queries) GetRepoOwnerUsernameByID(ctx context.Context, db DBTX, id int64) (GetRepoOwnerUsernameByIDRow, error) { |
| 200 | row := db.QueryRow(ctx, getRepoOwnerUsernameByID, id) |
| 201 | var i GetRepoOwnerUsernameByIDRow |
| 202 | err := row.Scan(&i.OwnerUsername, &i.RepoName) |
| 203 | return i, err |
| 204 | } |
| 205 | |
| 206 | const listAllRepoFullNames = `-- name: ListAllRepoFullNames :many |
| 207 | SELECT |
| 208 | r.id, |
| 209 | r.name, |
| 210 | u.username AS owner_username |
| 211 | FROM repos r |
| 212 | JOIN users u ON u.id = r.owner_user_id |
| 213 | WHERE r.deleted_at IS NULL |
| 214 | ORDER BY r.id |
| 215 | ` |
| 216 | |
| 217 | type ListAllRepoFullNamesRow struct { |
| 218 | ID int64 |
| 219 | Name string |
| 220 | OwnerUsername string |
| 221 | } |
| 222 | |
| 223 | // Used by `shithubd hooks reinstall --all` to enumerate every active |
| 224 | // bare repo on disk and re-link its hooks. |
| 225 | func (q *Queries) ListAllRepoFullNames(ctx context.Context, db DBTX) ([]ListAllRepoFullNamesRow, error) { |
| 226 | rows, err := db.Query(ctx, listAllRepoFullNames) |
| 227 | if err != nil { |
| 228 | return nil, err |
| 229 | } |
| 230 | defer rows.Close() |
| 231 | items := []ListAllRepoFullNamesRow{} |
| 232 | for rows.Next() { |
| 233 | var i ListAllRepoFullNamesRow |
| 234 | if err := rows.Scan(&i.ID, &i.Name, &i.OwnerUsername); err != nil { |
| 235 | return nil, err |
| 236 | } |
| 237 | items = append(items, i) |
| 238 | } |
| 239 | if err := rows.Err(); err != nil { |
| 240 | return nil, err |
| 241 | } |
| 242 | return items, nil |
| 243 | } |
| 244 | |
| 245 | const listReposForOwnerUser = `-- name: ListReposForOwnerUser :many |
| 246 | SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 247 | default_branch, is_archived, archived_at, deleted_at, |
| 248 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 249 | has_issues, has_pulls, created_at, updated_at, default_branch_oid |
| 250 | FROM repos |
| 251 | WHERE owner_user_id = $1 AND deleted_at IS NULL |
| 252 | ORDER BY updated_at DESC |
| 253 | ` |
| 254 | |
| 255 | func (q *Queries) ListReposForOwnerUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) ([]Repo, error) { |
| 256 | rows, err := db.Query(ctx, listReposForOwnerUser, ownerUserID) |
| 257 | if err != nil { |
| 258 | return nil, err |
| 259 | } |
| 260 | defer rows.Close() |
| 261 | items := []Repo{} |
| 262 | for rows.Next() { |
| 263 | var i Repo |
| 264 | if err := rows.Scan( |
| 265 | &i.ID, |
| 266 | &i.OwnerUserID, |
| 267 | &i.OwnerOrgID, |
| 268 | &i.Name, |
| 269 | &i.Description, |
| 270 | &i.Visibility, |
| 271 | &i.DefaultBranch, |
| 272 | &i.IsArchived, |
| 273 | &i.ArchivedAt, |
| 274 | &i.DeletedAt, |
| 275 | &i.DiskUsedBytes, |
| 276 | &i.ForkOfRepoID, |
| 277 | &i.LicenseKey, |
| 278 | &i.PrimaryLanguage, |
| 279 | &i.HasIssues, |
| 280 | &i.HasPulls, |
| 281 | &i.CreatedAt, |
| 282 | &i.UpdatedAt, |
| 283 | &i.DefaultBranchOid, |
| 284 | ); err != nil { |
| 285 | return nil, err |
| 286 | } |
| 287 | items = append(items, i) |
| 288 | } |
| 289 | if err := rows.Err(); err != nil { |
| 290 | return nil, err |
| 291 | } |
| 292 | return items, nil |
| 293 | } |
| 294 | |
| 295 | const softDeleteRepo = `-- name: SoftDeleteRepo :exec |
| 296 | UPDATE repos SET deleted_at = now() WHERE id = $1 |
| 297 | ` |
| 298 | |
| 299 | func (q *Queries) SoftDeleteRepo(ctx context.Context, db DBTX, id int64) error { |
| 300 | _, err := db.Exec(ctx, softDeleteRepo, id) |
| 301 | return err |
| 302 | } |
| 303 | |
| 304 | const updateRepoDefaultBranchOID = `-- name: UpdateRepoDefaultBranchOID :exec |
| 305 | UPDATE repos SET default_branch_oid = $2::text WHERE id = $1 |
| 306 | ` |
| 307 | |
| 308 | type UpdateRepoDefaultBranchOIDParams struct { |
| 309 | ID int64 |
| 310 | DefaultBranchOid pgtype.Text |
| 311 | } |
| 312 | |
| 313 | // Set when push:process detects a commit on the repo's default branch. |
| 314 | // Pass NULL to clear (e.g. when the branch is force-deleted in a future |
| 315 | // sprint). The repo home view reads this to decide between empty and |
| 316 | // populated layouts. |
| 317 | func (q *Queries) UpdateRepoDefaultBranchOID(ctx context.Context, db DBTX, arg UpdateRepoDefaultBranchOIDParams) error { |
| 318 | _, err := db.Exec(ctx, updateRepoDefaultBranchOID, arg.ID, arg.DefaultBranchOid) |
| 319 | return err |
| 320 | } |
| 321 | |
| 322 | const updateRepoDiskUsed = `-- name: UpdateRepoDiskUsed :exec |
| 323 | UPDATE repos SET disk_used_bytes = $2 WHERE id = $1 |
| 324 | ` |
| 325 | |
| 326 | type UpdateRepoDiskUsedParams struct { |
| 327 | ID int64 |
| 328 | DiskUsedBytes int64 |
| 329 | } |
| 330 | |
| 331 | func (q *Queries) UpdateRepoDiskUsed(ctx context.Context, db DBTX, arg UpdateRepoDiskUsedParams) error { |
| 332 | _, err := db.Exec(ctx, updateRepoDiskUsed, arg.ID, arg.DiskUsedBytes) |
| 333 | return err |
| 334 | } |
| 335 |