first commit

This commit is contained in:
2023-04-12 16:56:55 +08:00
commit e82ca51b08
53 changed files with 2762 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
package res_type
import (
"database/sql/driver"
"encoding/json"
"fmt"
)
// 解析map ----------------------------------
type ResFieldByMap map[string]any
func (c *ResFieldByMap) Scan(value any) error {
if value == nil {
return nil
}
if err := json.Unmarshal(value.([]byte), c); err != nil {
return fmt.Errorf("ResFieldByMap json.Unmarshal Error, %s", err)
}
return nil
}
func (c ResFieldByMap) Value() (driver.Value, error) {
b, err := json.Marshal(c)
return string(b), err
}

View File

@@ -0,0 +1,3 @@
package res_type
type ResFieldByFloat float64

View File

@@ -0,0 +1,3 @@
package res_type
type ResFieldByInteger int64

View File

@@ -0,0 +1,38 @@
package res_type
import (
"database/sql/driver"
"encoding/json"
"fmt"
)
// 切片 ------------------------------------
type ResFieldByAnys []any
func (c *ResFieldByAnys) Scan(value any) error {
if value == nil {
return nil
}
switch v := value.(type) {
case []byte:
if len(v) == 0 {
return nil
}
if rune('[') != rune(v[0]) {
return nil
}
default:
}
if err := json.Unmarshal(value.([]byte), c); err != nil {
return fmt.Errorf("ResFieldByAnys json.Unmarshal Error, %s, %s", value, err)
}
return nil
}
func (c ResFieldByAnys) Value() (driver.Value, error) {
b, err := json.Marshal(c)
return string(b), err
}

View File

@@ -0,0 +1,29 @@
package res_type
import (
"database/sql/driver"
"github.com/spf13/cast"
)
// Number 类型 --------------------------------
type ResFieldByNumber float64
func (this *ResFieldByNumber) Scan(value any) error {
if value == nil {
return nil
}
switch s := value.(type) {
case []byte:
*this = ResFieldByNumber(cast.ToFloat64(string(s)))
default:
*this = ResFieldByNumber(cast.ToFloat64(s))
}
return nil
}
func (this ResFieldByNumber) Value() (driver.Value, error) {
return this, nil
}

View File

@@ -0,0 +1,28 @@
package res_type
import (
"database/sql/driver"
"fmt"
)
// 字符串 -------------------------------------
type ResFieldByString string
func (this *ResFieldByString) Scan(value any) error {
if value == nil {
return nil
}
switch s := value.(type) {
case []byte:
*this = ResFieldByString(s)
default:
*this = ResFieldByString(fmt.Sprintf("%v", s))
}
return nil
}
func (c ResFieldByString) Value() (driver.Value, error) {
return c, nil
}