advsql/insert.go

16 lines
329 B
Go
Raw 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-05 12:38:39 +02:00
return nil
}
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
})
}
}