https://github.com/go-courier/sqlx
https://github.com/go-courier/sqlx
mysql sql
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/go-courier/sqlx
- Owner: go-courier
- License: mit
- Created: 2018-08-22T09:45:54.000Z (over 7 years ago)
- Default Branch: v2
- Last Pushed: 2023-07-18T11:48:04.000Z (over 2 years ago)
- Last Synced: 2024-11-17T12:45:40.881Z (over 1 year ago)
- Topics: mysql, sql
- Language: Go
- Size: 441 KB
- Stars: 4
- Watchers: 2
- Forks: 4
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## Sqlx
[](https://godoc.org/github.com/go-courier/sqlx/v2)
[](https://codecov.io/gh/go-courier/sqlx)
[](https://goreportcard.com/report/github.com/go-courier/sqlx/v2)
Sql helpers just for mysql(5.7+)/postgres(10+) and mysql/postgres-compatibility db.
```go
// @def primary ID
// @def index I_nickname/BTREE Nickname
// @def index I_username Username
// @def index I_geom/SPATIAL Geom
// @def unique_index I_name Name
type User struct {
ID uint64 `db:"f_id,autoincrement"`
// 姓名
NameNeedToDrop string `db:"f_name_need_to_drop,deprecated"`
OldName string `db:"f_old_name,deprecated=f_name"`
Name string `db:"f_name,default=''"`
Username string `db:"f_username,default=''"`
Nickname string `db:"f_nickname,default=''"`
Gender Gender `db:"f_gender,default='0'"`
Boolean bool `db:"f_boolean,default=false"`
Geom GeomString `db:"f_geom"`
CreatedAt datatypes.Timestamp `db:"f_created_at,default='0'"`
UpdatedAt datatypes.Timestamp `db:"f_updated_at,default='0'"`
Enabled datatypes.Bool `db:"f_enabled,default='0'"`
}
type GeomString struct {
V string
}
func (g GeomString) Value() (driver.Value, error) {
return g.V, nil
}
func (g *GeomString) Scan(src interface{}) error {
return nil
}
func (GeomString) DataType(driverName string) string {
if driverName == "mysql" {
return "geometry"
}
return "geometry(Point)"
}
func (GeomString) ValueEx() string {
return "ST_GeomFromText(?)"
}
```