github.com/kunlun-qilian/sqlx/v3@v3.0.0/generator/__examples__/database/user.go (about)

     1  package database
     2  
     3  import (
     4  	"database/sql/driver"
     5  
     6  	"github.com/kunlun-qilian/sqlx/v3/datatypes"
     7  )
     8  
     9  // @def primary ID
    10  // @def index I_nickname/BTREE Nickname
    11  // @def index I_username Username
    12  // @def index I_geom/SPATIAL (#Geom)
    13  // @def unique_index I_name Name
    14  type User struct {
    15  	ID uint64 `db:"f_id,autoincrement"`
    16  	// 姓名
    17  	Name      string              `db:"f_name,default=''"`
    18  	Username  string              `db:"f_username,default=''"`
    19  	Nickname  string              `db:"f_nickname,default=''"`
    20  	Gender    Gender              `db:"f_gender,default='0'"`
    21  	Boolean   bool                `db:"f_boolean,default=false"`
    22  	Geom      GeomString          `db:"f_geom"`
    23  	CreatedAt datatypes.Timestamp `db:"f_created_at,default='0'"`
    24  	UpdatedAt datatypes.Timestamp `db:"f_updated_at,default='0'"`
    25  	DeletedAt datatypes.Timestamp `db:"f_deleted_at,default='0'"`
    26  }
    27  
    28  type GeomString struct {
    29  	V string
    30  }
    31  
    32  func (g GeomString) Value() (driver.Value, error) {
    33  	return g.V, nil
    34  }
    35  
    36  func (g *GeomString) Scan(src interface{}) error {
    37  	return nil
    38  }
    39  
    40  func (GeomString) DataType(driverName string) string {
    41  	if driverName == "mysql" {
    42  		return "geometry"
    43  	}
    44  	return "geometry(Point)"
    45  }
    46  
    47  func (GeomString) ValueEx() string {
    48  	return "ST_GeomFromText(?)"
    49  }