EncodeFunc and DecodeFunc replaced by ScanFunc
This commit is contained in:
parent
e9402c2f4e
commit
3eac777080
@ -15,15 +15,15 @@ type User struct {
|
||||
Salt string
|
||||
}
|
||||
|
||||
func UserDecoder(u *User, decode DecodeFunc) error {
|
||||
func UserDecoder(u *User, decode ScanFunc) error {
|
||||
return decode(&u.Name, &u.Hash, &u.Salt)
|
||||
}
|
||||
|
||||
func InsertUserEncoder(u *User, encode EncodeFunc) error {
|
||||
func InsertUserEncoder(u *User, encode ScanFunc) error {
|
||||
return encode(u.Name, u.Hash, u.Salt)
|
||||
}
|
||||
|
||||
func UpdateUserByNameEncoder(u *User, encode EncodeFunc) error {
|
||||
func UpdateUserByNameEncoder(u *User, encode ScanFunc) error {
|
||||
return encode(u.Salt, u.Name)
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,6 @@ type defaultDecoderType interface {
|
||||
}
|
||||
|
||||
// Decoder provides default decoders for primitive datatypes
|
||||
func Decoder[T defaultDecoderType](value *T, decode DecodeFunc) error {
|
||||
func Decoder[T defaultDecoderType](value *T, decode ScanFunc) error {
|
||||
return decode(value)
|
||||
}
|
||||
|
@ -11,5 +11,4 @@ type QueryOneContextFunc[T any] func(ctx context.Context, args ...interface{}) *
|
||||
type InsertFunc[T any] func(v *T) error
|
||||
type UpdateFunc[T any] func(v *T) error
|
||||
|
||||
type DecodeFunc = func(args ...interface{}) error
|
||||
type EncodeFunc = func(args ...interface{}) error
|
||||
type ScanFunc = func(args ...interface{}) error
|
||||
|
@ -1,6 +1,6 @@
|
||||
package advsql
|
||||
|
||||
func Insert[T any](db *Database, query string, encoder func(v *T, encode EncodeFunc) error) InsertFunc[T] {
|
||||
func Insert[T any](db *Database, query string, encoder func(v *T, encode ScanFunc) error) InsertFunc[T] {
|
||||
s := db.prepare(query)
|
||||
|
||||
return func(value *T) error {
|
||||
|
@ -2,14 +2,14 @@ package advsql
|
||||
|
||||
import "context"
|
||||
|
||||
func QueryMany[T any](db *Database, query string, decoder func(v *T, decode DecodeFunc) error) QueryManyFunc[T] {
|
||||
func QueryMany[T any](db *Database, query string, decoder func(v *T, decode ScanFunc) error) QueryManyFunc[T] {
|
||||
ctxfunc := QueryManyContext(db, query, decoder)
|
||||
return func(args ...interface{}) <-chan *T {
|
||||
return ctxfunc(context.Background(), args...)
|
||||
}
|
||||
}
|
||||
|
||||
func QueryManyContext[T any](db *Database, query string, decoder func(v *T, decode DecodeFunc) error) QueryManyContextFunc[T] {
|
||||
func QueryManyContext[T any](db *Database, query string, decoder func(v *T, decode ScanFunc) error) QueryManyContextFunc[T] {
|
||||
s, err := db.db.Prepare(query)
|
||||
if err != nil {
|
||||
return nil
|
||||
|
@ -2,14 +2,14 @@ package advsql
|
||||
|
||||
import "context"
|
||||
|
||||
func QueryOne[T any](db *Database, query string, decoder func(v *T, decode DecodeFunc) error) QueryOneFunc[T] {
|
||||
func QueryOne[T any](db *Database, query string, decoder func(v *T, decode ScanFunc) error) QueryOneFunc[T] {
|
||||
ctxfunc := QueryOneContext(db, query, decoder)
|
||||
return func(args ...interface{}) *T {
|
||||
return ctxfunc(context.Background(), args...)
|
||||
}
|
||||
}
|
||||
|
||||
func QueryOneContext[T any](db *Database, query string, decoder func(v *T, decode DecodeFunc) error) QueryOneContextFunc[T] {
|
||||
func QueryOneContext[T any](db *Database, query string, decoder func(v *T, decode ScanFunc) error) QueryOneContextFunc[T] {
|
||||
manyfunc := QueryManyContext(db, query, decoder)
|
||||
return func(ctx context.Context, args ...interface{}) *T {
|
||||
nctx, cancel := context.WithCancel(ctx)
|
||||
|
@ -1,5 +1,5 @@
|
||||
package advsql
|
||||
|
||||
func Update[T any](db *Database, query string, encoder func(v *T, encode EncodeFunc) error) UpdateFunc[T] {
|
||||
func Update[T any](db *Database, query string, encoder func(v *T, encode ScanFunc) error) UpdateFunc[T] {
|
||||
return UpdateFunc[T](Insert(db, query, encoder))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user