records.sql.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. // Code generated by sqlc. DO NOT EDIT.
  2. // versions:
  3. // sqlc v1.30.0
  4. // source: records.sql
  5. package queries
  6. import (
  7. "context"
  8. "time"
  9. )
  10. const createRecord = `-- name: CreateRecord :one
  11. INSERT INTO records (zone_id, cf_record_id, name, type, content, proxied, is_static)
  12. VALUES (?, ?, ?, ?, ?, ?, ?)
  13. RETURNING id, zone_id, cf_record_id, name, type, content, proxied, is_static, created_at, updated_at
  14. `
  15. type CreateRecordParams struct {
  16. ZoneID int64 `json:"zone_id"`
  17. CfRecordID string `json:"cf_record_id"`
  18. Name string `json:"name"`
  19. Type string `json:"type"`
  20. Content string `json:"content"`
  21. Proxied int64 `json:"proxied"`
  22. IsStatic int64 `json:"is_static"`
  23. }
  24. func (q *Queries) CreateRecord(ctx context.Context, arg CreateRecordParams) (Record, error) {
  25. row := q.db.QueryRowContext(ctx, createRecord,
  26. arg.ZoneID,
  27. arg.CfRecordID,
  28. arg.Name,
  29. arg.Type,
  30. arg.Content,
  31. arg.Proxied,
  32. arg.IsStatic,
  33. )
  34. var i Record
  35. err := row.Scan(
  36. &i.ID,
  37. &i.ZoneID,
  38. &i.CfRecordID,
  39. &i.Name,
  40. &i.Type,
  41. &i.Content,
  42. &i.Proxied,
  43. &i.IsStatic,
  44. &i.CreatedAt,
  45. &i.UpdatedAt,
  46. )
  47. return i, err
  48. }
  49. const deleteRecord = `-- name: DeleteRecord :exec
  50. DELETE FROM records WHERE id = ?
  51. `
  52. func (q *Queries) DeleteRecord(ctx context.Context, id int64) error {
  53. _, err := q.db.ExecContext(ctx, deleteRecord, id)
  54. return err
  55. }
  56. const deleteRecordByCfID = `-- name: DeleteRecordByCfID :exec
  57. DELETE FROM records WHERE zone_id = ? AND cf_record_id = ?
  58. `
  59. type DeleteRecordByCfIDParams struct {
  60. ZoneID int64 `json:"zone_id"`
  61. CfRecordID string `json:"cf_record_id"`
  62. }
  63. func (q *Queries) DeleteRecordByCfID(ctx context.Context, arg DeleteRecordByCfIDParams) error {
  64. _, err := q.db.ExecContext(ctx, deleteRecordByCfID, arg.ZoneID, arg.CfRecordID)
  65. return err
  66. }
  67. const getRecord = `-- name: GetRecord :one
  68. SELECT r.id, r.zone_id, r.cf_record_id, r.name, r.type, r.content, r.proxied, r.is_static, r.created_at, r.updated_at, z.zone_id as cf_zone_id, z.name as zone_name
  69. FROM records r
  70. JOIN zones z ON z.id = r.zone_id
  71. WHERE r.id = ?
  72. `
  73. type GetRecordRow struct {
  74. ID int64 `json:"id"`
  75. ZoneID int64 `json:"zone_id"`
  76. CfRecordID string `json:"cf_record_id"`
  77. Name string `json:"name"`
  78. Type string `json:"type"`
  79. Content string `json:"content"`
  80. Proxied int64 `json:"proxied"`
  81. IsStatic int64 `json:"is_static"`
  82. CreatedAt time.Time `json:"created_at"`
  83. UpdatedAt time.Time `json:"updated_at"`
  84. CfZoneID string `json:"cf_zone_id"`
  85. ZoneName string `json:"zone_name"`
  86. }
  87. func (q *Queries) GetRecord(ctx context.Context, id int64) (GetRecordRow, error) {
  88. row := q.db.QueryRowContext(ctx, getRecord, id)
  89. var i GetRecordRow
  90. err := row.Scan(
  91. &i.ID,
  92. &i.ZoneID,
  93. &i.CfRecordID,
  94. &i.Name,
  95. &i.Type,
  96. &i.Content,
  97. &i.Proxied,
  98. &i.IsStatic,
  99. &i.CreatedAt,
  100. &i.UpdatedAt,
  101. &i.CfZoneID,
  102. &i.ZoneName,
  103. )
  104. return i, err
  105. }
  106. const listNonStaticRecords = `-- name: ListNonStaticRecords :many
  107. SELECT r.id, r.zone_id, r.cf_record_id, r.name, r.type, r.content, r.proxied, r.is_static, r.created_at, r.updated_at, z.zone_id as cf_zone_id, z.api_key as zone_api_key
  108. FROM records r
  109. JOIN zones z ON z.id = r.zone_id
  110. WHERE r.is_static = 0
  111. `
  112. type ListNonStaticRecordsRow struct {
  113. ID int64 `json:"id"`
  114. ZoneID int64 `json:"zone_id"`
  115. CfRecordID string `json:"cf_record_id"`
  116. Name string `json:"name"`
  117. Type string `json:"type"`
  118. Content string `json:"content"`
  119. Proxied int64 `json:"proxied"`
  120. IsStatic int64 `json:"is_static"`
  121. CreatedAt time.Time `json:"created_at"`
  122. UpdatedAt time.Time `json:"updated_at"`
  123. CfZoneID string `json:"cf_zone_id"`
  124. ZoneApiKey string `json:"zone_api_key"`
  125. }
  126. func (q *Queries) ListNonStaticRecords(ctx context.Context) ([]ListNonStaticRecordsRow, error) {
  127. rows, err := q.db.QueryContext(ctx, listNonStaticRecords)
  128. if err != nil {
  129. return nil, err
  130. }
  131. defer rows.Close()
  132. var items []ListNonStaticRecordsRow
  133. for rows.Next() {
  134. var i ListNonStaticRecordsRow
  135. if err := rows.Scan(
  136. &i.ID,
  137. &i.ZoneID,
  138. &i.CfRecordID,
  139. &i.Name,
  140. &i.Type,
  141. &i.Content,
  142. &i.Proxied,
  143. &i.IsStatic,
  144. &i.CreatedAt,
  145. &i.UpdatedAt,
  146. &i.CfZoneID,
  147. &i.ZoneApiKey,
  148. ); err != nil {
  149. return nil, err
  150. }
  151. items = append(items, i)
  152. }
  153. if err := rows.Close(); err != nil {
  154. return nil, err
  155. }
  156. if err := rows.Err(); err != nil {
  157. return nil, err
  158. }
  159. return items, nil
  160. }
  161. const listRecordCfIDsByZone = `-- name: ListRecordCfIDsByZone :many
  162. SELECT cf_record_id FROM records WHERE zone_id = ?
  163. `
  164. func (q *Queries) ListRecordCfIDsByZone(ctx context.Context, zoneID int64) ([]string, error) {
  165. rows, err := q.db.QueryContext(ctx, listRecordCfIDsByZone, zoneID)
  166. if err != nil {
  167. return nil, err
  168. }
  169. defer rows.Close()
  170. var items []string
  171. for rows.Next() {
  172. var cf_record_id string
  173. if err := rows.Scan(&cf_record_id); err != nil {
  174. return nil, err
  175. }
  176. items = append(items, cf_record_id)
  177. }
  178. if err := rows.Close(); err != nil {
  179. return nil, err
  180. }
  181. if err := rows.Err(); err != nil {
  182. return nil, err
  183. }
  184. return items, nil
  185. }
  186. const listRecords = `-- name: ListRecords :many
  187. SELECT r.id, r.zone_id, r.cf_record_id, r.name, r.type, r.content, r.proxied, r.is_static, r.created_at, r.updated_at, z.zone_id as cf_zone_id, z.name as zone_name
  188. FROM records r
  189. JOIN zones z ON z.id = r.zone_id
  190. ORDER BY r.name
  191. `
  192. type ListRecordsRow struct {
  193. ID int64 `json:"id"`
  194. ZoneID int64 `json:"zone_id"`
  195. CfRecordID string `json:"cf_record_id"`
  196. Name string `json:"name"`
  197. Type string `json:"type"`
  198. Content string `json:"content"`
  199. Proxied int64 `json:"proxied"`
  200. IsStatic int64 `json:"is_static"`
  201. CreatedAt time.Time `json:"created_at"`
  202. UpdatedAt time.Time `json:"updated_at"`
  203. CfZoneID string `json:"cf_zone_id"`
  204. ZoneName string `json:"zone_name"`
  205. }
  206. func (q *Queries) ListRecords(ctx context.Context) ([]ListRecordsRow, error) {
  207. rows, err := q.db.QueryContext(ctx, listRecords)
  208. if err != nil {
  209. return nil, err
  210. }
  211. defer rows.Close()
  212. var items []ListRecordsRow
  213. for rows.Next() {
  214. var i ListRecordsRow
  215. if err := rows.Scan(
  216. &i.ID,
  217. &i.ZoneID,
  218. &i.CfRecordID,
  219. &i.Name,
  220. &i.Type,
  221. &i.Content,
  222. &i.Proxied,
  223. &i.IsStatic,
  224. &i.CreatedAt,
  225. &i.UpdatedAt,
  226. &i.CfZoneID,
  227. &i.ZoneName,
  228. ); err != nil {
  229. return nil, err
  230. }
  231. items = append(items, i)
  232. }
  233. if err := rows.Close(); err != nil {
  234. return nil, err
  235. }
  236. if err := rows.Err(); err != nil {
  237. return nil, err
  238. }
  239. return items, nil
  240. }
  241. const listRecordsByZone = `-- name: ListRecordsByZone :many
  242. SELECT r.id, r.zone_id, r.cf_record_id, r.name, r.type, r.content, r.proxied, r.is_static, r.created_at, r.updated_at, z.zone_id as cf_zone_id, z.name as zone_name
  243. FROM records r
  244. JOIN zones z ON z.id = r.zone_id
  245. WHERE r.zone_id = ?
  246. ORDER BY r.name
  247. `
  248. type ListRecordsByZoneRow struct {
  249. ID int64 `json:"id"`
  250. ZoneID int64 `json:"zone_id"`
  251. CfRecordID string `json:"cf_record_id"`
  252. Name string `json:"name"`
  253. Type string `json:"type"`
  254. Content string `json:"content"`
  255. Proxied int64 `json:"proxied"`
  256. IsStatic int64 `json:"is_static"`
  257. CreatedAt time.Time `json:"created_at"`
  258. UpdatedAt time.Time `json:"updated_at"`
  259. CfZoneID string `json:"cf_zone_id"`
  260. ZoneName string `json:"zone_name"`
  261. }
  262. func (q *Queries) ListRecordsByZone(ctx context.Context, zoneID int64) ([]ListRecordsByZoneRow, error) {
  263. rows, err := q.db.QueryContext(ctx, listRecordsByZone, zoneID)
  264. if err != nil {
  265. return nil, err
  266. }
  267. defer rows.Close()
  268. var items []ListRecordsByZoneRow
  269. for rows.Next() {
  270. var i ListRecordsByZoneRow
  271. if err := rows.Scan(
  272. &i.ID,
  273. &i.ZoneID,
  274. &i.CfRecordID,
  275. &i.Name,
  276. &i.Type,
  277. &i.Content,
  278. &i.Proxied,
  279. &i.IsStatic,
  280. &i.CreatedAt,
  281. &i.UpdatedAt,
  282. &i.CfZoneID,
  283. &i.ZoneName,
  284. ); err != nil {
  285. return nil, err
  286. }
  287. items = append(items, i)
  288. }
  289. if err := rows.Close(); err != nil {
  290. return nil, err
  291. }
  292. if err := rows.Err(); err != nil {
  293. return nil, err
  294. }
  295. return items, nil
  296. }
  297. const updateRecord = `-- name: UpdateRecord :one
  298. UPDATE records
  299. SET name = ?, type = ?, content = ?, proxied = ?, is_static = ?, updated_at = CURRENT_TIMESTAMP
  300. WHERE id = ?
  301. RETURNING id, zone_id, cf_record_id, name, type, content, proxied, is_static, created_at, updated_at
  302. `
  303. type UpdateRecordParams struct {
  304. Name string `json:"name"`
  305. Type string `json:"type"`
  306. Content string `json:"content"`
  307. Proxied int64 `json:"proxied"`
  308. IsStatic int64 `json:"is_static"`
  309. ID int64 `json:"id"`
  310. }
  311. func (q *Queries) UpdateRecord(ctx context.Context, arg UpdateRecordParams) (Record, error) {
  312. row := q.db.QueryRowContext(ctx, updateRecord,
  313. arg.Name,
  314. arg.Type,
  315. arg.Content,
  316. arg.Proxied,
  317. arg.IsStatic,
  318. arg.ID,
  319. )
  320. var i Record
  321. err := row.Scan(
  322. &i.ID,
  323. &i.ZoneID,
  324. &i.CfRecordID,
  325. &i.Name,
  326. &i.Type,
  327. &i.Content,
  328. &i.Proxied,
  329. &i.IsStatic,
  330. &i.CreatedAt,
  331. &i.UpdatedAt,
  332. )
  333. return i, err
  334. }
  335. const updateRecordContent = `-- name: UpdateRecordContent :exec
  336. UPDATE records
  337. SET content = ?, updated_at = CURRENT_TIMESTAMP
  338. WHERE id = ?
  339. `
  340. type UpdateRecordContentParams struct {
  341. Content string `json:"content"`
  342. ID int64 `json:"id"`
  343. }
  344. func (q *Queries) UpdateRecordContent(ctx context.Context, arg UpdateRecordContentParams) error {
  345. _, err := q.db.ExecContext(ctx, updateRecordContent, arg.Content, arg.ID)
  346. return err
  347. }
  348. const upsertRecord = `-- name: UpsertRecord :one
  349. INSERT INTO records (zone_id, cf_record_id, name, type, content, proxied, is_static)
  350. VALUES (?, ?, ?, ?, ?, ?, ?)
  351. ON CONFLICT(zone_id, cf_record_id) DO UPDATE SET
  352. name = excluded.name,
  353. type = excluded.type,
  354. content = excluded.content,
  355. proxied = excluded.proxied,
  356. updated_at = CURRENT_TIMESTAMP
  357. RETURNING id, zone_id, cf_record_id, name, type, content, proxied, is_static, created_at, updated_at
  358. `
  359. type UpsertRecordParams struct {
  360. ZoneID int64 `json:"zone_id"`
  361. CfRecordID string `json:"cf_record_id"`
  362. Name string `json:"name"`
  363. Type string `json:"type"`
  364. Content string `json:"content"`
  365. Proxied int64 `json:"proxied"`
  366. IsStatic int64 `json:"is_static"`
  367. }
  368. func (q *Queries) UpsertRecord(ctx context.Context, arg UpsertRecordParams) (Record, error) {
  369. row := q.db.QueryRowContext(ctx, upsertRecord,
  370. arg.ZoneID,
  371. arg.CfRecordID,
  372. arg.Name,
  373. arg.Type,
  374. arg.Content,
  375. arg.Proxied,
  376. arg.IsStatic,
  377. )
  378. var i Record
  379. err := row.Scan(
  380. &i.ID,
  381. &i.ZoneID,
  382. &i.CfRecordID,
  383. &i.Name,
  384. &i.Type,
  385. &i.Content,
  386. &i.Proxied,
  387. &i.IsStatic,
  388. &i.CreatedAt,
  389. &i.UpdatedAt,
  390. )
  391. return i, err
  392. }