Sqlx: NamedExec doesn't support slice of struct?

Created on 28 May 2019  路  5Comments  路  Source: jmoiron/sqlx

Hi,
I am using postgresql, when run the below

`

type person struct {
FirstName string
LastName string
Gender string
}
persons := []person{
{
"f1",
"l1",
"m",
},
{
"f2",
"l2",
"m",
},
}
`

insertCmd := INSERT INTO person(first_name, last_name, gender) VALUES(:firstname, :lastname, :gender)
db.NamedExec(insertCmd, persons )
getting errors:
panic: reflect: call of github.com/jmoiron/sql/reflectx.(*Mapper).TraversalsByNameFunc on slice Value,

I found tests https://github.com/jmoiron/sqlx/blob/master/named_test.go#L194 works,
any advice?

Most helpful comment

check if you are using the master brach.

All 5 comments

check if you are using the master brach.

I'm using go dep -> dep ensure, use the master branch but in the vendor not the latest version of code...

hi will there be a new release soon to include the bug fixes?

Code below would not work.

persons := []map[string]interface{}{
    {
        "first": "Bin",
        "last":  "Smuth",
        "email": "[email protected]",
    },
    {
        "first": "Bin2",
        "last":  "Smuth2",
        "email": "[email protected]",
    },
}
_, err = db.NamedExec(`INSERT INTO person (first_name,last_name,email) VALUES (:first,:last,:email)`, persons)

print(err)

I noticed go get -u does not download the latest version (1.2.1) but an older one (1.2.0) if no entry in go.mod exists. That older version does not, for instance, support NamedExec with slices.
I have to change the version manually to v1.2.1-0.20200324155115-ee514944af4b.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

johnknapp picture johnknapp  路  5Comments

pt-arvind picture pt-arvind  路  4Comments

luiscvega picture luiscvega  路  4Comments

plandem picture plandem  路  5Comments

resal81 picture resal81  路  5Comments