query.sql.go 15 KB

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