query.sql.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. // Code generated by sqlc. DO NOT EDIT.
  2. // versions:
  3. // sqlc v1.13.0
  4. // source: query.sql
  5. package db
  6. import (
  7. "context"
  8. "database/sql"
  9. "time"
  10. )
  11. const addFollower = `-- name: AddFollower :exec
  12. INSERT INTO ap_followers(iri, inbox, request, request_object, name, username, image, approved_at) values($1, $2, $3, $4, $5, $6, $7, $8)
  13. `
  14. type AddFollowerParams struct {
  15. Iri string
  16. Inbox string
  17. Request string
  18. RequestObject []byte
  19. Name sql.NullString
  20. Username string
  21. Image sql.NullString
  22. ApprovedAt sql.NullTime
  23. }
  24. func (q *Queries) AddFollower(ctx context.Context, arg AddFollowerParams) error {
  25. _, err := q.db.ExecContext(ctx, addFollower,
  26. arg.Iri,
  27. arg.Inbox,
  28. arg.Request,
  29. arg.RequestObject,
  30. arg.Name,
  31. arg.Username,
  32. arg.Image,
  33. arg.ApprovedAt,
  34. )
  35. return err
  36. }
  37. const addNotification = `-- name: AddNotification :exec
  38. INSERT INTO notifications (channel, destination) VALUES($1, $2)
  39. `
  40. type AddNotificationParams struct {
  41. Channel string
  42. Destination string
  43. }
  44. func (q *Queries) AddNotification(ctx context.Context, arg AddNotificationParams) error {
  45. _, err := q.db.ExecContext(ctx, addNotification, arg.Channel, arg.Destination)
  46. return err
  47. }
  48. const addToAcceptedActivities = `-- name: AddToAcceptedActivities :exec
  49. INSERT INTO ap_accepted_activities(iri, actor, type, timestamp) values($1, $2, $3, $4)
  50. `
  51. type AddToAcceptedActivitiesParams struct {
  52. Iri string
  53. Actor string
  54. Type string
  55. Timestamp time.Time
  56. }
  57. func (q *Queries) AddToAcceptedActivities(ctx context.Context, arg AddToAcceptedActivitiesParams) error {
  58. _, err := q.db.ExecContext(ctx, addToAcceptedActivities,
  59. arg.Iri,
  60. arg.Actor,
  61. arg.Type,
  62. arg.Timestamp,
  63. )
  64. return err
  65. }
  66. const addToOutbox = `-- name: AddToOutbox :exec
  67. INSERT INTO ap_outbox(iri, value, type, live_notification) values($1, $2, $3, $4)
  68. `
  69. type AddToOutboxParams struct {
  70. Iri string
  71. Value []byte
  72. Type string
  73. LiveNotification sql.NullBool
  74. }
  75. func (q *Queries) AddToOutbox(ctx context.Context, arg AddToOutboxParams) error {
  76. _, err := q.db.ExecContext(ctx, addToOutbox,
  77. arg.Iri,
  78. arg.Value,
  79. arg.Type,
  80. arg.LiveNotification,
  81. )
  82. return err
  83. }
  84. const approveFederationFollower = `-- name: ApproveFederationFollower :exec
  85. UPDATE ap_followers SET approved_at = $1, disabled_at = null WHERE iri = $2
  86. `
  87. type ApproveFederationFollowerParams struct {
  88. ApprovedAt sql.NullTime
  89. Iri string
  90. }
  91. func (q *Queries) ApproveFederationFollower(ctx context.Context, arg ApproveFederationFollowerParams) error {
  92. _, err := q.db.ExecContext(ctx, approveFederationFollower, arg.ApprovedAt, arg.Iri)
  93. return err
  94. }
  95. const banIPAddress = `-- name: BanIPAddress :exec
  96. INSERT INTO ip_bans(ip_address, notes) values($1, $2)
  97. `
  98. type BanIPAddressParams struct {
  99. IpAddress string
  100. Notes sql.NullString
  101. }
  102. func (q *Queries) BanIPAddress(ctx context.Context, arg BanIPAddressParams) error {
  103. _, err := q.db.ExecContext(ctx, banIPAddress, arg.IpAddress, arg.Notes)
  104. return err
  105. }
  106. const doesInboundActivityExist = `-- name: DoesInboundActivityExist :one
  107. SELECT count(*) FROM ap_accepted_activities WHERE iri = $1 AND actor = $2 AND TYPE = $3
  108. `
  109. type DoesInboundActivityExistParams struct {
  110. Iri string
  111. Actor string
  112. Type string
  113. }
  114. func (q *Queries) DoesInboundActivityExist(ctx context.Context, arg DoesInboundActivityExistParams) (int64, error) {
  115. row := q.db.QueryRowContext(ctx, doesInboundActivityExist, arg.Iri, arg.Actor, arg.Type)
  116. var count int64
  117. err := row.Scan(&count)
  118. return count, err
  119. }
  120. const getFederationFollowerApprovalRequests = `-- name: GetFederationFollowerApprovalRequests :many
  121. SELECT iri, inbox, name, username, image, created_at FROM ap_followers WHERE approved_at IS null AND disabled_at is null
  122. `
  123. type GetFederationFollowerApprovalRequestsRow struct {
  124. Iri string
  125. Inbox string
  126. Name sql.NullString
  127. Username string
  128. Image sql.NullString
  129. CreatedAt sql.NullTime
  130. }
  131. func (q *Queries) GetFederationFollowerApprovalRequests(ctx context.Context) ([]GetFederationFollowerApprovalRequestsRow, error) {
  132. rows, err := q.db.QueryContext(ctx, getFederationFollowerApprovalRequests)
  133. if err != nil {
  134. return nil, err
  135. }
  136. defer rows.Close()
  137. var items []GetFederationFollowerApprovalRequestsRow
  138. for rows.Next() {
  139. var i GetFederationFollowerApprovalRequestsRow
  140. if err := rows.Scan(
  141. &i.Iri,
  142. &i.Inbox,
  143. &i.Name,
  144. &i.Username,
  145. &i.Image,
  146. &i.CreatedAt,
  147. ); err != nil {
  148. return nil, err
  149. }
  150. items = append(items, i)
  151. }
  152. if err := rows.Close(); err != nil {
  153. return nil, err
  154. }
  155. if err := rows.Err(); err != nil {
  156. return nil, err
  157. }
  158. return items, nil
  159. }
  160. const getFederationFollowersWithOffset = `-- name: GetFederationFollowersWithOffset :many
  161. SELECT iri, inbox, name, username, image, created_at FROM ap_followers WHERE approved_at is not null ORDER BY created_at DESC LIMIT $1 OFFSET $2
  162. `
  163. type GetFederationFollowersWithOffsetParams struct {
  164. Limit int32
  165. Offset int32
  166. }
  167. type GetFederationFollowersWithOffsetRow struct {
  168. Iri string
  169. Inbox string
  170. Name sql.NullString
  171. Username string
  172. Image sql.NullString
  173. CreatedAt sql.NullTime
  174. }
  175. func (q *Queries) GetFederationFollowersWithOffset(ctx context.Context, arg GetFederationFollowersWithOffsetParams) ([]GetFederationFollowersWithOffsetRow, error) {
  176. rows, err := q.db.QueryContext(ctx, getFederationFollowersWithOffset, arg.Limit, arg.Offset)
  177. if err != nil {
  178. return nil, err
  179. }
  180. defer rows.Close()
  181. var items []GetFederationFollowersWithOffsetRow
  182. for rows.Next() {
  183. var i GetFederationFollowersWithOffsetRow
  184. if err := rows.Scan(
  185. &i.Iri,
  186. &i.Inbox,
  187. &i.Name,
  188. &i.Username,
  189. &i.Image,
  190. &i.CreatedAt,
  191. ); err != nil {
  192. return nil, err
  193. }
  194. items = append(items, i)
  195. }
  196. if err := rows.Close(); err != nil {
  197. return nil, err
  198. }
  199. if err := rows.Err(); err != nil {
  200. return nil, err
  201. }
  202. return items, nil
  203. }
  204. const getFollowerByIRI = `-- name: GetFollowerByIRI :one
  205. SELECT iri, inbox, name, username, image, request, request_object, created_at, approved_at, disabled_at FROM ap_followers WHERE iri = $1
  206. `
  207. func (q *Queries) GetFollowerByIRI(ctx context.Context, iri string) (ApFollower, error) {
  208. row := q.db.QueryRowContext(ctx, getFollowerByIRI, iri)
  209. var i ApFollower
  210. err := row.Scan(
  211. &i.Iri,
  212. &i.Inbox,
  213. &i.Name,
  214. &i.Username,
  215. &i.Image,
  216. &i.Request,
  217. &i.RequestObject,
  218. &i.CreatedAt,
  219. &i.ApprovedAt,
  220. &i.DisabledAt,
  221. )
  222. return i, err
  223. }
  224. const getFollowerCount = `-- name: GetFollowerCount :one
  225. SElECT count(*) FROM ap_followers WHERE approved_at is not null
  226. `
  227. // Queries added to query.sql must be compiled into Go code with sqlc. Read README.md for details.
  228. // Federation related queries.
  229. func (q *Queries) GetFollowerCount(ctx context.Context) (int64, error) {
  230. row := q.db.QueryRowContext(ctx, getFollowerCount)
  231. var count int64
  232. err := row.Scan(&count)
  233. return count, err
  234. }
  235. const getIPAddressBans = `-- name: GetIPAddressBans :many
  236. SELECT ip_address, notes, created_at FROM ip_bans
  237. `
  238. func (q *Queries) GetIPAddressBans(ctx context.Context) ([]IpBan, error) {
  239. rows, err := q.db.QueryContext(ctx, getIPAddressBans)
  240. if err != nil {
  241. return nil, err
  242. }
  243. defer rows.Close()
  244. var items []IpBan
  245. for rows.Next() {
  246. var i IpBan
  247. if err := rows.Scan(&i.IpAddress, &i.Notes, &i.CreatedAt); err != nil {
  248. return nil, err
  249. }
  250. items = append(items, i)
  251. }
  252. if err := rows.Close(); err != nil {
  253. return nil, err
  254. }
  255. if err := rows.Err(); err != nil {
  256. return nil, err
  257. }
  258. return items, nil
  259. }
  260. const getInboundActivitiesWithOffset = `-- name: GetInboundActivitiesWithOffset :many
  261. SELECT iri, actor, type, timestamp FROM ap_accepted_activities ORDER BY timestamp DESC LIMIT $1 OFFSET $2
  262. `
  263. type GetInboundActivitiesWithOffsetParams struct {
  264. Limit int32
  265. Offset int32
  266. }
  267. type GetInboundActivitiesWithOffsetRow struct {
  268. Iri string
  269. Actor string
  270. Type string
  271. Timestamp time.Time
  272. }
  273. func (q *Queries) GetInboundActivitiesWithOffset(ctx context.Context, arg GetInboundActivitiesWithOffsetParams) ([]GetInboundActivitiesWithOffsetRow, error) {
  274. rows, err := q.db.QueryContext(ctx, getInboundActivitiesWithOffset, arg.Limit, arg.Offset)
  275. if err != nil {
  276. return nil, err
  277. }
  278. defer rows.Close()
  279. var items []GetInboundActivitiesWithOffsetRow
  280. for rows.Next() {
  281. var i GetInboundActivitiesWithOffsetRow
  282. if err := rows.Scan(
  283. &i.Iri,
  284. &i.Actor,
  285. &i.Type,
  286. &i.Timestamp,
  287. ); err != nil {
  288. return nil, err
  289. }
  290. items = append(items, i)
  291. }
  292. if err := rows.Close(); err != nil {
  293. return nil, err
  294. }
  295. if err := rows.Err(); err != nil {
  296. return nil, err
  297. }
  298. return items, nil
  299. }
  300. const getInboundActivityCount = `-- name: GetInboundActivityCount :one
  301. SELECT count(*) FROM ap_accepted_activities
  302. `
  303. func (q *Queries) GetInboundActivityCount(ctx context.Context) (int64, error) {
  304. row := q.db.QueryRowContext(ctx, getInboundActivityCount)
  305. var count int64
  306. err := row.Scan(&count)
  307. return count, err
  308. }
  309. const getLocalPostCount = `-- name: GetLocalPostCount :one
  310. SElECT count(*) FROM ap_outbox
  311. `
  312. func (q *Queries) GetLocalPostCount(ctx context.Context) (int64, error) {
  313. row := q.db.QueryRowContext(ctx, getLocalPostCount)
  314. var count int64
  315. err := row.Scan(&count)
  316. return count, err
  317. }
  318. const getNotificationDestinationsForChannel = `-- name: GetNotificationDestinationsForChannel :many
  319. SELECT destination FROM notifications WHERE channel = $1
  320. `
  321. func (q *Queries) GetNotificationDestinationsForChannel(ctx context.Context, channel string) ([]string, error) {
  322. rows, err := q.db.QueryContext(ctx, getNotificationDestinationsForChannel, channel)
  323. if err != nil {
  324. return nil, err
  325. }
  326. defer rows.Close()
  327. var items []string
  328. for rows.Next() {
  329. var destination string
  330. if err := rows.Scan(&destination); err != nil {
  331. return nil, err
  332. }
  333. items = append(items, destination)
  334. }
  335. if err := rows.Close(); err != nil {
  336. return nil, err
  337. }
  338. if err := rows.Err(); err != nil {
  339. return nil, err
  340. }
  341. return items, nil
  342. }
  343. const getObjectFromOutboxByID = `-- name: GetObjectFromOutboxByID :one
  344. SELECT value FROM ap_outbox WHERE iri = $1
  345. `
  346. func (q *Queries) GetObjectFromOutboxByID(ctx context.Context, iri string) ([]byte, error) {
  347. row := q.db.QueryRowContext(ctx, getObjectFromOutboxByID, iri)
  348. var value []byte
  349. err := row.Scan(&value)
  350. return value, err
  351. }
  352. const getObjectFromOutboxByIRI = `-- name: GetObjectFromOutboxByIRI :one
  353. SELECT value, live_notification, created_at FROM ap_outbox WHERE iri = $1
  354. `
  355. type GetObjectFromOutboxByIRIRow struct {
  356. Value []byte
  357. LiveNotification sql.NullBool
  358. CreatedAt sql.NullTime
  359. }
  360. func (q *Queries) GetObjectFromOutboxByIRI(ctx context.Context, iri string) (GetObjectFromOutboxByIRIRow, error) {
  361. row := q.db.QueryRowContext(ctx, getObjectFromOutboxByIRI, iri)
  362. var i GetObjectFromOutboxByIRIRow
  363. err := row.Scan(&i.Value, &i.LiveNotification, &i.CreatedAt)
  364. return i, err
  365. }
  366. const getOutboxWithOffset = `-- name: GetOutboxWithOffset :many
  367. SELECT value FROM ap_outbox LIMIT $1 OFFSET $2
  368. `
  369. type GetOutboxWithOffsetParams struct {
  370. Limit int32
  371. Offset int32
  372. }
  373. func (q *Queries) GetOutboxWithOffset(ctx context.Context, arg GetOutboxWithOffsetParams) ([][]byte, error) {
  374. rows, err := q.db.QueryContext(ctx, getOutboxWithOffset, arg.Limit, arg.Offset)
  375. if err != nil {
  376. return nil, err
  377. }
  378. defer rows.Close()
  379. var items [][]byte
  380. for rows.Next() {
  381. var value []byte
  382. if err := rows.Scan(&value); err != nil {
  383. return nil, err
  384. }
  385. items = append(items, value)
  386. }
  387. if err := rows.Close(); err != nil {
  388. return nil, err
  389. }
  390. if err := rows.Err(); err != nil {
  391. return nil, err
  392. }
  393. return items, nil
  394. }
  395. const getRejectedAndBlockedFollowers = `-- name: GetRejectedAndBlockedFollowers :many
  396. SELECT iri, name, username, image, created_at, disabled_at FROM ap_followers WHERE disabled_at is not null
  397. `
  398. type GetRejectedAndBlockedFollowersRow struct {
  399. Iri string
  400. Name sql.NullString
  401. Username string
  402. Image sql.NullString
  403. CreatedAt sql.NullTime
  404. DisabledAt sql.NullTime
  405. }
  406. func (q *Queries) GetRejectedAndBlockedFollowers(ctx context.Context) ([]GetRejectedAndBlockedFollowersRow, error) {
  407. rows, err := q.db.QueryContext(ctx, getRejectedAndBlockedFollowers)
  408. if err != nil {
  409. return nil, err
  410. }
  411. defer rows.Close()
  412. var items []GetRejectedAndBlockedFollowersRow
  413. for rows.Next() {
  414. var i GetRejectedAndBlockedFollowersRow
  415. if err := rows.Scan(
  416. &i.Iri,
  417. &i.Name,
  418. &i.Username,
  419. &i.Image,
  420. &i.CreatedAt,
  421. &i.DisabledAt,
  422. ); err != nil {
  423. return nil, err
  424. }
  425. items = append(items, i)
  426. }
  427. if err := rows.Close(); err != nil {
  428. return nil, err
  429. }
  430. if err := rows.Err(); err != nil {
  431. return nil, err
  432. }
  433. return items, nil
  434. }
  435. const isIPAddressBlocked = `-- name: IsIPAddressBlocked :one
  436. SELECT count(*) FROM ip_bans WHERE ip_address = $1
  437. `
  438. func (q *Queries) IsIPAddressBlocked(ctx context.Context, ipAddress string) (int64, error) {
  439. row := q.db.QueryRowContext(ctx, isIPAddressBlocked, ipAddress)
  440. var count int64
  441. err := row.Scan(&count)
  442. return count, err
  443. }
  444. const rejectFederationFollower = `-- name: RejectFederationFollower :exec
  445. UPDATE ap_followers SET approved_at = null, disabled_at = $1 WHERE iri = $2
  446. `
  447. type RejectFederationFollowerParams struct {
  448. DisabledAt sql.NullTime
  449. Iri string
  450. }
  451. func (q *Queries) RejectFederationFollower(ctx context.Context, arg RejectFederationFollowerParams) error {
  452. _, err := q.db.ExecContext(ctx, rejectFederationFollower, arg.DisabledAt, arg.Iri)
  453. return err
  454. }
  455. const removeFollowerByIRI = `-- name: RemoveFollowerByIRI :exec
  456. DELETE FROM ap_followers WHERE iri = $1
  457. `
  458. func (q *Queries) RemoveFollowerByIRI(ctx context.Context, iri string) error {
  459. _, err := q.db.ExecContext(ctx, removeFollowerByIRI, iri)
  460. return err
  461. }
  462. const removeIPAddressBan = `-- name: RemoveIPAddressBan :exec
  463. DELETE FROM ip_bans WHERE ip_address = $1
  464. `
  465. func (q *Queries) RemoveIPAddressBan(ctx context.Context, ipAddress string) error {
  466. _, err := q.db.ExecContext(ctx, removeIPAddressBan, ipAddress)
  467. return err
  468. }
  469. const removeNotificationDestinationForChannel = `-- name: RemoveNotificationDestinationForChannel :exec
  470. DELETE FROM notifications WHERE channel = $1 AND destination = $2
  471. `
  472. type RemoveNotificationDestinationForChannelParams struct {
  473. Channel string
  474. Destination string
  475. }
  476. func (q *Queries) RemoveNotificationDestinationForChannel(ctx context.Context, arg RemoveNotificationDestinationForChannelParams) error {
  477. _, err := q.db.ExecContext(ctx, removeNotificationDestinationForChannel, arg.Channel, arg.Destination)
  478. return err
  479. }
  480. const updateFollowerByIRI = `-- name: UpdateFollowerByIRI :exec
  481. UPDATE ap_followers SET inbox = $1, name = $2, username = $3, image = $4 WHERE iri = $5
  482. `
  483. type UpdateFollowerByIRIParams struct {
  484. Inbox string
  485. Name sql.NullString
  486. Username string
  487. Image sql.NullString
  488. Iri string
  489. }
  490. func (q *Queries) UpdateFollowerByIRI(ctx context.Context, arg UpdateFollowerByIRIParams) error {
  491. _, err := q.db.ExecContext(ctx, updateFollowerByIRI,
  492. arg.Inbox,
  493. arg.Name,
  494. arg.Username,
  495. arg.Image,
  496. arg.Iri,
  497. )
  498. return err
  499. }