| 1 | // Code generated by sqlc. DO NOT EDIT. |
| 2 | // versions: |
| 3 | // sqlc v1.31.1 |
| 4 | // source: follows.sql |
| 5 | |
| 6 | package socialdb |
| 7 | |
| 8 | import ( |
| 9 | "context" |
| 10 | |
| 11 | "github.com/jackc/pgx/v5/pgtype" |
| 12 | ) |
| 13 | |
| 14 | const countFollowersForOrg = `-- name: CountFollowersForOrg :one |
| 15 | SELECT COUNT(*) FROM follows f |
| 16 | JOIN users u ON u.id = f.follower_user_id |
| 17 | WHERE f.followee_org_id = $1 |
| 18 | AND u.suspended_at IS NULL |
| 19 | AND u.deleted_at IS NULL |
| 20 | ` |
| 21 | |
| 22 | func (q *Queries) CountFollowersForOrg(ctx context.Context, db DBTX, followeeOrgID pgtype.Int8) (int64, error) { |
| 23 | row := db.QueryRow(ctx, countFollowersForOrg, followeeOrgID) |
| 24 | var count int64 |
| 25 | err := row.Scan(&count) |
| 26 | return count, err |
| 27 | } |
| 28 | |
| 29 | const countFollowersForUser = `-- name: CountFollowersForUser :one |
| 30 | SELECT COUNT(*) FROM follows f |
| 31 | JOIN users u ON u.id = f.follower_user_id |
| 32 | WHERE f.followee_user_id = $1 |
| 33 | AND u.suspended_at IS NULL |
| 34 | AND u.deleted_at IS NULL |
| 35 | ` |
| 36 | |
| 37 | func (q *Queries) CountFollowersForUser(ctx context.Context, db DBTX, followeeUserID pgtype.Int8) (int64, error) { |
| 38 | row := db.QueryRow(ctx, countFollowersForUser, followeeUserID) |
| 39 | var count int64 |
| 40 | err := row.Scan(&count) |
| 41 | return count, err |
| 42 | } |
| 43 | |
| 44 | const countFollowingForUser = `-- name: CountFollowingForUser :one |
| 45 | SELECT COUNT(*) FROM follows f |
| 46 | LEFT JOIN users u ON u.id = f.followee_user_id |
| 47 | LEFT JOIN orgs o ON o.id = f.followee_org_id |
| 48 | WHERE f.follower_user_id = $1 |
| 49 | AND (f.followee_user_id IS NULL OR (u.suspended_at IS NULL AND u.deleted_at IS NULL)) |
| 50 | AND (f.followee_org_id IS NULL OR (o.suspended_at IS NULL AND o.deleted_at IS NULL)) |
| 51 | ` |
| 52 | |
| 53 | func (q *Queries) CountFollowingForUser(ctx context.Context, db DBTX, followerUserID int64) (int64, error) { |
| 54 | row := db.QueryRow(ctx, countFollowingForUser, followerUserID) |
| 55 | var count int64 |
| 56 | err := row.Scan(&count) |
| 57 | return count, err |
| 58 | } |
| 59 | |
| 60 | const followOrg = `-- name: FollowOrg :one |
| 61 | WITH inserted AS ( |
| 62 | INSERT INTO follows (follower_user_id, followee_org_id) |
| 63 | VALUES ($1, $2) |
| 64 | ON CONFLICT (follower_user_id, followee_org_id) |
| 65 | WHERE followee_org_id IS NOT NULL |
| 66 | DO NOTHING |
| 67 | RETURNING 1 |
| 68 | ) |
| 69 | SELECT EXISTS (SELECT 1 FROM inserted) AS inserted |
| 70 | ` |
| 71 | |
| 72 | type FollowOrgParams struct { |
| 73 | FollowerUserID int64 |
| 74 | FolloweeOrgID pgtype.Int8 |
| 75 | } |
| 76 | |
| 77 | func (q *Queries) FollowOrg(ctx context.Context, db DBTX, arg FollowOrgParams) (bool, error) { |
| 78 | row := db.QueryRow(ctx, followOrg, arg.FollowerUserID, arg.FolloweeOrgID) |
| 79 | var inserted bool |
| 80 | err := row.Scan(&inserted) |
| 81 | return inserted, err |
| 82 | } |
| 83 | |
| 84 | const followUser = `-- name: FollowUser :one |
| 85 | |
| 86 | WITH inserted AS ( |
| 87 | INSERT INTO follows (follower_user_id, followee_user_id) |
| 88 | VALUES ($1, $2) |
| 89 | ON CONFLICT (follower_user_id, followee_user_id) |
| 90 | WHERE followee_user_id IS NOT NULL |
| 91 | DO NOTHING |
| 92 | RETURNING 1 |
| 93 | ) |
| 94 | SELECT EXISTS (SELECT 1 FROM inserted) AS inserted |
| 95 | ` |
| 96 | |
| 97 | type FollowUserParams struct { |
| 98 | FollowerUserID int64 |
| 99 | FolloweeUserID pgtype.Int8 |
| 100 | } |
| 101 | |
| 102 | // ─── follows ─────────────────────────────────────────────────────── |
| 103 | func (q *Queries) FollowUser(ctx context.Context, db DBTX, arg FollowUserParams) (bool, error) { |
| 104 | row := db.QueryRow(ctx, followUser, arg.FollowerUserID, arg.FolloweeUserID) |
| 105 | var inserted bool |
| 106 | err := row.Scan(&inserted) |
| 107 | return inserted, err |
| 108 | } |
| 109 | |
| 110 | const isFollowingOrg = `-- name: IsFollowingOrg :one |
| 111 | SELECT EXISTS ( |
| 112 | SELECT 1 FROM follows |
| 113 | WHERE follower_user_id = $1 |
| 114 | AND followee_org_id = $2 |
| 115 | ) AS following |
| 116 | ` |
| 117 | |
| 118 | type IsFollowingOrgParams struct { |
| 119 | FollowerUserID int64 |
| 120 | FolloweeOrgID pgtype.Int8 |
| 121 | } |
| 122 | |
| 123 | func (q *Queries) IsFollowingOrg(ctx context.Context, db DBTX, arg IsFollowingOrgParams) (bool, error) { |
| 124 | row := db.QueryRow(ctx, isFollowingOrg, arg.FollowerUserID, arg.FolloweeOrgID) |
| 125 | var following bool |
| 126 | err := row.Scan(&following) |
| 127 | return following, err |
| 128 | } |
| 129 | |
| 130 | const isFollowingUser = `-- name: IsFollowingUser :one |
| 131 | SELECT EXISTS ( |
| 132 | SELECT 1 FROM follows |
| 133 | WHERE follower_user_id = $1 |
| 134 | AND followee_user_id = $2 |
| 135 | ) AS following |
| 136 | ` |
| 137 | |
| 138 | type IsFollowingUserParams struct { |
| 139 | FollowerUserID int64 |
| 140 | FolloweeUserID pgtype.Int8 |
| 141 | } |
| 142 | |
| 143 | func (q *Queries) IsFollowingUser(ctx context.Context, db DBTX, arg IsFollowingUserParams) (bool, error) { |
| 144 | row := db.QueryRow(ctx, isFollowingUser, arg.FollowerUserID, arg.FolloweeUserID) |
| 145 | var following bool |
| 146 | err := row.Scan(&following) |
| 147 | return following, err |
| 148 | } |
| 149 | |
| 150 | const listFollowersForOrg = `-- name: ListFollowersForOrg :many |
| 151 | SELECT f.follower_user_id AS user_id, f.followed_at, u.username, u.display_name |
| 152 | FROM follows f |
| 153 | JOIN users u ON u.id = f.follower_user_id |
| 154 | WHERE f.followee_org_id = $1 |
| 155 | AND u.suspended_at IS NULL |
| 156 | AND u.deleted_at IS NULL |
| 157 | ORDER BY f.followed_at DESC, f.id DESC |
| 158 | LIMIT $2 OFFSET $3 |
| 159 | ` |
| 160 | |
| 161 | type ListFollowersForOrgParams struct { |
| 162 | FolloweeOrgID pgtype.Int8 |
| 163 | Limit int32 |
| 164 | Offset int32 |
| 165 | } |
| 166 | |
| 167 | type ListFollowersForOrgRow struct { |
| 168 | UserID int64 |
| 169 | FollowedAt pgtype.Timestamptz |
| 170 | Username string |
| 171 | DisplayName string |
| 172 | } |
| 173 | |
| 174 | func (q *Queries) ListFollowersForOrg(ctx context.Context, db DBTX, arg ListFollowersForOrgParams) ([]ListFollowersForOrgRow, error) { |
| 175 | rows, err := db.Query(ctx, listFollowersForOrg, arg.FolloweeOrgID, arg.Limit, arg.Offset) |
| 176 | if err != nil { |
| 177 | return nil, err |
| 178 | } |
| 179 | defer rows.Close() |
| 180 | items := []ListFollowersForOrgRow{} |
| 181 | for rows.Next() { |
| 182 | var i ListFollowersForOrgRow |
| 183 | if err := rows.Scan( |
| 184 | &i.UserID, |
| 185 | &i.FollowedAt, |
| 186 | &i.Username, |
| 187 | &i.DisplayName, |
| 188 | ); err != nil { |
| 189 | return nil, err |
| 190 | } |
| 191 | items = append(items, i) |
| 192 | } |
| 193 | if err := rows.Err(); err != nil { |
| 194 | return nil, err |
| 195 | } |
| 196 | return items, nil |
| 197 | } |
| 198 | |
| 199 | const listFollowersForUser = `-- name: ListFollowersForUser :many |
| 200 | SELECT f.follower_user_id AS user_id, f.followed_at, u.username, u.display_name |
| 201 | FROM follows f |
| 202 | JOIN users u ON u.id = f.follower_user_id |
| 203 | WHERE f.followee_user_id = $1 |
| 204 | AND u.suspended_at IS NULL |
| 205 | AND u.deleted_at IS NULL |
| 206 | ORDER BY f.followed_at DESC, f.id DESC |
| 207 | LIMIT $2 OFFSET $3 |
| 208 | ` |
| 209 | |
| 210 | type ListFollowersForUserParams struct { |
| 211 | FolloweeUserID pgtype.Int8 |
| 212 | Limit int32 |
| 213 | Offset int32 |
| 214 | } |
| 215 | |
| 216 | type ListFollowersForUserRow struct { |
| 217 | UserID int64 |
| 218 | FollowedAt pgtype.Timestamptz |
| 219 | Username string |
| 220 | DisplayName string |
| 221 | } |
| 222 | |
| 223 | func (q *Queries) ListFollowersForUser(ctx context.Context, db DBTX, arg ListFollowersForUserParams) ([]ListFollowersForUserRow, error) { |
| 224 | rows, err := db.Query(ctx, listFollowersForUser, arg.FolloweeUserID, arg.Limit, arg.Offset) |
| 225 | if err != nil { |
| 226 | return nil, err |
| 227 | } |
| 228 | defer rows.Close() |
| 229 | items := []ListFollowersForUserRow{} |
| 230 | for rows.Next() { |
| 231 | var i ListFollowersForUserRow |
| 232 | if err := rows.Scan( |
| 233 | &i.UserID, |
| 234 | &i.FollowedAt, |
| 235 | &i.Username, |
| 236 | &i.DisplayName, |
| 237 | ); err != nil { |
| 238 | return nil, err |
| 239 | } |
| 240 | items = append(items, i) |
| 241 | } |
| 242 | if err := rows.Err(); err != nil { |
| 243 | return nil, err |
| 244 | } |
| 245 | return items, nil |
| 246 | } |
| 247 | |
| 248 | const listFollowingOrgsForUser = `-- name: ListFollowingOrgsForUser :many |
| 249 | SELECT f.followee_org_id AS org_id, f.followed_at, o.slug, o.display_name |
| 250 | FROM follows f |
| 251 | JOIN orgs o ON o.id = f.followee_org_id |
| 252 | WHERE f.follower_user_id = $1 |
| 253 | AND o.suspended_at IS NULL |
| 254 | AND o.deleted_at IS NULL |
| 255 | ORDER BY f.followed_at DESC, f.id DESC |
| 256 | LIMIT $2 OFFSET $3 |
| 257 | ` |
| 258 | |
| 259 | type ListFollowingOrgsForUserParams struct { |
| 260 | FollowerUserID int64 |
| 261 | Limit int32 |
| 262 | Offset int32 |
| 263 | } |
| 264 | |
| 265 | type ListFollowingOrgsForUserRow struct { |
| 266 | OrgID pgtype.Int8 |
| 267 | FollowedAt pgtype.Timestamptz |
| 268 | Slug string |
| 269 | DisplayName string |
| 270 | } |
| 271 | |
| 272 | func (q *Queries) ListFollowingOrgsForUser(ctx context.Context, db DBTX, arg ListFollowingOrgsForUserParams) ([]ListFollowingOrgsForUserRow, error) { |
| 273 | rows, err := db.Query(ctx, listFollowingOrgsForUser, arg.FollowerUserID, arg.Limit, arg.Offset) |
| 274 | if err != nil { |
| 275 | return nil, err |
| 276 | } |
| 277 | defer rows.Close() |
| 278 | items := []ListFollowingOrgsForUserRow{} |
| 279 | for rows.Next() { |
| 280 | var i ListFollowingOrgsForUserRow |
| 281 | if err := rows.Scan( |
| 282 | &i.OrgID, |
| 283 | &i.FollowedAt, |
| 284 | &i.Slug, |
| 285 | &i.DisplayName, |
| 286 | ); err != nil { |
| 287 | return nil, err |
| 288 | } |
| 289 | items = append(items, i) |
| 290 | } |
| 291 | if err := rows.Err(); err != nil { |
| 292 | return nil, err |
| 293 | } |
| 294 | return items, nil |
| 295 | } |
| 296 | |
| 297 | const listFollowingUsersForUser = `-- name: ListFollowingUsersForUser :many |
| 298 | SELECT f.followee_user_id AS user_id, f.followed_at, u.username, u.display_name |
| 299 | FROM follows f |
| 300 | JOIN users u ON u.id = f.followee_user_id |
| 301 | WHERE f.follower_user_id = $1 |
| 302 | AND u.suspended_at IS NULL |
| 303 | AND u.deleted_at IS NULL |
| 304 | ORDER BY f.followed_at DESC, f.id DESC |
| 305 | LIMIT $2 OFFSET $3 |
| 306 | ` |
| 307 | |
| 308 | type ListFollowingUsersForUserParams struct { |
| 309 | FollowerUserID int64 |
| 310 | Limit int32 |
| 311 | Offset int32 |
| 312 | } |
| 313 | |
| 314 | type ListFollowingUsersForUserRow struct { |
| 315 | UserID pgtype.Int8 |
| 316 | FollowedAt pgtype.Timestamptz |
| 317 | Username string |
| 318 | DisplayName string |
| 319 | } |
| 320 | |
| 321 | func (q *Queries) ListFollowingUsersForUser(ctx context.Context, db DBTX, arg ListFollowingUsersForUserParams) ([]ListFollowingUsersForUserRow, error) { |
| 322 | rows, err := db.Query(ctx, listFollowingUsersForUser, arg.FollowerUserID, arg.Limit, arg.Offset) |
| 323 | if err != nil { |
| 324 | return nil, err |
| 325 | } |
| 326 | defer rows.Close() |
| 327 | items := []ListFollowingUsersForUserRow{} |
| 328 | for rows.Next() { |
| 329 | var i ListFollowingUsersForUserRow |
| 330 | if err := rows.Scan( |
| 331 | &i.UserID, |
| 332 | &i.FollowedAt, |
| 333 | &i.Username, |
| 334 | &i.DisplayName, |
| 335 | ); err != nil { |
| 336 | return nil, err |
| 337 | } |
| 338 | items = append(items, i) |
| 339 | } |
| 340 | if err := rows.Err(); err != nil { |
| 341 | return nil, err |
| 342 | } |
| 343 | return items, nil |
| 344 | } |
| 345 | |
| 346 | const unfollowOrg = `-- name: UnfollowOrg :execrows |
| 347 | DELETE FROM follows |
| 348 | WHERE follower_user_id = $1 |
| 349 | AND followee_org_id = $2 |
| 350 | ` |
| 351 | |
| 352 | type UnfollowOrgParams struct { |
| 353 | FollowerUserID int64 |
| 354 | FolloweeOrgID pgtype.Int8 |
| 355 | } |
| 356 | |
| 357 | func (q *Queries) UnfollowOrg(ctx context.Context, db DBTX, arg UnfollowOrgParams) (int64, error) { |
| 358 | result, err := db.Exec(ctx, unfollowOrg, arg.FollowerUserID, arg.FolloweeOrgID) |
| 359 | if err != nil { |
| 360 | return 0, err |
| 361 | } |
| 362 | return result.RowsAffected(), nil |
| 363 | } |
| 364 | |
| 365 | const unfollowUser = `-- name: UnfollowUser :execrows |
| 366 | DELETE FROM follows |
| 367 | WHERE follower_user_id = $1 |
| 368 | AND followee_user_id = $2 |
| 369 | ` |
| 370 | |
| 371 | type UnfollowUserParams struct { |
| 372 | FollowerUserID int64 |
| 373 | FolloweeUserID pgtype.Int8 |
| 374 | } |
| 375 | |
| 376 | func (q *Queries) UnfollowUser(ctx context.Context, db DBTX, arg UnfollowUserParams) (int64, error) { |
| 377 | result, err := db.Exec(ctx, unfollowUser, arg.FollowerUserID, arg.FolloweeUserID) |
| 378 | if err != nil { |
| 379 | return 0, err |
| 380 | } |
| 381 | return result.RowsAffected(), nil |
| 382 | } |
| 383 |