summaryrefslogtreecommitdiffstats
path: root/sqlr_test.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2024-02-06 22:32:09 -0800
committerRose Hogenson <rosehogenson@posteo.net>2024-02-06 22:32:09 -0800
commitbe2efe80d7f11b695cb542ae94b4d5f1f69ba537 (patch)
tree6564d8521faee4144c5bd3954ef65a194ce8323c /sqlr_test.go
parent432e3bda53ca02b9f3eb58163f8459d051f1df20 (diff)
downloadsqlr-be2efe80d7f11b695cb542ae94b4d5f1f69ba537.tar.zst
Use reflect.VisibleFields to find struct fields.
Diffstat (limited to 'sqlr_test.go')
-rw-r--r--sqlr_test.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/sqlr_test.go b/sqlr_test.go
index 4323f11..4625fde 100644
--- a/sqlr_test.go
+++ b/sqlr_test.go
@@ -54,6 +54,17 @@ func TestScan(t *testing.T) {
ColA int `sql:"col_a"`
ColB string `sql:"col_b"`
}{100, "test"},
+ }, {
+ desc: "embedded struct",
+ db: `
+ CREATE TABLE Tbl (Col);
+ INSERT INTO Tbl VALUES (100)`,
+ query: "SELECT Col FROM Tbl",
+ want: func() any {
+ type Inner struct{ Col int }
+ type outer struct{ Inner }
+ return &outer{Inner{100}}
+ }(),
}} {
t.Run(tc.desc, func(t *testing.T) {
db, err := sql.Open("sqlite3", ":memory:")
@@ -129,6 +140,13 @@ func TestScan_Errors(t *testing.T) {
out: new(struct {
Col int `sql:"-"`
}),
+ }, {
+ desc: "unexported field",
+ db: `
+ CREATE TABLE Tbl (col);
+ INSERT INTO Tbl VALUES (100)`,
+ query: "SELECT col FROM Tbl",
+ out: new(struct{ col int }),
}} {
t.Run(tc.desc, func(t *testing.T) {
db, err := sql.Open("sqlite3", ":memory:")