pgx/pgtype/name.go
Jack Christensen 1f3e484ca1 pgtype.Encode(Binary|Text) do not write length
To aid in composability, these methods no longer write their own length. This
is especially useful for text formatted arrays and may be useful for future
database/sql compatibility. It also makes the code a little simpler as the
types no longer have to compute their own size.

Along with this, these methods cannot encode NULL. They now return a boolean
if they are NULL. This also benefits text array encoding as numeric arrays
require NULL to be exactly `NULL` while string arrays require NULL to be
`"NULL"`.
2017-03-11 12:45:30 -06:00

45 lines
1.2 KiB
Go

package pgtype
import (
"io"
)
// Name is a type used for PostgreSQL's special 63-byte
// name data type, used for identifiers like table names.
// The pg_class.relname column is a good example of where the
// name data type is used.
//
// Note that the underlying Go data type of pgx.Name is string,
// so there is no way to enforce the 63-byte length. Inputting
// a longer name into PostgreSQL will result in silent truncation
// to 63 bytes.
//
// Also, if you have custom-compiled PostgreSQL and set
// NAMEDATALEN to a different value, obviously that number of
// bytes applies, rather than the default 63.
type Name Text
func (dst *Name) ConvertFrom(src interface{}) error {
return (*Text)(dst).ConvertFrom(src)
}
func (src *Name) AssignTo(dst interface{}) error {
return (*Text)(src).AssignTo(dst)
}
func (dst *Name) DecodeText(src []byte) error {
return (*Text)(dst).DecodeText(src)
}
func (dst *Name) DecodeBinary(src []byte) error {
return (*Text)(dst).DecodeBinary(src)
}
func (src Name) EncodeText(w io.Writer) (bool, error) {
return (Text)(src).EncodeText(w)
}
func (src Name) EncodeBinary(w io.Writer) (bool, error) {
return (Text)(src).EncodeBinary(w)
}