@@ -0,0 +1,216 @@ |
| 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 |
| 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 | + ) |
| 84 | + return i, err |
| 85 | +} |
| 86 | + |
| 87 | +const existsRepoForOwnerUser = `-- name: ExistsRepoForOwnerUser :one |
| 88 | +SELECT EXISTS( |
| 89 | + SELECT 1 FROM repos |
| 90 | + WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NULL |
| 91 | +) |
| 92 | +` |
| 93 | + |
| 94 | +type ExistsRepoForOwnerUserParams struct { |
| 95 | + OwnerUserID pgtype.Int8 |
| 96 | + Name string |
| 97 | +} |
| 98 | + |
| 99 | +func (q *Queries) ExistsRepoForOwnerUser(ctx context.Context, db DBTX, arg ExistsRepoForOwnerUserParams) (bool, error) { |
| 100 | + row := db.QueryRow(ctx, existsRepoForOwnerUser, arg.OwnerUserID, arg.Name) |
| 101 | + var exists bool |
| 102 | + err := row.Scan(&exists) |
| 103 | + return exists, err |
| 104 | +} |
| 105 | + |
| 106 | +const getRepoByOwnerUserAndName = `-- name: GetRepoByOwnerUserAndName :one |
| 107 | +SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 108 | + default_branch, is_archived, archived_at, deleted_at, |
| 109 | + disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 110 | + has_issues, has_pulls, created_at, updated_at |
| 111 | +FROM repos |
| 112 | +WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NULL |
| 113 | +` |
| 114 | + |
| 115 | +type GetRepoByOwnerUserAndNameParams struct { |
| 116 | + OwnerUserID pgtype.Int8 |
| 117 | + Name string |
| 118 | +} |
| 119 | + |
| 120 | +func (q *Queries) GetRepoByOwnerUserAndName(ctx context.Context, db DBTX, arg GetRepoByOwnerUserAndNameParams) (Repo, error) { |
| 121 | + row := db.QueryRow(ctx, getRepoByOwnerUserAndName, arg.OwnerUserID, arg.Name) |
| 122 | + var i Repo |
| 123 | + err := row.Scan( |
| 124 | + &i.ID, |
| 125 | + &i.OwnerUserID, |
| 126 | + &i.OwnerOrgID, |
| 127 | + &i.Name, |
| 128 | + &i.Description, |
| 129 | + &i.Visibility, |
| 130 | + &i.DefaultBranch, |
| 131 | + &i.IsArchived, |
| 132 | + &i.ArchivedAt, |
| 133 | + &i.DeletedAt, |
| 134 | + &i.DiskUsedBytes, |
| 135 | + &i.ForkOfRepoID, |
| 136 | + &i.LicenseKey, |
| 137 | + &i.PrimaryLanguage, |
| 138 | + &i.HasIssues, |
| 139 | + &i.HasPulls, |
| 140 | + &i.CreatedAt, |
| 141 | + &i.UpdatedAt, |
| 142 | + ) |
| 143 | + return i, err |
| 144 | +} |
| 145 | + |
| 146 | +const listReposForOwnerUser = `-- name: ListReposForOwnerUser :many |
| 147 | +SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 148 | + default_branch, is_archived, archived_at, deleted_at, |
| 149 | + disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 150 | + has_issues, has_pulls, created_at, updated_at |
| 151 | +FROM repos |
| 152 | +WHERE owner_user_id = $1 AND deleted_at IS NULL |
| 153 | +ORDER BY updated_at DESC |
| 154 | +` |
| 155 | + |
| 156 | +func (q *Queries) ListReposForOwnerUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) ([]Repo, error) { |
| 157 | + rows, err := db.Query(ctx, listReposForOwnerUser, ownerUserID) |
| 158 | + if err != nil { |
| 159 | + return nil, err |
| 160 | + } |
| 161 | + defer rows.Close() |
| 162 | + items := []Repo{} |
| 163 | + for rows.Next() { |
| 164 | + var i Repo |
| 165 | + if err := rows.Scan( |
| 166 | + &i.ID, |
| 167 | + &i.OwnerUserID, |
| 168 | + &i.OwnerOrgID, |
| 169 | + &i.Name, |
| 170 | + &i.Description, |
| 171 | + &i.Visibility, |
| 172 | + &i.DefaultBranch, |
| 173 | + &i.IsArchived, |
| 174 | + &i.ArchivedAt, |
| 175 | + &i.DeletedAt, |
| 176 | + &i.DiskUsedBytes, |
| 177 | + &i.ForkOfRepoID, |
| 178 | + &i.LicenseKey, |
| 179 | + &i.PrimaryLanguage, |
| 180 | + &i.HasIssues, |
| 181 | + &i.HasPulls, |
| 182 | + &i.CreatedAt, |
| 183 | + &i.UpdatedAt, |
| 184 | + ); err != nil { |
| 185 | + return nil, err |
| 186 | + } |
| 187 | + items = append(items, i) |
| 188 | + } |
| 189 | + if err := rows.Err(); err != nil { |
| 190 | + return nil, err |
| 191 | + } |
| 192 | + return items, nil |
| 193 | +} |
| 194 | + |
| 195 | +const softDeleteRepo = `-- name: SoftDeleteRepo :exec |
| 196 | +UPDATE repos SET deleted_at = now() WHERE id = $1 |
| 197 | +` |
| 198 | + |
| 199 | +func (q *Queries) SoftDeleteRepo(ctx context.Context, db DBTX, id int64) error { |
| 200 | + _, err := db.Exec(ctx, softDeleteRepo, id) |
| 201 | + return err |
| 202 | +} |
| 203 | + |
| 204 | +const updateRepoDiskUsed = `-- name: UpdateRepoDiskUsed :exec |
| 205 | +UPDATE repos SET disk_used_bytes = $2 WHERE id = $1 |
| 206 | +` |
| 207 | + |
| 208 | +type UpdateRepoDiskUsedParams struct { |
| 209 | + ID int64 |
| 210 | + DiskUsedBytes int64 |
| 211 | +} |
| 212 | + |
| 213 | +func (q *Queries) UpdateRepoDiskUsed(ctx context.Context, db DBTX, arg UpdateRepoDiskUsedParams) error { |
| 214 | + _, err := db.Exec(ctx, updateRepoDiskUsed, arg.ID, arg.DiskUsedBytes) |
| 215 | + return err |
| 216 | +} |