github.com/go-courier/sqlx/v2@v2.23.13/README.md (about)

     1  ## Sqlx
     2  
     3  [![GoDoc Widget](https://godoc.org/github.com/go-courier/sqlx/v2?status.svg)](https://godoc.org/github.com/go-courier/sqlx/v2)
     4  [![codecov](https://codecov.io/gh/go-courier/sqlx/branch/master/graph/badge.svg)](https://codecov.io/gh/go-courier/sqlx)
     5  [![Go Report Card](https://goreportcard.com/badge/github.com/go-courier/sqlx/v2)](https://goreportcard.com/report/github.com/go-courier/sqlx/v2)
     6  
     7  
     8  Sql helpers just for mysql(5.7+)/postgres(10+) and mysql/postgres-compatibility db.
     9  
    10  
    11  ```go
    12  // @def primary ID
    13  // @def index I_nickname/BTREE Nickname
    14  // @def index I_username Username
    15  // @def index I_geom/SPATIAL Geom
    16  // @def unique_index I_name Name
    17  type User struct {
    18  	ID uint64 `db:"f_id,autoincrement"`
    19  	// 姓名
    20  	NameNeedToDrop   string                   `db:"f_name_need_to_drop,deprecated"`
    21  	OldName   string                          `db:"f_old_name,deprecated=f_name"`
    22  	Name      string                          `db:"f_name,default=''"`
    23  	Username  string                          `db:"f_username,default=''"`
    24  	Nickname  string                          `db:"f_nickname,default=''"`
    25  	Gender    Gender                          `db:"f_gender,default='0'"`
    26  	Boolean   bool                            `db:"f_boolean,default=false"`
    27  	Geom      GeomString                      `db:"f_geom"`
    28  	CreatedAt datatypes.Timestamp             `db:"f_created_at,default='0'"`
    29  	UpdatedAt datatypes.Timestamp             `db:"f_updated_at,default='0'"`
    30  	Enabled   datatypes.Bool                  `db:"f_enabled,default='0'"`
    31  }
    32  
    33  type GeomString struct {
    34  	V string
    35  }
    36  
    37  func (g GeomString) Value() (driver.Value, error) {
    38  	return g.V, nil
    39  }
    40  
    41  func (g *GeomString) Scan(src interface{}) error {
    42  	return nil
    43  }
    44  
    45  func (GeomString) DataType(driverName string) string {
    46  	if driverName == "mysql" {
    47  		return "geometry"
    48  	}
    49  	return "geometry(Point)"
    50  }
    51  
    52  func (GeomString) ValueEx() string {
    53  	return "ST_GeomFromText(?)"
    54  }
    55  ```