github.com/RevenueMonster/sqlike@v1.0.6/sql/dialect/mysql/value.go (about)

     1  package mysql
     2  
     3  import (
     4  	"database/sql"
     5  	"database/sql/driver"
     6  	"encoding/json"
     7  	"fmt"
     8  	"strconv"
     9  	"time"
    10  
    11  	"github.com/RevenueMonster/sqlike/util"
    12  )
    13  
    14  // Format :
    15  func (ms MySQL) Format(it interface{}) (val string) {
    16  	switch vi := it.(type) {
    17  	case []byte:
    18  		val = strconv.Quote(util.UnsafeString(vi))
    19  	case string:
    20  		val = strconv.Quote(vi)
    21  	case bool:
    22  		val = "0"
    23  		if vi {
    24  			val = "1"
    25  		}
    26  	case int64:
    27  		val = strconv.FormatInt(vi, 10)
    28  	case uint64:
    29  		val = strconv.FormatUint(vi, 10)
    30  	case float64:
    31  		val = strconv.FormatFloat(vi, 'e', -1, 64)
    32  	case time.Time:
    33  		val = vi.Format(`"2006-01-02 15:04:05.999999"`)
    34  	case json.RawMessage:
    35  		val = strconv.Quote(util.UnsafeString(vi))
    36  	case sql.RawBytes:
    37  		val = string(vi)
    38  	case nil:
    39  		val = "NULL"
    40  	case fmt.Stringer:
    41  		val = strconv.Quote(vi.String())
    42  	case driver.Valuer:
    43  		v, _ := vi.Value()
    44  		val = ms.Format(v)
    45  	default:
    46  		val = fmt.Sprintf("%v", vi)
    47  	}
    48  	return
    49  }