records.sql.go 11 KB

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