advsql/insert.go

16 lines
329 B
Go
Raw Permalink Normal View History

package advsql
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)
if err != nil {
2022-07-09 23:55:22 +02:00
panic(err)
}
2022-07-05 12:38:39 +02:00
return func(value *T) error {
return encoder(value, func(args ...interface{}) error {
2022-07-05 12:38:39 +02:00
_, err := s.Exec(args...)
return err
})
}
}