sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Add sqlx.Conn to correspond to sql.Conn

Open andeya opened this issue 6 years ago • 4 comments

Requires version: go ≥ 1.9

andeya avatar Jun 13 '18 04:06 andeya

Pull Request Test Coverage Report for Build 30

  • 0 of 58 (0.0%) changed or added relevant lines in 1 file are covered.
  • 80 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-2.7%) to 69.147%

Changes Missing Coverage Covered Lines Changed/Added Lines %
sqlx_conn.go 0 58 0.0%
<!-- Total: 0 58
Files with Coverage Reduction New Missed Lines %
reflectx/reflect.go 80 97.67%
<!-- Total: 80
Totals Coverage Status
Change from base Build 17: -2.7%
Covered Lines: 1078
Relevant Lines: 1559

💛 - Coveralls

coveralls avatar Jun 13 '18 04:06 coveralls

Nice contribution. I'd like to add some testing and perhaps get vgo integration going before I leave some verisons of Go behind.

jmoiron avatar Jun 13 '18 20:06 jmoiron

The test just like this:

type Stat struct {
	Uri       string `db:"uri"`
	Total     int64  `db:"total"`
	CreatedAt int64  `db:"created_at"`
}

func TestDBConn(t *testing.T) {
	conn, err := db.Conn(context.Background())
	if err != nil {
		t.Fatal(err)
	}
	defer conn.Close()
	var total int64 = 1
	r, err := conn.ExecContext(
		context.Background(),
		`INSERT INTO stat VALUE ('/j',?,1528996897)
		ON DUPLICATE KEY UPDATE total=@total_tmp:=total+?;`,
		total, 1,
	)
	if err != nil {
		t.Fatal(err)
	}
	rowsAffected, err := r.RowsAffected()
	if err != nil {
		t.Fatal(err)
	}
	if rowsAffected == 2 {
		err = conn.GetContext(context.Background(), &total, "SELECT @total_tmp as total;")
		if err != nil {
			t.Fatal(err)
		}
	}
	t.Log(total)
}

andeya avatar Jun 14 '18 17:06 andeya

@henrylee2cn how about adding your test to the PR?

glaslos avatar Oct 15 '18 09:10 glaslos