shared.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package gen
  2. var (
  3. commonMysqlDataTypeMap = map[string]string{
  4. "tinyint": "int64",
  5. "smallint": "int64",
  6. "mediumint": "int64",
  7. "int": "int64",
  8. "integer": "int64",
  9. "bigint": "int64",
  10. "float": "float64",
  11. "double": "float64",
  12. "decimal": "float64",
  13. "date": "time.Time",
  14. "time": "string",
  15. "year": "int64",
  16. "datetime": "time.Time",
  17. "timestamp": "time.Time",
  18. "char": "string",
  19. "varchar": "string",
  20. "tinyblob": "string",
  21. "tinytext": "string",
  22. "blob": "string",
  23. "text": "string",
  24. "mediumblob": "string",
  25. "mediumtext": "string",
  26. "longblob": "string",
  27. "longtext": "string",
  28. }
  29. )
  30. const (
  31. QueryNone QueryType = 0
  32. QueryOne QueryType = 1 // 仅支持单个字段为查询条件
  33. QueryAll QueryType = 2 // 可支持多个字段为查询条件,且关系均为and
  34. QueryLimit QueryType = 3 // 可支持多个字段为查询条件,且关系均为and
  35. )
  36. type (
  37. QueryType int
  38. Case struct {
  39. SnakeCase string
  40. LowerCamelCase string
  41. UpperCamelCase string
  42. }
  43. InnerWithField struct {
  44. Case
  45. DataType string
  46. }
  47. InnerTable struct {
  48. Case
  49. ContainsCache bool
  50. CreateNotFound bool
  51. PrimaryField *InnerField
  52. Fields []*InnerField
  53. CacheKey map[string]Key // key-数据库字段
  54. }
  55. InnerField struct {
  56. IsPrimaryKey bool
  57. InnerWithField
  58. DataBaseType string // 数据库中字段类型
  59. Tag string // 标签,格式:`db:"xxx"`
  60. Comment string // 注释,以"// 开头"
  61. Cache bool // 是否缓存模式
  62. QueryType QueryType
  63. WithFields []InnerWithField
  64. Sort []InnerSort
  65. }
  66. InnerSort struct {
  67. Field Case
  68. Asc bool
  69. }
  70. OuterTable struct {
  71. Table string `json:"table"`
  72. CreateNotFound bool `json:"createNotFound,optional"`
  73. Fields []*OuterFiled `json:"fields"`
  74. }
  75. OuterWithField struct {
  76. Name string `json:"name"`
  77. DataBaseType string `json:"dataBaseType"`
  78. }
  79. OuterSort struct {
  80. Field string `json:"fields"`
  81. Asc bool `json:"asc,optional"`
  82. }
  83. OuterFiled struct {
  84. IsPrimaryKey bool `json:"isPrimaryKey,optional"`
  85. Name string `json:"name"`
  86. DataBaseType string `json:"dataBaseType"`
  87. Comment string `json:"comment"`
  88. Cache bool `json:"cache,optional"`
  89. // if IsPrimaryKey==false下面字段有效
  90. QueryType QueryType `json:"queryType"` // 查找类型
  91. WithFields []OuterWithField `json:"withFields,optional"` // 其他字段联合组成条件的字段列表
  92. OuterSort []OuterSort `json:"sort,optional"`
  93. }
  94. )