mirror of https://github.com/jackc/pgx.git
Generate text to int scan plans
parent
b99d95470f
commit
77b9b59622
|
@ -131,213 +131,3 @@ func (scanPlanBinaryInt2ToInt16) Scan(ci *ConnInfo, oid uint32, formatCode int16
|
|||
*p = int16(binary.BigEndian.Uint16(src))
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToInt8 struct{}
|
||||
|
||||
func (scanPlanTextAnyToInt8) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*int8)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseInt(string(src), 10, 8)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = int8(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToInt16 struct{}
|
||||
|
||||
func (scanPlanTextAnyToInt16) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*int16)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseInt(string(src), 10, 16)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = int16(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToInt32 struct{}
|
||||
|
||||
func (scanPlanTextAnyToInt32) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*int32)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseInt(string(src), 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = int32(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToInt64 struct{}
|
||||
|
||||
func (scanPlanTextAnyToInt64) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*int64)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseInt(string(src), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = int64(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToInt struct{}
|
||||
|
||||
func (scanPlanTextAnyToInt) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*int)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseInt(string(src), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = int(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToUint8 struct{}
|
||||
|
||||
func (scanPlanTextAnyToUint8) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*uint8)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseUint(string(src), 10, 8)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = uint8(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToUint16 struct{}
|
||||
|
||||
func (scanPlanTextAnyToUint16) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*uint16)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseUint(string(src), 10, 16)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = uint16(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToUint32 struct{}
|
||||
|
||||
func (scanPlanTextAnyToUint32) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*uint32)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseUint(string(src), 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = uint32(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToUint64 struct{}
|
||||
|
||||
func (scanPlanTextAnyToUint64) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*uint64)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseUint(string(src), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = uint64(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToUint struct{}
|
||||
|
||||
func (scanPlanTextAnyToUint) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*uint)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseUint(string(src), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = uint(n)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,216 @@
|
|||
package pgtype
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type scanPlanTextAnyToInt8 struct{}
|
||||
|
||||
func (scanPlanTextAnyToInt8) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*int8)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseInt(string(src), 10, 8)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = int8(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToUint8 struct{}
|
||||
|
||||
func (scanPlanTextAnyToUint8) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*uint8)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseUint(string(src), 10, 8)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = uint8(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToInt16 struct{}
|
||||
|
||||
func (scanPlanTextAnyToInt16) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*int16)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseInt(string(src), 10, 16)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = int16(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToUint16 struct{}
|
||||
|
||||
func (scanPlanTextAnyToUint16) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*uint16)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseUint(string(src), 10, 16)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = uint16(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToInt32 struct{}
|
||||
|
||||
func (scanPlanTextAnyToInt32) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*int32)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseInt(string(src), 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = int32(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToUint32 struct{}
|
||||
|
||||
func (scanPlanTextAnyToUint32) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*uint32)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseUint(string(src), 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = uint32(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToInt64 struct{}
|
||||
|
||||
func (scanPlanTextAnyToInt64) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*int64)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseInt(string(src), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = int64(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToUint64 struct{}
|
||||
|
||||
func (scanPlanTextAnyToUint64) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*uint64)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseUint(string(src), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = uint64(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToInt struct{}
|
||||
|
||||
func (scanPlanTextAnyToInt) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*int)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseInt(string(src), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = int(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToUint struct{}
|
||||
|
||||
func (scanPlanTextAnyToUint) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*uint)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseUint(string(src), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = uint(n)
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package pgtype
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
<% [
|
||||
["8", 8],
|
||||
["16", 16],
|
||||
["32", 32],
|
||||
["64", 64],
|
||||
["", 0]
|
||||
].each do |type_suffix, bit_size| %>
|
||||
type scanPlanTextAnyToInt<%= type_suffix %> struct{}
|
||||
|
||||
func (scanPlanTextAnyToInt<%= type_suffix %>) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*int<%= type_suffix %>)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseInt(string(src), 10, <%= bit_size %>)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = int<%= type_suffix %>(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToUint<%= type_suffix %> struct{}
|
||||
|
||||
func (scanPlanTextAnyToUint<%= type_suffix %>) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if src == nil {
|
||||
return fmt.Errorf("cannot scan null into %T", dst)
|
||||
}
|
||||
|
||||
p, ok := (dst).(*uint<%= type_suffix %>)
|
||||
if !ok {
|
||||
return ErrScanTargetTypeChanged
|
||||
}
|
||||
|
||||
n, err := strconv.ParseUint(string(src), 10, <%= bit_size %>)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = uint<%= type_suffix %>(n)
|
||||
return nil
|
||||
}
|
||||
<% end %>
|
Loading…
Reference in New Issue