sql: converting argument $10 type: unsupported type main.RequestRecord, a struct

456 views
Skip to first unread message

Kimiya Sharifk

unread,
Jan 28, 2022, 1:12:48 PM1/28/22
to golang-nuts
Hi

i have a struct  event and inner that i have struct RequestRecord
type RequestRecord struct {
ID string `json:"id"`
Addr string `json:"addr"`
Host string `json:"host"`
Method string `json:"method"`
UserAgent string `json:"useragent"`
}
type event struct {
ID string `json:"id"`
TimeStamp string `json:"timestamp"`
Action string `json:"action"`
Length int `json:"length"`
Repository string `json:"repository"`
FromRepository string `json:"fromRepository"`
URL string `json:"url"`
Tag string `json:"tag"`
Request RequestRecord `json:"request"`
}

in inserting to database  i get this error:
sql: converting argument $10 type: unsupported type main.RequestRecord, a struct

i attached main.go

main.go

Amit Saha

unread,
Jan 28, 2022, 6:36:06 PM1/28/22
to golang-nuts

Your code uses the `pq` driver but it is using `sqlite` db. Have you looked at using a driver for sqlite instead? such as https://github.com/mattn/go-sqlite3 

Additionally, i suggest, you share your code in a way, others can run and reproduce the error so that they can try to help you and also please share the HTTP request you sent to your server which reproduces the error. If i try to build your code now, i get this:

# test
./main.go:153:11: too many arguments in call to StoreItem
        have (*sql.DB, interface { Scan(interface {}) error; Value() (driver.Value, error) }, interface { Scan(interface {}) error; Value() (driver.Value, error) })
        want (*sql.DB, []event)
Reply all
Reply to author
Forward
0 new messages