github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/modelgen/__examples__/user.go (about)

     1  package example
     2  
     3  import (
     4  	"database/sql/driver"
     5  
     6  	"github.com/machinefi/w3bstream/pkg/depends/base/types"
     7  )
     8  
     9  // @def primary ID
    10  // @def index        I_nickname/BTREE Name
    11  // @def index        I_username       Username
    12  // @def index        I_geom/SPATIAL   (#Geom)
    13  // @def unique_index UI_name          Name
    14  // @def unique_index UI_id_org        ID OrgID
    15  
    16  // User 用户表
    17  type User struct {
    18  	ID uint64 `db:"f_id,autoincrement"`
    19  
    20  	Name     string     `db:"f_name,default=''"`     // 姓名
    21  	Nickname string     `db:"f_nickname,default=''"` // 昵称
    22  	Username string     `db:"f_username,default=''"` // 用户名
    23  	Gender   Gender     `db:"f_gender,default='0'"`
    24  	Boolean  bool       `db:"f_boolean,default=false"`
    25  	Geom     GeomString `db:"f_geom"`
    26  	// @rel Org.ID
    27  	// 关联组织
    28  	// 组织ID
    29  	OrgID     uint64          `db:"f_org_id"`
    30  	CreatedAt types.Timestamp `db:"f_created_at,default='0'"`
    31  	UpdatedAt types.Timestamp `db:"f_updated_at,default='0'"`
    32  	DeletedAt types.Timestamp `db:"f_deleted_at,default='0'"`
    33  }
    34  
    35  type GeomString struct {
    36  	V string
    37  }
    38  
    39  func (g GeomString) Value() (driver.Value, error) {
    40  	return g.V, nil
    41  }
    42  
    43  func (g *GeomString) Scan(src interface{}) error {
    44  	return nil
    45  }
    46  
    47  func (GeomString) DataType(driverName string) string {
    48  	if driverName == "mysql" {
    49  		return "geometry"
    50  	}
    51  	return "geometry(Point)"
    52  }
    53  
    54  func (GeomString) ValueEx() string {
    55  	return "ST_GeomFromText(?)"
    56  }