github.com/kunlun-qilian/sqlx/v3@v3.0.0/README.md (about)

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