MCPcopy
hub / github.com/jmoiron/sqlx / TestEmbeddedLiterals

Function TestEmbeddedLiterals

sqlx_test.go:1693–1733  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1691}
1692
1693func TestEmbeddedLiterals(t *testing.T) {
1694 var schema = Schema{
1695 create: `
1696 CREATE TABLE x (
1697 k text
1698 );`,
1699 drop: `drop table x;`,
1700 }
1701
1702 RunWithSchema(schema, t, func(db *DB, t *testing.T, now string) {
1703 type t1 struct {
1704 K *string
1705 }
1706 type t2 struct {
1707 Inline struct {
1708 F string
1709 }
1710 K *string
1711 }
1712
1713 db.MustExec(db.Rebind("INSERT INTO x (k) VALUES (?), (?), (?);"), "one", "two", "three")
1714
1715 target := t1{}
1716 err := db.Get(&target, db.Rebind("SELECT * FROM x WHERE k=?"), "one")
1717 if err != nil {
1718 t.Error(err)
1719 }
1720 if *target.K != "one" {
1721 t.Error("Expected target.K to be `one`, got ", target.K)
1722 }
1723
1724 target2 := t2{}
1725 err = db.Get(&target2, db.Rebind("SELECT * FROM x WHERE k=?"), "one")
1726 if err != nil {
1727 t.Error(err)
1728 }
1729 if *target2.K != "one" {
1730 t.Errorf("Expected target2.K to be `one`, got `%v`", target2.K)
1731 }
1732 })
1733}
1734
1735func BenchmarkBindStruct(b *testing.B) {
1736 b.StopTimer()

Callers

nothing calls this directly

Calls 6

RunWithSchemaFunction · 0.85
ErrorMethod · 0.80
ErrorfMethod · 0.80
RebindMethod · 0.65
MustExecMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected