2021-12-11 17:35:24 +01:00
|
|
|
package advsql
|
|
|
|
|
2022-07-12 17:56:06 +02:00
|
|
|
func Insert[T any](db *Database, query string, encoder func(v *T, encode ScanFunc) error) InsertFunc[T] {
|
2022-07-11 13:28:07 +02:00
|
|
|
s := db.prepare(query)
|
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
|
|
|
}
|