infa.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package back
  2. import "errors"
  3. // InformationMass
  4. type informationMass struct {
  5. Infa string `json:"Link"`
  6. Rows []string
  7. }
  8. func prepareInfa() []string {
  9. var e error
  10. var elist []string
  11. queries["Insert@Infa@"], e = db.Prepare(`INSERT INTO "InformationMass" ("infa", "published") VALUES($1, CURRENT_TIMESTAMP)`)
  12. if e != nil {
  13. elist = append(elist, e.Error())
  14. }
  15. queries["Select@Infa@"], e = db.Prepare(`SELECT "infa" FROM "InformationMass" ORDER BY "published" DESC`)
  16. if e != nil {
  17. elist = append(elist, e.Error())
  18. }
  19. queries["Insert@Record@"], e = db.Prepare(`INSERT INTO "Record"("Name", "Passport", "Phone", "Cause") VALUES ($1, $2, $3, $4) RETURNING "ID"`)
  20. if e != nil {
  21. elist = append(elist, "[Insert@Record@] - "+e.Error())
  22. }
  23. queries["Insert@TimeRecord@"], e = db.Prepare(`INSERT INTO "TimeRecord"("Date", "Time", "Record") VALUES($1, $2, $3)`)
  24. if e != nil {
  25. elist = append(elist, "[Insert@TimeRecord@] - "+e.Error())
  26. }
  27. queries["Update@TimeRecord@"], e = db.Prepare(`UPDATE "TimeRecord" SET "Record"=$1 WHERE "Date"=$2 AND "Time"=$3`)
  28. if e != nil {
  29. elist = append(elist, "[Insert@TimeRecord@] - "+e.Error())
  30. }
  31. queries["Select@TimeRecord@Times"], e = db.Prepare(`SELECT "Time" FROM "TimeRecord" WHERE "Date"=$1 AND "Record" IS NULL`)
  32. if e != nil {
  33. elist = append(elist, "[Select@TimeRecord@Times] - "+e.Error())
  34. }
  35. queries["Select#Order#"], e = db.Prepare(`SELECT o."ID", o."Name", o."Passport", o."Phone", o."Cause", a."Date", a."Time"
  36. FROM "Record" AS o INNER JOIN "TimeRecord" AS a ON o."ID"=a."Record" WHERE a."Date"=$1
  37. ORDER BY a."Date" ASC, a."Time"`)
  38. if e != nil {
  39. elist = append(elist, "Select#Order#"+e.Error())
  40. }
  41. return elist
  42. }
  43. func (m *informationMass) Insert() error {
  44. stmt, ok := queries["Insert@Infa@"]
  45. if !ok {
  46. return errors.New("Запрос Insert@Infa@ не найден")
  47. }
  48. _, e := stmt.Exec(m.Infa)
  49. if e != nil {
  50. return e
  51. }
  52. return nil
  53. }
  54. func (m *informationMass) Select() error {
  55. stmt, ok := queries["Select@Infa@"]
  56. if !ok {
  57. return errors.New("Запрос Select@Infa@ не найден")
  58. }
  59. rows, e := stmt.Query()
  60. if e != nil {
  61. return e
  62. }
  63. defer rows.Close()
  64. var infa string
  65. for rows.Next() {
  66. e = rows.Scan(&infa)
  67. if e != nil {
  68. return e
  69. }
  70. m.Rows = append(m.Rows, infa)
  71. }
  72. return nil
  73. }