github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/internal/pkg/helper/column-generate.go (about) 1 package helper 2 3 import ( 4 "fmt" 5 "math" 6 "strconv" 7 ) 8 9 func GenBit() (ret, note string) { 10 ret = "0,1:R" 11 note = "bit" 12 return 13 } 14 func GenTinyint(hasSign bool) (ret, note string) { 15 if hasSign { 16 ret = "-128-127:R" 17 } else { 18 ret = "0-255:R" 19 } 20 note = "tinyint 2^8" 21 return 22 } 23 func GenSmallint(hasSign bool) (ret, note string) { 24 if hasSign { 25 ret = "-32768-32767:R" 26 } else { 27 ret = "0-65535:R" 28 } 29 note = "smallint 2^16" 30 return 31 } 32 func GenMediumint(hasSign bool) (ret, note string) { 33 if hasSign { 34 ret = "-8388608-8388607:R" 35 } else { 36 ret = "0-16777215:R" 37 } 38 39 note = "mediumint 2^24" 40 return 41 } 42 func GenInt(hasSign bool) (ret, note string) { 43 if hasSign { 44 ret = "-2147483648-2147483647:R" 45 } else { 46 ret = "0-4294967295:R" 47 } 48 49 note = "int 2^32" 50 return 51 } 52 func GenBigint(hasSign bool) (ret, note string) { 53 //MaxInt64 = 1<<63 - 1 // 9223372036854775807 54 //MinInt64 = -1 << 63 // -9223372036854775808 55 56 if hasSign { 57 ret = fmt.Sprintf("%d-%d:R", math.MinInt32, math.MaxInt32) // compatible for 32 bits system 58 } else { 59 ret = fmt.Sprintf("0-%d:R", math.MaxInt32) // compatible for 32 bits system 60 } 61 62 note = "bigint 2^64" 63 return 64 } 65 66 func GenFloat(hasSign bool) (ret, note string) { 67 if hasSign { 68 ret = "-99-99.999:R" 69 } else { 70 ret = "0-99.999:R" 71 } 72 73 note = "float" 74 return 75 } 76 func GenDouble(hasSign bool) (ret, note string) { 77 if hasSign { 78 ret = "-99-99.999999:R" 79 } else { 80 ret = "0-99.999999:R" 81 } 82 83 note = "double" 84 return 85 } 86 func GenDecimal(hasSign bool) (ret, note string) { 87 if hasSign { 88 ret = "-99-99.99:R" 89 } else { 90 ret = "0-99.99:R" 91 } 92 93 note = "decimal" 94 return 95 } 96 97 func GenChar(param string) (ret string, loop string) { 98 ret = `a-z` 99 100 loopInt, _ := strconv.Atoi(param) 101 if loopInt > 0 { 102 loop = fmt.Sprintf("%d", loopInt) 103 } 104 105 return 106 } 107 108 func GenBin() (from, format string) { 109 format = "binary()" 110 return 111 } 112 113 // date time 114 func GenDate() (rang, typ, format string) { 115 rang = `"(-1M)-(+1w):86400"` 116 typ = "timestamp" 117 format = `"YY/MM/DD"` 118 119 return 120 } 121 func GenTime() (rang, typ, format string) { 122 rang = `"(-1M)-(+1w):60"` 123 typ = "timestamp" 124 format = `"hh:mm:ss"` 125 126 return 127 } 128 func GenYear() (rang, typ, format string) { 129 rang = `"(-6Y)-(+6Y):31536000"` 130 typ = "timestamp" 131 format = `"YYYY"` 132 133 return 134 } 135 136 func GenDatetime() (rang, typ, format string) { 137 rang = `"(-1M)-(+1w):60"` 138 typ = "timestamp" 139 format = `"YY/MM/DD hh:mm:ss"` 140 141 return 142 } 143 func GenTimestamp() (rang, typ, format string) { 144 rang = `"(-1M)-(+1w):60"` 145 typ = "timestamp" 146 format = `""` 147 148 return 149 }