Lightweight & Compitable wrapper of database/sql
This repository has been archived on 2020-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Guillermo Prandi 1e7bccc690
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
Exclude schema from index name (#65)
Exclude schema from the index name

simple drone test

fix column default value be empty (#59)

Use https for gocover badge (#64)

Co-authored-by: Guillermo Prandi <guillep2k@users.noreply.github.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: SijmenSchoon <sijmenschoon@noreply@gitea.io>
Reviewed-on: #65
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
2020-01-19 09:04:11 +00:00
.circleci Add context support (#46) 2019-01-17 14:40:11 +08:00
.drone.yml simple drone test 2020-01-19 16:59:09 +08:00
.gitignore add set db to dialect 2014-04-18 18:39:59 +08:00
benchmark.sh init core after sperated repository 2014-04-08 20:57:04 +08:00
cache.go comment go lint 2019-06-20 09:10:01 +08:00
column.go fix column default value be empty (#59) 2019-11-13 11:09:21 +00:00
converstion.go Add context support (#46) 2019-01-17 14:40:11 +08:00
db_test.go Fix flag.Parse on init (#57) 2019-08-30 03:53:40 +00:00
db.go lunny/fix_fmt_lint (#53) 2019-07-15 13:42:17 +00:00
dialect.go Remove QuoteStr() in interface Dialect (#55) 2019-07-24 05:07:17 +00:00
driver.go Add context support (#46) 2019-01-17 14:40:11 +08:00
error.go lunny/fix_fmt_lint (#53) 2019-07-15 13:42:17 +00:00
filter_test.go fix arg conversion (#61) 2019-09-28 05:59:35 +00:00
filter.go fix arg conversion (#61) 2019-09-28 05:59:35 +00:00
go.mod Fix flag.Parse on init (#57) 2019-08-30 03:53:40 +00:00
go.sum Fix flag.Parse on init (#57) 2019-08-30 03:53:40 +00:00
ilogger.go lunny/fix_fmt_lint (#53) 2019-07-15 13:42:17 +00:00
index.go Exclude schema from index name (#65) 2020-01-19 09:04:11 +00:00
LICENSE include copyright name + email 2015-09-04 12:26:30 -04:00
mapper_test.go Add context support (#46) 2019-01-17 14:40:11 +08:00
mapper.go lunny/fix_fmt_lint (#53) 2019-07-15 13:42:17 +00:00
pk_test.go Add context support (#46) 2019-01-17 14:40:11 +08:00
pk.go Add context support (#46) 2019-01-17 14:40:11 +08:00
README.md Use https for gocover badge (#64) 2019-11-03 03:34:15 +00:00
rows.go lunny/fix_fmt_lint (#53) 2019-07-15 13:42:17 +00:00
scan.go Add context support (#46) 2019-01-17 14:40:11 +08:00
stmt.go lunny/fix_fmt_lint (#53) 2019-07-15 13:42:17 +00:00
table_test.go Add context support (#46) 2019-01-17 14:40:11 +08:00
table.go lunny/fix_fmt_lint (#53) 2019-07-15 13:42:17 +00:00
tx.go Add context support (#46) 2019-01-17 14:40:11 +08:00
type.go Add Year type for supporting mysql (#58) 2019-09-06 12:36:29 +00:00

Core is a lightweight wrapper of sql.DB.

Build Status Test Coverage Go Report Card

Open

db, _ := core.Open(db, connstr)

SetMapper

db.SetMapper(SameMapper())

Scan usage

Scan

rows, _ := db.Query()
for rows.Next() {
    rows.Scan()
}

ScanMap

rows, _ := db.Query()
for rows.Next() {
    rows.ScanMap()

ScanSlice

You can use []string, [][]byte, []interface{}, []*string, []sql.NullString to ScanSclice. Notice, slice's length should be equal or less than select columns.

rows, _ := db.Query()
cols, _ := rows.Columns()
for rows.Next() {
    var s = make([]string, len(cols))
    rows.ScanSlice(&s)
}
rows, _ := db.Query()
cols, _ := rows.Columns()
for rows.Next() {
    var s = make([]*string, len(cols))
    rows.ScanSlice(&s)
}

ScanStruct

rows, _ := db.Query()
for rows.Next() {
    rows.ScanStructByName()
    rows.ScanStructByIndex()
}

Query usage

rows, err := db.Query("select * from table where name = ?", name)

user = User{
    Name:"lunny",
}
rows, err := db.QueryStruct("select * from table where name = ?Name",
            &user)

var user = map[string]interface{}{
    "name": "lunny",
}
rows, err = db.QueryMap("select * from table where name = ?name",
            &user)

QueryRow usage

row := db.QueryRow("select * from table where name = ?", name)

user = User{
    Name:"lunny",
}
row := db.QueryRowStruct("select * from table where name = ?Name",
            &user)

var user = map[string]interface{}{
    "name": "lunny",
}
row = db.QueryRowMap("select * from table where name = ?name",
            &user)

Exec usage

db.Exec("insert into user (`name`, title, age, alias, nick_name,created) values (?,?,?,?,?,?)", name, title, age, alias...)

user = User{
    Name:"lunny",
    Title:"test",
    Age: 18,
}
result, err = db.ExecStruct("insert into user (`name`, title, age, alias, nick_name,created) values (?Name,?Title,?Age,?Alias,?NickName,?Created)",
            &user)

var user = map[string]interface{}{
    "Name": "lunny",
    "Title": "test",
    "Age": 18,
}
result, err = db.ExecMap("insert into user (`name`, title, age, alias, nick_name,created) values (?Name,?Title,?Age,?Alias,?NickName,?Created)",
            &user)