Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
athxx opened this issue Jun 2, 2021 · 1 comment
Closed

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

athxx opened this issue Jun 2, 2021 · 1 comment

Comments

@athxx
Copy link

athxx commented Jun 2, 2021

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
Copy link
Member

fifsky commented Jun 3, 2021

tx,err := gosql.Begin()
.....
tx.Commit()

@athxx athxx closed this as completed Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants