sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

fix: batch insert bind for ptr slice

Open fifsky opened this issue 3 years ago • 1 comments

Variables behave inconsistently when using batch inserts

  people := []Person{}
  db.Select(&people, "SELECT * FROM person ORDER BY first_name ASC")   <---- this is ptr
  // batch insert with structs
  personStructs := []Person{
      {FirstName: "Ardie", LastName: "Savea", Email: "[email protected]"},
      {FirstName: "Sonny Bill", LastName: "Williams", Email: "[email protected]"},
      {FirstName: "Ngani", LastName: "Laumape", Email: "[email protected]"},
  }

  _, err = db.NamedExec(`INSERT INTO person (first_name, last_name, email)
      VALUES (:first_name, :last_name, :email)`, personStructs) <----- this not ptr

So, support batch insert used ptr slice

  // batch insert with structs
  personStructs := []Person{
      {FirstName: "Ardie", LastName: "Savea", Email: "[email protected]"},
      {FirstName: "Sonny Bill", LastName: "Williams", Email: "[email protected]"},
      {FirstName: "Ngani", LastName: "Laumape", Email: "[email protected]"},
  }

  _, err = db.NamedExec(`INSERT INTO person (first_name, last_name, email)
      VALUES (:first_name, :last_name, :email)`, &personStructs) <----- this ptr

fifsky avatar Apr 17 '22 03:04 fifsky

Hello, @ardan-bkennedy, and I recently stepped in to help maintain this project. We are sorting the opened issues and pull requests and would like to know if you still NEED this merged. Thank you for your contribution.

dlsniper avatar Feb 01 '24 13:02 dlsniper