ilibs / gosql

🐥The very simple ORM library for Golang
MIT License
295 stars 39 forks source link

默认的gosql里面没有Commit ??? #38

Closed athxx closed 3 years ago

athxx commented 3 years ago
package main

import (
    "fmt"
    _ "github.com/go-sql-driver/mysql" //mysql driver
    "github.com/ilibs/gosql/v2"
    "os"
)

func main() {
    configs := make(map[string]*gosql.Config)
    configs["default"] = &gosql.Config{
        Enable:  true,
        Driver:  "mysql",
        Dsn:     "root:321@@tcp(127.0.0.1:3306)/soulma?charset=utf8mb4&parseTime=True&loc=Asia%2FShanghai",
        ShowSql: true,
    }

    configs["db2"] = &gosql.Config{
        Enable:  true,
        Driver:  "mysql",
        Dsn:     "root:123@@tcp(127.0.0.1:3306)/soulmb?charset=utf8mb4&parseTime=True&loc=Asia%2FShanghai",
        ShowSql: true,
    }
    //connection database
    if err := gosql.Connect(configs); err != nil {
        fmt.Println(err.Error())
        os.Exit(0)
    }

    type UserList struct {
        UID int `db:"Pid"`
    }
    user := UserList{}
    rows  := gosql.Use("db2").QueryRowx("SELECT * FROM user_list WHERE pid = 1333;")
    gosql.Begin()
    // `木有gosql.Commit这函数`
    gosql.Begin()
    gosql.Use("db2").Commit() // `这里有Commit函数`
    fmt.Println(rows.Err(),user)
}
fifsky commented 3 years ago
tx,err := gosql.Begin()
.....
tx.Commit()