-
Hi! Could you advice me the best way to INSERT multiple rows?
( I use |
Beta Was this translation helpful? Give feedback.
Answered by
zombiezen
Oct 26, 2023
Replies: 1 comment 1 reply
-
Things to keep in mind (not specific to this package, but applicable to SQLite in general):
Putting this all together, the sort of code I would recommend is something like this: func myFunc(conn *sqlite.Conn) (err error) {
endFn, err := sqlitex.ImmediateTransaction(conn)
if err != nil {
return err
}
defer endFn(&err)
stmt := conn.Prep("INSERT INTO table (col1, col2) VALUES (?, ?);")
for _, row := range mySlice {
stmt.BindText(1, row.col1)
stmt.BindText(2, row.col2)
if err := stmt.Step(); err != nil {
return err
}
if err := stmt.Reset(); err != nil {
return err
}
}
return nil
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
thedmdim
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Things to keep in mind (not specific to this package, but applicable to SQLite in general):
Conn.Prep
, for example.