advsql/insert.go
2022-07-09 23:55:22 +02:00

16 lines
329 B
Go

package advsql
func Insert[T any](db *Database, query string, encoder func(v *T, encode EncodeFunc) error) InsertFunc[T] {
s, err := db.prepare(query)
if err != nil {
panic(err)
}
return func(value *T) error {
return encoder(value, func(args ...interface{}) error {
_, err := s.Exec(args...)
return err
})
}
}