tmd-block.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package models_table
  2. import (
  3. "errors"
  4. "kkscrap-go/locals"
  5. e "github.com/dabory/abango-rest/etc"
  6. )
  7. func (t *EthBlock) TableName() string { // 반드시 있어야 table name을 가져올 수 있다.
  8. return e.TableName(*t)
  9. }
  10. func (t *EthBlock) RecordName() string { //필수
  11. return "Id of " + e.NumToStr(t.Id) + " in " + e.TableName(*t) + " "
  12. }
  13. func (t *EthBlock) GetaRow(y *locals.SyncController) error {
  14. if has, err := y.Db.Get(t); has == true {
  15. e.RecRead("dfefefqef", t.RecordName())
  16. return nil
  17. } else {
  18. if err == nil {
  19. return errors.New(e.RecNotFound("wecasdfw", t.RecordName()))
  20. } else {
  21. return errors.New(e.RecReadErr("dsflkjfyfd", t.RecordName()+err.Error()))
  22. }
  23. }
  24. }
  25. func (t *EthBlock) AddaRow(y *locals.SyncController) error {
  26. if affected, err := y.Db.Insert(t); affected == 1 && err == nil {
  27. e.RecAdded("eradsfvzc", t.RecordName())
  28. return nil
  29. } else {
  30. if err == nil {
  31. return errors.New(e.RecNotAdded("cxzvfdfasd", t.RecordName()))
  32. } else {
  33. return errors.New(e.RecAddErr("jfhgkeytg", t.RecordName()+err.Error()))
  34. }
  35. }
  36. }
  37. func (t *EthBlock) EditaRow(y *locals.SyncController) error {
  38. SyncEditaRowDefault(y, t)
  39. if affected, err := SyncUpdateQry(y, t.Id).Update(t); affected == 1 && err == nil {
  40. e.RecEdited("oiryhgsg", t.RecordName())
  41. return nil
  42. } else {
  43. if err == nil { // 같은 컨텐츠의 경우 0 값을 리턴하면서 다음 레코드로 진행
  44. e.RecNotEdited("liuytrgs", t.RecordName())
  45. t.Id = 0
  46. return nil // Error 아님
  47. } else {
  48. return errors.New(e.RecEditErr("petresfggs", t.RecordName()+err.Error()))
  49. }
  50. }
  51. }
  52. func (t *EthBlock) DelaRow(y *locals.SyncController) error {
  53. if affected, err := y.Db.ID(t.Id).Delete(t); affected == 1 && err == nil {
  54. e.RecDeleted("sdfwefavhk", t.RecordName())
  55. return nil
  56. } else {
  57. if err == nil {
  58. return errors.New(e.RecNotDeleted("lkdfgvfzv", t.RecordName())) // Error간주
  59. } else {
  60. return errors.New(e.RecDelErr("potuynbtr", t.RecordName()+err.Error()))
  61. }
  62. }
  63. }
  64. type BlockPageRet struct {
  65. PageVars locals.PageVars
  66. Page []EthBlock
  67. }
  68. func (t *BlockPageRet) TableName() string {
  69. return " Eth_Block "
  70. }
  71. func (t *BlockPageRet) RecordName() string { //필수
  72. return "Id of " + e.NumToStr(t.TableName) + " in " + e.TableName(*t) + " "
  73. }
  74. func (t *BlockPageRet) GetPage(y *locals.SyncController) error {
  75. qry := *y.Db.
  76. Table("Eth_Block").
  77. Where(t.PageVars.Query).
  78. Cols(t.PageVars.Fields).
  79. Limit(t.PageVars.Limit, t.PageVars.Offset)
  80. if t.PageVars.Asc != "" {
  81. qry = *qry.Asc(t.PageVars.Asc)
  82. }
  83. if t.PageVars.Desc != "" {
  84. qry = *qry.Desc(t.PageVars.Desc)
  85. }
  86. if cnt, err := qry.FindAndCount(&t.Page); err == nil {
  87. t.PageVars.QueryCnt = cnt
  88. e.PageRead("qweopfgbjs", t.TableName())
  89. return nil
  90. } else {
  91. return errors.New(e.PageQryErr("qreplhbdf", t.TableName()+err.Error()))
  92. }
  93. }