Loggest thy stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

259 lines
6.1 KiB

  1. // Code generated by sqlc. DO NOT EDIT.
  2. // versions:
  3. // sqlc v1.13.0
  4. // source: scope.sql
  5. package mysqlcore
  6. import (
  7. "context"
  8. "database/sql"
  9. )
  10. const deleteAllScopeMembers = `-- name: DeleteAllScopeMembers :exec
  11. DELETE FROM scope_member WHERE scope_id=?
  12. `
  13. func (q *Queries) DeleteAllScopeMembers(ctx context.Context, scopeID int) error {
  14. _, err := q.exec(ctx, q.deleteAllScopeMembersStmt, deleteAllScopeMembers, scopeID)
  15. return err
  16. }
  17. const deleteScope = `-- name: DeleteScope :exec
  18. DELETE FROM scope WHERE id=?
  19. `
  20. func (q *Queries) DeleteScope(ctx context.Context, id int) error {
  21. _, err := q.exec(ctx, q.deleteScopeStmt, deleteScope, id)
  22. return err
  23. }
  24. const deleteScopeMember = `-- name: DeleteScopeMember :exec
  25. DELETE FROM scope_member WHERE scope_id=? AND user_id=?
  26. `
  27. type DeleteScopeMemberParams struct {
  28. ScopeID int
  29. UserID string
  30. }
  31. func (q *Queries) DeleteScopeMember(ctx context.Context, arg DeleteScopeMemberParams) error {
  32. _, err := q.exec(ctx, q.deleteScopeMemberStmt, deleteScopeMember, arg.ScopeID, arg.UserID)
  33. return err
  34. }
  35. const getScope = `-- name: GetScope :one
  36. SELECT id, name, abbreviation FROM scope
  37. WHERE id = ?
  38. `
  39. func (q *Queries) GetScope(ctx context.Context, id int) (Scope, error) {
  40. row := q.queryRow(ctx, q.getScopeStmt, getScope, id)
  41. var i Scope
  42. err := row.Scan(&i.ID, &i.Name, &i.Abbreviation)
  43. return i, err
  44. }
  45. const getScopeDisplayName = `-- name: GetScopeDisplayName :one
  46. SELECT name FROM scope_member
  47. WHERE user_id = ? AND scope_id = ?
  48. `
  49. type GetScopeDisplayNameParams struct {
  50. UserID string
  51. ScopeID int
  52. }
  53. func (q *Queries) GetScopeDisplayName(ctx context.Context, arg GetScopeDisplayNameParams) (string, error) {
  54. row := q.queryRow(ctx, q.getScopeDisplayNameStmt, getScopeDisplayName, arg.UserID, arg.ScopeID)
  55. var name string
  56. err := row.Scan(&name)
  57. return name, err
  58. }
  59. const getScopeWithDisplayName = `-- name: GetScopeWithDisplayName :one
  60. SELECT id, scope.name, abbreviation, sm.name AS display_name FROM scope
  61. LEFT JOIN scope_member sm ON scope.id = sm.scope_id
  62. WHERE id = ? AND sm.user_id = ?
  63. `
  64. type GetScopeWithDisplayNameParams struct {
  65. ID int
  66. UserID string
  67. }
  68. type GetScopeWithDisplayNameRow struct {
  69. ID int
  70. Name string
  71. Abbreviation string
  72. DisplayName sql.NullString
  73. }
  74. func (q *Queries) GetScopeWithDisplayName(ctx context.Context, arg GetScopeWithDisplayNameParams) (GetScopeWithDisplayNameRow, error) {
  75. row := q.queryRow(ctx, q.getScopeWithDisplayNameStmt, getScopeWithDisplayName, arg.ID, arg.UserID)
  76. var i GetScopeWithDisplayNameRow
  77. err := row.Scan(
  78. &i.ID,
  79. &i.Name,
  80. &i.Abbreviation,
  81. &i.DisplayName,
  82. )
  83. return i, err
  84. }
  85. const insertScope = `-- name: InsertScope :execresult
  86. INSERT INTO scope (id, name, abbreviation)
  87. VALUES (?, ?, ?)
  88. `
  89. type InsertScopeParams struct {
  90. ID int
  91. Name string
  92. Abbreviation string
  93. }
  94. func (q *Queries) InsertScope(ctx context.Context, arg InsertScopeParams) (sql.Result, error) {
  95. return q.exec(ctx, q.insertScopeStmt, insertScope, arg.ID, arg.Name, arg.Abbreviation)
  96. }
  97. const listScopeMembers = `-- name: ListScopeMembers :many
  98. SELECT user_id, name, owner FROM scope_member
  99. WHERE scope_id = ?
  100. ORDER BY name
  101. `
  102. type ListScopeMembersRow struct {
  103. UserID string
  104. Name string
  105. Owner bool
  106. }
  107. func (q *Queries) ListScopeMembers(ctx context.Context, scopeID int) ([]ListScopeMembersRow, error) {
  108. rows, err := q.query(ctx, q.listScopeMembersStmt, listScopeMembers, scopeID)
  109. if err != nil {
  110. return nil, err
  111. }
  112. defer rows.Close()
  113. items := []ListScopeMembersRow{}
  114. for rows.Next() {
  115. var i ListScopeMembersRow
  116. if err := rows.Scan(&i.UserID, &i.Name, &i.Owner); err != nil {
  117. return nil, err
  118. }
  119. items = append(items, i)
  120. }
  121. if err := rows.Close(); err != nil {
  122. return nil, err
  123. }
  124. if err := rows.Err(); err != nil {
  125. return nil, err
  126. }
  127. return items, nil
  128. }
  129. const listScopes = `-- name: ListScopes :many
  130. SELECT id, name, abbreviation FROM scope
  131. ORDER BY name
  132. `
  133. func (q *Queries) ListScopes(ctx context.Context) ([]Scope, error) {
  134. rows, err := q.query(ctx, q.listScopesStmt, listScopes)
  135. if err != nil {
  136. return nil, err
  137. }
  138. defer rows.Close()
  139. items := []Scope{}
  140. for rows.Next() {
  141. var i Scope
  142. if err := rows.Scan(&i.ID, &i.Name, &i.Abbreviation); err != nil {
  143. return nil, err
  144. }
  145. items = append(items, i)
  146. }
  147. if err := rows.Close(); err != nil {
  148. return nil, err
  149. }
  150. if err := rows.Err(); err != nil {
  151. return nil, err
  152. }
  153. return items, nil
  154. }
  155. const listScopesByUser = `-- name: ListScopesByUser :many
  156. SELECT id, s.name, abbreviation, sm.name as display_name FROM scope_member sm
  157. RIGHT JOIN scope s on s.id = sm.scope_id
  158. WHERE sm.user_id = ?
  159. ORDER BY s.name
  160. `
  161. type ListScopesByUserRow struct {
  162. ID int
  163. Name string
  164. Abbreviation string
  165. DisplayName sql.NullString
  166. }
  167. func (q *Queries) ListScopesByUser(ctx context.Context, userID string) ([]ListScopesByUserRow, error) {
  168. rows, err := q.query(ctx, q.listScopesByUserStmt, listScopesByUser, userID)
  169. if err != nil {
  170. return nil, err
  171. }
  172. defer rows.Close()
  173. items := []ListScopesByUserRow{}
  174. for rows.Next() {
  175. var i ListScopesByUserRow
  176. if err := rows.Scan(
  177. &i.ID,
  178. &i.Name,
  179. &i.Abbreviation,
  180. &i.DisplayName,
  181. ); err != nil {
  182. return nil, err
  183. }
  184. items = append(items, i)
  185. }
  186. if err := rows.Close(); err != nil {
  187. return nil, err
  188. }
  189. if err := rows.Err(); err != nil {
  190. return nil, err
  191. }
  192. return items, nil
  193. }
  194. const updateScope = `-- name: UpdateScope :exec
  195. UPDATE scope SET name = ?, abbreviation = ? WHERE id = ?
  196. `
  197. type UpdateScopeParams struct {
  198. Name string
  199. Abbreviation string
  200. ID int
  201. }
  202. func (q *Queries) UpdateScope(ctx context.Context, arg UpdateScopeParams) error {
  203. _, err := q.exec(ctx, q.updateScopeStmt, updateScope, arg.Name, arg.Abbreviation, arg.ID)
  204. return err
  205. }
  206. const updateScopeMember = `-- name: UpdateScopeMember :exec
  207. REPLACE INTO scope_member (scope_id, user_id, name, owner)
  208. VALUES (?, ?, ?, ?)
  209. `
  210. type UpdateScopeMemberParams struct {
  211. ScopeID int
  212. UserID string
  213. Name string
  214. Owner bool
  215. }
  216. func (q *Queries) UpdateScopeMember(ctx context.Context, arg UpdateScopeMemberParams) error {
  217. _, err := q.exec(ctx, q.updateScopeMemberStmt, updateScopeMember,
  218. arg.ScopeID,
  219. arg.UserID,
  220. arg.Name,
  221. arg.Owner,
  222. )
  223. return err
  224. }