2021-12-11 17:35:24 +01:00
|
|
|
package advsql
|
|
|
|
|
2022-07-08 22:25:05 +02:00
|
|
|
func Insert[T any](db *Database, query string, encoder func(v *T, encode EncodeFunc) error) InsertFunc[T] {
|
2022-07-05 12:38:39 +02:00
|
|
|
s, err := db.prepare(query)
|
2021-12-11 17:35:24 +01:00
|
|
|
if err != nil {
|
2022-07-09 23:55:22 +02:00
|
|
|
panic(err)
|
2021-12-11 17:35:24 +01:00
|
|
|
}
|
|
|
|
|
2022-07-05 12:38:39 +02:00
|
|
|
return func(value *T) error {
|
2022-07-08 22:25:05 +02:00
|
|
|
return encoder(value, func(args ...interface{}) error {
|
2022-07-05 12:38:39 +02:00
|
|
|
_, err := s.Exec(args...)
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
}
|
2021-12-11 17:35:24 +01:00
|
|
|
}
|