query.sql.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. // Code generated by sqlc. DO NOT EDIT.
  2. // versions:
  3. // sqlc v1.19.1
  4. // source: query.sql
  5. package db
  6. import (
  7. "context"
  8. "database/sql"
  9. "time"
  10. )
  11. const addAccessTokenForUser = `-- name: AddAccessTokenForUser :exec
  12. INSERT INTO user_access_tokens(token, user_id) values($1, $2)
  13. `
  14. type AddAccessTokenForUserParams struct {
  15. Token string
  16. UserID string
  17. }
  18. func (q *Queries) AddAccessTokenForUser(ctx context.Context, arg AddAccessTokenForUserParams) error {
  19. _, err := q.db.ExecContext(ctx, addAccessTokenForUser, arg.Token, arg.UserID)
  20. return err
  21. }
  22. const addAuthForUser = `-- name: AddAuthForUser :exec
  23. INSERT INTO auth(user_id, token, type) values($1, $2, $3)
  24. `
  25. type AddAuthForUserParams struct {
  26. UserID string
  27. Token string
  28. Type string
  29. }
  30. func (q *Queries) AddAuthForUser(ctx context.Context, arg AddAuthForUserParams) error {
  31. _, err := q.db.ExecContext(ctx, addAuthForUser, arg.UserID, arg.Token, arg.Type)
  32. return err
  33. }
  34. const addFollower = `-- name: AddFollower :exec
  35. INSERT INTO ap_followers(iri, inbox, request, request_object, name, username, image, approved_at) values($1, $2, $3, $4, $5, $6, $7, $8)
  36. `
  37. type AddFollowerParams struct {
  38. Iri string
  39. Inbox string
  40. Request string
  41. RequestObject []byte
  42. Name sql.NullString
  43. Username string
  44. Image sql.NullString
  45. ApprovedAt sql.NullTime
  46. }
  47. func (q *Queries) AddFollower(ctx context.Context, arg AddFollowerParams) error {
  48. _, err := q.db.ExecContext(ctx, addFollower,
  49. arg.Iri,
  50. arg.Inbox,
  51. arg.Request,
  52. arg.RequestObject,
  53. arg.Name,
  54. arg.Username,
  55. arg.Image,
  56. arg.ApprovedAt,
  57. )
  58. return err
  59. }
  60. const addNotification = `-- name: AddNotification :exec
  61. INSERT INTO notifications (channel, destination) VALUES($1, $2)
  62. `
  63. type AddNotificationParams struct {
  64. Channel string
  65. Destination string
  66. }
  67. func (q *Queries) AddNotification(ctx context.Context, arg AddNotificationParams) error {
  68. _, err := q.db.ExecContext(ctx, addNotification, arg.Channel, arg.Destination)
  69. return err
  70. }
  71. const addToAcceptedActivities = `-- name: AddToAcceptedActivities :exec
  72. INSERT INTO ap_accepted_activities(iri, actor, type, timestamp) values($1, $2, $3, $4)
  73. `
  74. type AddToAcceptedActivitiesParams struct {
  75. Iri string
  76. Actor string
  77. Type string
  78. Timestamp time.Time
  79. }
  80. func (q *Queries) AddToAcceptedActivities(ctx context.Context, arg AddToAcceptedActivitiesParams) error {
  81. _, err := q.db.ExecContext(ctx, addToAcceptedActivities,
  82. arg.Iri,
  83. arg.Actor,
  84. arg.Type,
  85. arg.Timestamp,
  86. )
  87. return err
  88. }
  89. const addToOutbox = `-- name: AddToOutbox :exec
  90. INSERT INTO ap_outbox(iri, value, type, live_notification) values($1, $2, $3, $4)
  91. `
  92. type AddToOutboxParams struct {
  93. Iri string
  94. Value []byte
  95. Type string
  96. LiveNotification sql.NullBool
  97. }
  98. func (q *Queries) AddToOutbox(ctx context.Context, arg AddToOutboxParams) error {
  99. _, err := q.db.ExecContext(ctx, addToOutbox,
  100. arg.Iri,
  101. arg.Value,
  102. arg.Type,
  103. arg.LiveNotification,
  104. )
  105. return err
  106. }
  107. const approveFederationFollower = `-- name: ApproveFederationFollower :exec
  108. UPDATE ap_followers SET approved_at = $1, disabled_at = null WHERE iri = $2
  109. `
  110. type ApproveFederationFollowerParams struct {
  111. ApprovedAt sql.NullTime
  112. Iri string
  113. }
  114. func (q *Queries) ApproveFederationFollower(ctx context.Context, arg ApproveFederationFollowerParams) error {
  115. _, err := q.db.ExecContext(ctx, approveFederationFollower, arg.ApprovedAt, arg.Iri)
  116. return err
  117. }
  118. const banIPAddress = `-- name: BanIPAddress :exec
  119. INSERT INTO ip_bans(ip_address, notes) values($1, $2)
  120. `
  121. type BanIPAddressParams struct {
  122. IpAddress string
  123. Notes sql.NullString
  124. }
  125. func (q *Queries) BanIPAddress(ctx context.Context, arg BanIPAddressParams) error {
  126. _, err := q.db.ExecContext(ctx, banIPAddress, arg.IpAddress, arg.Notes)
  127. return err
  128. }
  129. const changeDisplayColor = `-- name: ChangeDisplayColor :exec
  130. UPDATE users SET display_color = $1 WHERE id = $2
  131. `
  132. type ChangeDisplayColorParams struct {
  133. DisplayColor int32
  134. ID string
  135. }
  136. func (q *Queries) ChangeDisplayColor(ctx context.Context, arg ChangeDisplayColorParams) error {
  137. _, err := q.db.ExecContext(ctx, changeDisplayColor, arg.DisplayColor, arg.ID)
  138. return err
  139. }
  140. const changeDisplayName = `-- name: ChangeDisplayName :exec
  141. UPDATE users SET display_name = $1, previous_names = previous_names || $2, namechanged_at = $3 WHERE id = $4
  142. `
  143. type ChangeDisplayNameParams struct {
  144. DisplayName string
  145. PreviousNames sql.NullString
  146. NamechangedAt sql.NullTime
  147. ID string
  148. }
  149. func (q *Queries) ChangeDisplayName(ctx context.Context, arg ChangeDisplayNameParams) error {
  150. _, err := q.db.ExecContext(ctx, changeDisplayName,
  151. arg.DisplayName,
  152. arg.PreviousNames,
  153. arg.NamechangedAt,
  154. arg.ID,
  155. )
  156. return err
  157. }
  158. const doesInboundActivityExist = `-- name: DoesInboundActivityExist :one
  159. SELECT count(*) FROM ap_accepted_activities WHERE iri = $1 AND actor = $2 AND TYPE = $3
  160. `
  161. type DoesInboundActivityExistParams struct {
  162. Iri string
  163. Actor string
  164. Type string
  165. }
  166. func (q *Queries) DoesInboundActivityExist(ctx context.Context, arg DoesInboundActivityExistParams) (int64, error) {
  167. row := q.db.QueryRowContext(ctx, doesInboundActivityExist, arg.Iri, arg.Actor, arg.Type)
  168. var count int64
  169. err := row.Scan(&count)
  170. return count, err
  171. }
  172. const getFederationFollowerApprovalRequests = `-- name: GetFederationFollowerApprovalRequests :many
  173. SELECT iri, inbox, name, username, image, created_at FROM ap_followers WHERE approved_at IS null AND disabled_at is null
  174. `
  175. type GetFederationFollowerApprovalRequestsRow struct {
  176. Iri string
  177. Inbox string
  178. Name sql.NullString
  179. Username string
  180. Image sql.NullString
  181. CreatedAt sql.NullTime
  182. }
  183. func (q *Queries) GetFederationFollowerApprovalRequests(ctx context.Context) ([]GetFederationFollowerApprovalRequestsRow, error) {
  184. rows, err := q.db.QueryContext(ctx, getFederationFollowerApprovalRequests)
  185. if err != nil {
  186. return nil, err
  187. }
  188. defer rows.Close()
  189. var items []GetFederationFollowerApprovalRequestsRow
  190. for rows.Next() {
  191. var i GetFederationFollowerApprovalRequestsRow
  192. if err := rows.Scan(
  193. &i.Iri,
  194. &i.Inbox,
  195. &i.Name,
  196. &i.Username,
  197. &i.Image,
  198. &i.CreatedAt,
  199. ); err != nil {
  200. return nil, err
  201. }
  202. items = append(items, i)
  203. }
  204. if err := rows.Close(); err != nil {
  205. return nil, err
  206. }
  207. if err := rows.Err(); err != nil {
  208. return nil, err
  209. }
  210. return items, nil
  211. }
  212. const getFederationFollowersWithOffset = `-- name: GetFederationFollowersWithOffset :many
  213. 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
  214. `
  215. type GetFederationFollowersWithOffsetParams struct {
  216. Limit int32
  217. Offset int32
  218. }
  219. type GetFederationFollowersWithOffsetRow struct {
  220. Iri string
  221. Inbox string
  222. Name sql.NullString
  223. Username string
  224. Image sql.NullString
  225. CreatedAt sql.NullTime
  226. }
  227. func (q *Queries) GetFederationFollowersWithOffset(ctx context.Context, arg GetFederationFollowersWithOffsetParams) ([]GetFederationFollowersWithOffsetRow, error) {
  228. rows, err := q.db.QueryContext(ctx, getFederationFollowersWithOffset, arg.Limit, arg.Offset)
  229. if err != nil {
  230. return nil, err
  231. }
  232. defer rows.Close()
  233. var items []GetFederationFollowersWithOffsetRow
  234. for rows.Next() {
  235. var i GetFederationFollowersWithOffsetRow
  236. if err := rows.Scan(
  237. &i.Iri,
  238. &i.Inbox,
  239. &i.Name,
  240. &i.Username,
  241. &i.Image,
  242. &i.CreatedAt,
  243. ); err != nil {
  244. return nil, err
  245. }
  246. items = append(items, i)
  247. }
  248. if err := rows.Close(); err != nil {
  249. return nil, err
  250. }
  251. if err := rows.Err(); err != nil {
  252. return nil, err
  253. }
  254. return items, nil
  255. }
  256. const getFollowerByIRI = `-- name: GetFollowerByIRI :one
  257. SELECT iri, inbox, name, username, image, request, request_object, created_at, approved_at, disabled_at FROM ap_followers WHERE iri = $1
  258. `
  259. func (q *Queries) GetFollowerByIRI(ctx context.Context, iri string) (ApFollower, error) {
  260. row := q.db.QueryRowContext(ctx, getFollowerByIRI, iri)
  261. var i ApFollower
  262. err := row.Scan(
  263. &i.Iri,
  264. &i.Inbox,
  265. &i.Name,
  266. &i.Username,
  267. &i.Image,
  268. &i.Request,
  269. &i.RequestObject,
  270. &i.CreatedAt,
  271. &i.ApprovedAt,
  272. &i.DisabledAt,
  273. )
  274. return i, err
  275. }
  276. const getFollowerCount = `-- name: GetFollowerCount :one
  277. SElECT count(*) FROM ap_followers WHERE approved_at is not null
  278. `
  279. // Queries added to query.sql must be compiled into Go code with sqlc. Read README.md for details.
  280. // Federation related queries.
  281. func (q *Queries) GetFollowerCount(ctx context.Context) (int64, error) {
  282. row := q.db.QueryRowContext(ctx, getFollowerCount)
  283. var count int64
  284. err := row.Scan(&count)
  285. return count, err
  286. }
  287. const getIPAddressBans = `-- name: GetIPAddressBans :many
  288. SELECT ip_address, notes, created_at FROM ip_bans
  289. `
  290. func (q *Queries) GetIPAddressBans(ctx context.Context) ([]IpBan, error) {
  291. rows, err := q.db.QueryContext(ctx, getIPAddressBans)
  292. if err != nil {
  293. return nil, err
  294. }
  295. defer rows.Close()
  296. var items []IpBan
  297. for rows.Next() {
  298. var i IpBan
  299. if err := rows.Scan(&i.IpAddress, &i.Notes, &i.CreatedAt); err != nil {
  300. return nil, err
  301. }
  302. items = append(items, i)
  303. }
  304. if err := rows.Close(); err != nil {
  305. return nil, err
  306. }
  307. if err := rows.Err(); err != nil {
  308. return nil, err
  309. }
  310. return items, nil
  311. }
  312. const getInboundActivitiesWithOffset = `-- name: GetInboundActivitiesWithOffset :many
  313. SELECT iri, actor, type, timestamp FROM ap_accepted_activities ORDER BY timestamp DESC LIMIT $1 OFFSET $2
  314. `
  315. type GetInboundActivitiesWithOffsetParams struct {
  316. Limit int32
  317. Offset int32
  318. }
  319. type GetInboundActivitiesWithOffsetRow struct {
  320. Iri string
  321. Actor string
  322. Type string
  323. Timestamp time.Time
  324. }
  325. func (q *Queries) GetInboundActivitiesWithOffset(ctx context.Context, arg GetInboundActivitiesWithOffsetParams) ([]GetInboundActivitiesWithOffsetRow, error) {
  326. rows, err := q.db.QueryContext(ctx, getInboundActivitiesWithOffset, arg.Limit, arg.Offset)
  327. if err != nil {
  328. return nil, err
  329. }
  330. defer rows.Close()
  331. var items []GetInboundActivitiesWithOffsetRow
  332. for rows.Next() {
  333. var i GetInboundActivitiesWithOffsetRow
  334. if err := rows.Scan(
  335. &i.Iri,
  336. &i.Actor,
  337. &i.Type,
  338. &i.Timestamp,
  339. ); err != nil {
  340. return nil, err
  341. }
  342. items = append(items, i)
  343. }
  344. if err := rows.Close(); err != nil {
  345. return nil, err
  346. }
  347. if err := rows.Err(); err != nil {
  348. return nil, err
  349. }
  350. return items, nil
  351. }
  352. const getInboundActivityCount = `-- name: GetInboundActivityCount :one
  353. SELECT count(*) FROM ap_accepted_activities
  354. `
  355. func (q *Queries) GetInboundActivityCount(ctx context.Context) (int64, error) {
  356. row := q.db.QueryRowContext(ctx, getInboundActivityCount)
  357. var count int64
  358. err := row.Scan(&count)
  359. return count, err
  360. }
  361. const getLocalPostCount = `-- name: GetLocalPostCount :one
  362. SElECT count(*) FROM ap_outbox
  363. `
  364. func (q *Queries) GetLocalPostCount(ctx context.Context) (int64, error) {
  365. row := q.db.QueryRowContext(ctx, getLocalPostCount)
  366. var count int64
  367. err := row.Scan(&count)
  368. return count, err
  369. }
  370. const getMessagesFromUser = `-- name: GetMessagesFromUser :many
  371. SELECT id, body, hidden_at, timestamp FROM messages WHERE eventType = 'CHAT' AND user_id = $1 ORDER BY TIMESTAMP DESC
  372. `
  373. type GetMessagesFromUserRow struct {
  374. ID string
  375. Body sql.NullString
  376. HiddenAt sql.NullTime
  377. Timestamp sql.NullTime
  378. }
  379. func (q *Queries) GetMessagesFromUser(ctx context.Context, userID sql.NullString) ([]GetMessagesFromUserRow, error) {
  380. rows, err := q.db.QueryContext(ctx, getMessagesFromUser, userID)
  381. if err != nil {
  382. return nil, err
  383. }
  384. defer rows.Close()
  385. var items []GetMessagesFromUserRow
  386. for rows.Next() {
  387. var i GetMessagesFromUserRow
  388. if err := rows.Scan(
  389. &i.ID,
  390. &i.Body,
  391. &i.HiddenAt,
  392. &i.Timestamp,
  393. ); err != nil {
  394. return nil, err
  395. }
  396. items = append(items, i)
  397. }
  398. if err := rows.Close(); err != nil {
  399. return nil, err
  400. }
  401. if err := rows.Err(); err != nil {
  402. return nil, err
  403. }
  404. return items, nil
  405. }
  406. const getNotificationDestinationsForChannel = `-- name: GetNotificationDestinationsForChannel :many
  407. SELECT destination FROM notifications WHERE channel = $1
  408. `
  409. func (q *Queries) GetNotificationDestinationsForChannel(ctx context.Context, channel string) ([]string, error) {
  410. rows, err := q.db.QueryContext(ctx, getNotificationDestinationsForChannel, channel)
  411. if err != nil {
  412. return nil, err
  413. }
  414. defer rows.Close()
  415. var items []string
  416. for rows.Next() {
  417. var destination string
  418. if err := rows.Scan(&destination); err != nil {
  419. return nil, err
  420. }
  421. items = append(items, destination)
  422. }
  423. if err := rows.Close(); err != nil {
  424. return nil, err
  425. }
  426. if err := rows.Err(); err != nil {
  427. return nil, err
  428. }
  429. return items, nil
  430. }
  431. const getObjectFromOutboxByIRI = `-- name: GetObjectFromOutboxByIRI :one
  432. SELECT value, live_notification, created_at FROM ap_outbox WHERE iri = $1
  433. `
  434. type GetObjectFromOutboxByIRIRow struct {
  435. Value []byte
  436. LiveNotification sql.NullBool
  437. CreatedAt sql.NullTime
  438. }
  439. func (q *Queries) GetObjectFromOutboxByIRI(ctx context.Context, iri string) (GetObjectFromOutboxByIRIRow, error) {
  440. row := q.db.QueryRowContext(ctx, getObjectFromOutboxByIRI, iri)
  441. var i GetObjectFromOutboxByIRIRow
  442. err := row.Scan(&i.Value, &i.LiveNotification, &i.CreatedAt)
  443. return i, err
  444. }
  445. const getOutboxWithOffset = `-- name: GetOutboxWithOffset :many
  446. SELECT value FROM ap_outbox LIMIT $1 OFFSET $2
  447. `
  448. type GetOutboxWithOffsetParams struct {
  449. Limit int32
  450. Offset int32
  451. }
  452. func (q *Queries) GetOutboxWithOffset(ctx context.Context, arg GetOutboxWithOffsetParams) ([][]byte, error) {
  453. rows, err := q.db.QueryContext(ctx, getOutboxWithOffset, arg.Limit, arg.Offset)
  454. if err != nil {
  455. return nil, err
  456. }
  457. defer rows.Close()
  458. var items [][]byte
  459. for rows.Next() {
  460. var value []byte
  461. if err := rows.Scan(&value); err != nil {
  462. return nil, err
  463. }
  464. items = append(items, value)
  465. }
  466. if err := rows.Close(); err != nil {
  467. return nil, err
  468. }
  469. if err := rows.Err(); err != nil {
  470. return nil, err
  471. }
  472. return items, nil
  473. }
  474. const getRejectedAndBlockedFollowers = `-- name: GetRejectedAndBlockedFollowers :many
  475. SELECT iri, name, username, image, created_at, disabled_at FROM ap_followers WHERE disabled_at is not null
  476. `
  477. type GetRejectedAndBlockedFollowersRow struct {
  478. Iri string
  479. Name sql.NullString
  480. Username string
  481. Image sql.NullString
  482. CreatedAt sql.NullTime
  483. DisabledAt sql.NullTime
  484. }
  485. func (q *Queries) GetRejectedAndBlockedFollowers(ctx context.Context) ([]GetRejectedAndBlockedFollowersRow, error) {
  486. rows, err := q.db.QueryContext(ctx, getRejectedAndBlockedFollowers)
  487. if err != nil {
  488. return nil, err
  489. }
  490. defer rows.Close()
  491. var items []GetRejectedAndBlockedFollowersRow
  492. for rows.Next() {
  493. var i GetRejectedAndBlockedFollowersRow
  494. if err := rows.Scan(
  495. &i.Iri,
  496. &i.Name,
  497. &i.Username,
  498. &i.Image,
  499. &i.CreatedAt,
  500. &i.DisabledAt,
  501. ); err != nil {
  502. return nil, err
  503. }
  504. items = append(items, i)
  505. }
  506. if err := rows.Close(); err != nil {
  507. return nil, err
  508. }
  509. if err := rows.Err(); err != nil {
  510. return nil, err
  511. }
  512. return items, nil
  513. }
  514. const getUserByAccessToken = `-- name: GetUserByAccessToken :one
  515. SELECT users.id, display_name, display_color, users.created_at, disabled_at, previous_names, namechanged_at, authenticated_at, scopes FROM users, user_access_tokens WHERE token = $1 AND users.id = user_id
  516. `
  517. type GetUserByAccessTokenRow struct {
  518. ID string
  519. DisplayName string
  520. DisplayColor int32
  521. CreatedAt sql.NullTime
  522. DisabledAt sql.NullTime
  523. PreviousNames sql.NullString
  524. NamechangedAt sql.NullTime
  525. AuthenticatedAt sql.NullTime
  526. Scopes sql.NullString
  527. }
  528. func (q *Queries) GetUserByAccessToken(ctx context.Context, token string) (GetUserByAccessTokenRow, error) {
  529. row := q.db.QueryRowContext(ctx, getUserByAccessToken, token)
  530. var i GetUserByAccessTokenRow
  531. err := row.Scan(
  532. &i.ID,
  533. &i.DisplayName,
  534. &i.DisplayColor,
  535. &i.CreatedAt,
  536. &i.DisabledAt,
  537. &i.PreviousNames,
  538. &i.NamechangedAt,
  539. &i.AuthenticatedAt,
  540. &i.Scopes,
  541. )
  542. return i, err
  543. }
  544. const getUserByAuth = `-- name: GetUserByAuth :one
  545. SELECT users.id, display_name, display_color, users.created_at, disabled_at, previous_names, namechanged_at, authenticated_at, scopes FROM auth, users WHERE token = $1 AND auth.type = $2 AND users.id = auth.user_id
  546. `
  547. type GetUserByAuthParams struct {
  548. Token string
  549. Type string
  550. }
  551. type GetUserByAuthRow struct {
  552. ID string
  553. DisplayName string
  554. DisplayColor int32
  555. CreatedAt sql.NullTime
  556. DisabledAt sql.NullTime
  557. PreviousNames sql.NullString
  558. NamechangedAt sql.NullTime
  559. AuthenticatedAt sql.NullTime
  560. Scopes sql.NullString
  561. }
  562. func (q *Queries) GetUserByAuth(ctx context.Context, arg GetUserByAuthParams) (GetUserByAuthRow, error) {
  563. row := q.db.QueryRowContext(ctx, getUserByAuth, arg.Token, arg.Type)
  564. var i GetUserByAuthRow
  565. err := row.Scan(
  566. &i.ID,
  567. &i.DisplayName,
  568. &i.DisplayColor,
  569. &i.CreatedAt,
  570. &i.DisabledAt,
  571. &i.PreviousNames,
  572. &i.NamechangedAt,
  573. &i.AuthenticatedAt,
  574. &i.Scopes,
  575. )
  576. return i, err
  577. }
  578. const getUserDisplayNameByToken = `-- name: GetUserDisplayNameByToken :one
  579. SELECT display_name FROM users, user_access_tokens WHERE token = $1 AND users.id = user_id AND disabled_at = NULL
  580. `
  581. func (q *Queries) GetUserDisplayNameByToken(ctx context.Context, token string) (string, error) {
  582. row := q.db.QueryRowContext(ctx, getUserDisplayNameByToken, token)
  583. var display_name string
  584. err := row.Scan(&display_name)
  585. return display_name, err
  586. }
  587. const isDisplayNameAvailable = `-- name: IsDisplayNameAvailable :one
  588. SELECT count(*) FROM users WHERE display_name = $1 AND ( type='API' OR authenticated_at IS NOT NULL ) AND disabled_at IS NULL
  589. `
  590. func (q *Queries) IsDisplayNameAvailable(ctx context.Context, displayName string) (int64, error) {
  591. row := q.db.QueryRowContext(ctx, isDisplayNameAvailable, displayName)
  592. var count int64
  593. err := row.Scan(&count)
  594. return count, err
  595. }
  596. const isIPAddressBlocked = `-- name: IsIPAddressBlocked :one
  597. SELECT count(*) FROM ip_bans WHERE ip_address = $1
  598. `
  599. func (q *Queries) IsIPAddressBlocked(ctx context.Context, ipAddress string) (int64, error) {
  600. row := q.db.QueryRowContext(ctx, isIPAddressBlocked, ipAddress)
  601. var count int64
  602. err := row.Scan(&count)
  603. return count, err
  604. }
  605. const rejectFederationFollower = `-- name: RejectFederationFollower :exec
  606. UPDATE ap_followers SET approved_at = null, disabled_at = $1 WHERE iri = $2
  607. `
  608. type RejectFederationFollowerParams struct {
  609. DisabledAt sql.NullTime
  610. Iri string
  611. }
  612. func (q *Queries) RejectFederationFollower(ctx context.Context, arg RejectFederationFollowerParams) error {
  613. _, err := q.db.ExecContext(ctx, rejectFederationFollower, arg.DisabledAt, arg.Iri)
  614. return err
  615. }
  616. const removeFollowerByIRI = `-- name: RemoveFollowerByIRI :exec
  617. DELETE FROM ap_followers WHERE iri = $1
  618. `
  619. func (q *Queries) RemoveFollowerByIRI(ctx context.Context, iri string) error {
  620. _, err := q.db.ExecContext(ctx, removeFollowerByIRI, iri)
  621. return err
  622. }
  623. const removeIPAddressBan = `-- name: RemoveIPAddressBan :exec
  624. DELETE FROM ip_bans WHERE ip_address = $1
  625. `
  626. func (q *Queries) RemoveIPAddressBan(ctx context.Context, ipAddress string) error {
  627. _, err := q.db.ExecContext(ctx, removeIPAddressBan, ipAddress)
  628. return err
  629. }
  630. const removeNotificationDestinationForChannel = `-- name: RemoveNotificationDestinationForChannel :exec
  631. DELETE FROM notifications WHERE channel = $1 AND destination = $2
  632. `
  633. type RemoveNotificationDestinationForChannelParams struct {
  634. Channel string
  635. Destination string
  636. }
  637. func (q *Queries) RemoveNotificationDestinationForChannel(ctx context.Context, arg RemoveNotificationDestinationForChannelParams) error {
  638. _, err := q.db.ExecContext(ctx, removeNotificationDestinationForChannel, arg.Channel, arg.Destination)
  639. return err
  640. }
  641. const setAccessTokenToOwner = `-- name: SetAccessTokenToOwner :exec
  642. UPDATE user_access_tokens SET user_id = $1 WHERE token = $2
  643. `
  644. type SetAccessTokenToOwnerParams struct {
  645. UserID string
  646. Token string
  647. }
  648. func (q *Queries) SetAccessTokenToOwner(ctx context.Context, arg SetAccessTokenToOwnerParams) error {
  649. _, err := q.db.ExecContext(ctx, setAccessTokenToOwner, arg.UserID, arg.Token)
  650. return err
  651. }
  652. const setUserAsAuthenticated = `-- name: SetUserAsAuthenticated :exec
  653. UPDATE users SET authenticated_at = CURRENT_TIMESTAMP WHERE id = $1
  654. `
  655. func (q *Queries) SetUserAsAuthenticated(ctx context.Context, id string) error {
  656. _, err := q.db.ExecContext(ctx, setUserAsAuthenticated, id)
  657. return err
  658. }
  659. const updateFollowerByIRI = `-- name: UpdateFollowerByIRI :exec
  660. UPDATE ap_followers SET inbox = $1, name = $2, username = $3, image = $4 WHERE iri = $5
  661. `
  662. type UpdateFollowerByIRIParams struct {
  663. Inbox string
  664. Name sql.NullString
  665. Username string
  666. Image sql.NullString
  667. Iri string
  668. }
  669. func (q *Queries) UpdateFollowerByIRI(ctx context.Context, arg UpdateFollowerByIRIParams) error {
  670. _, err := q.db.ExecContext(ctx, updateFollowerByIRI,
  671. arg.Inbox,
  672. arg.Name,
  673. arg.Username,
  674. arg.Image,
  675. arg.Iri,
  676. )
  677. return err
  678. }