mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-05-20 17:28:40 +00:00
2dc9fc1626
* start moving to bun * changing more stuff * more * and yet more * tests passing * seems stable now * more big changes * small fix * little fixes
42 lines
827 B
Go
42 lines
827 B
Go
package pgtype
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"errors"
|
|
)
|
|
|
|
func DatabaseSQLValue(ci *ConnInfo, src Value) (interface{}, error) {
|
|
if valuer, ok := src.(driver.Valuer); ok {
|
|
return valuer.Value()
|
|
}
|
|
|
|
if textEncoder, ok := src.(TextEncoder); ok {
|
|
buf, err := textEncoder.EncodeText(ci, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return string(buf), nil
|
|
}
|
|
|
|
if binaryEncoder, ok := src.(BinaryEncoder); ok {
|
|
buf, err := binaryEncoder.EncodeBinary(ci, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return buf, nil
|
|
}
|
|
|
|
return nil, errors.New("cannot convert to database/sql compatible value")
|
|
}
|
|
|
|
func EncodeValueText(src TextEncoder) (interface{}, error) {
|
|
buf, err := src.EncodeText(nil, make([]byte, 0, 32))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if buf == nil {
|
|
return nil, nil
|
|
}
|
|
return string(buf), err
|
|
}
|