Replies: 8 comments
-
Hi @gnz00 . The first solution is already implemented - wiki. |
Beta Was this translation helpful? Give feedback.
-
Edit: I just realized I was embedding the struct! Nevermind! |
Beta Was this translation helpful? Give feedback.
-
@go-jet Actually, I may have closed this prematurely. Here is a full example showing a panic: package main
import (
"database/sql"
"fmt"
"net/http"
mysql "github.com/go-jet/jet/v2/mysql"
_ "github.com/go-sql-driver/mysql"
)
type TestObject struct {
Header http.Header `alias:"-"`
ID string `sql:"primary_key" alias:"id"`
}
func main() {
db, err := sql.Open("mysql", "root:pass@/mysql")
if err != nil {
panic(err)
}
var rows []*TestObject
table := mysql.NewTable("mysql", "user", "", mysql.StringColumn("id"))
mysql.
SELECT(
mysql.RawString("12345").AS("test_object.id"),
).
FROM(table).
Query(db, &rows)
for _, row := range rows {
fmt.Printf("%v\n", row)
}
}
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
It’s a contrived example but regardless of the type shouldn’t it be skipped with a tag of alias:”-“. I don’t think the expected behavior as you’ve described is a panic. |
Beta Was this translation helpful? Give feedback.
-
Setting alias to |
Beta Was this translation helpful? Give feedback.
-
I am suggesting that there be a token value that will explicitly opt out a field out of projection, as currently I am having to scan and then wrap to avoid panics on embedded 3rd-party structs. Alternatively, if there is no such projection for |
Beta Was this translation helpful? Give feedback.
-
You don't have to scan into whole complex destination. For instance: type Response struct {
Header map[string]string
ThirdParty ThirdParty
Data struct {
model.Actor
Films []model.Film
}
} Only var response Response
err := stmt.QueryContext(ctx, db, &response.Data) |
Beta Was this translation helpful? Give feedback.
-
Hey y'all, I was wondering if it is possible to skip certain fields while scanning rows into a destination.
I think there could be two potential solutions that could work together:
Or alternatively as a method on the QRM that only scans fields tagged with
alias
orsql
If there isn't a way currently I can take a crack at it.
Beta Was this translation helpful? Give feedback.
All reactions