1
0
mirror of https://github.com/jackc/pgx.git synced 2025-04-27 21:25:53 +00:00

Remove Set self support from pgtype

Set having the capability to assign an object of the same type was
inconsistently implemented. Some places it was not implemented at all, some
places it was a shallow copy, some places a deep copy. Given that it doesn't
seem likely to ever be used, and if it is needed it is easy enough to do
outside of the library this code has been removed.
This commit is contained in:
Jack Christensen 2017-03-11 20:18:56 -06:00
parent b94ccae4c9
commit a79b498533
36 changed files with 0 additions and 64 deletions

@ -25,8 +25,6 @@ type Aclitem struct {
func (dst *Aclitem) Set(src interface{}) error {
switch value := src.(type) {
case Aclitem:
*dst = value
case string:
*dst = Aclitem{String: value, Status: Present}
case *string:

@ -16,8 +16,6 @@ type AclitemArray struct {
func (dst *AclitemArray) Set(src interface{}) error {
switch value := src.(type) {
case AclitemArray:
*dst = value
case []string:
if value == nil {

@ -20,7 +20,6 @@ func TestAclitemSet(t *testing.T) {
source interface{}
result pgtype.Aclitem
}{
{source: pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present}, result: pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present}},
{source: "postgres=arwdDxt/postgres", result: pgtype.Aclitem{String: "postgres=arwdDxt/postgres", Status: pgtype.Present}},
{source: (*string)(nil), result: pgtype.Aclitem{Status: pgtype.Null}},
}

@ -14,8 +14,6 @@ type Bool struct {
func (dst *Bool) Set(src interface{}) error {
switch value := src.(type) {
case Bool:
*dst = value
case bool:
*dst = Bool{Bool: value, Status: Present}
case string:

@ -17,8 +17,6 @@ type BoolArray struct {
func (dst *BoolArray) Set(src interface{}) error {
switch value := src.(type) {
case BoolArray:
*dst = value
case []bool:
if value == nil {

@ -20,7 +20,6 @@ func TestBoolSet(t *testing.T) {
source interface{}
result pgtype.Bool
}{
{source: pgtype.Bool{Bool: false, Status: pgtype.Null}, result: pgtype.Bool{Bool: false, Status: pgtype.Null}},
{source: true, result: pgtype.Bool{Bool: true, Status: pgtype.Present}},
{source: false, result: pgtype.Bool{Bool: false, Status: pgtype.Present}},
{source: "true", result: pgtype.Bool{Bool: true, Status: pgtype.Present}},

@ -14,8 +14,6 @@ type Bytea struct {
func (dst *Bytea) Set(src interface{}) error {
switch value := src.(type) {
case Bytea:
*dst = value
case []byte:
if value != nil {
*dst = Bytea{Bytes: value, Status: Present}

@ -17,8 +17,6 @@ type ByteaArray struct {
func (dst *ByteaArray) Set(src interface{}) error {
switch value := src.(type) {
case ByteaArray:
*dst = value
case [][]byte:
if value == nil {

@ -20,7 +20,6 @@ func TestByteaSet(t *testing.T) {
source interface{}
result pgtype.Bytea
}{
{source: pgtype.Bytea{Bytes: []byte{1, 2, 3}, Status: pgtype.Null}, result: pgtype.Bytea{Bytes: []byte{1, 2, 3}, Status: pgtype.Null}},
{source: []byte{1, 2, 3}, result: pgtype.Bytea{Bytes: []byte{1, 2, 3}, Status: pgtype.Present}},
{source: []byte{}, result: pgtype.Bytea{Bytes: []byte{}, Status: pgtype.Present}},
{source: []byte(nil), result: pgtype.Bytea{Status: pgtype.Null}},

@ -23,8 +23,6 @@ const (
func (dst *Date) Set(src interface{}) error {
switch value := src.(type) {
case Date:
*dst = value
case time.Time:
*dst = Date{Time: value, Status: Present}
default:

@ -18,8 +18,6 @@ type DateArray struct {
func (dst *DateArray) Set(src interface{}) error {
switch value := src.(type) {
case DateArray:
*dst = value
case []time.Time:
if value == nil {

@ -29,7 +29,6 @@ func TestDateSet(t *testing.T) {
source interface{}
result pgtype.Date
}{
{source: pgtype.Date{Time: time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}, result: pgtype.Date{Time: time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}},
{source: time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC), result: pgtype.Date{Time: time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}},
{source: time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC), result: pgtype.Date{Time: time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}},
{source: time.Date(1999, 12, 31, 0, 0, 0, 0, time.UTC), result: pgtype.Date{Time: time.Date(1999, 12, 31, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}},

@ -17,8 +17,6 @@ type Float4 struct {
func (dst *Float4) Set(src interface{}) error {
switch value := src.(type) {
case Float4:
*dst = value
case float32:
*dst = Float4{Float: value, Status: Present}
case float64:

@ -17,8 +17,6 @@ type Float4Array struct {
func (dst *Float4Array) Set(src interface{}) error {
switch value := src.(type) {
case Float4Array:
*dst = value
case []float32:
if value == nil {

@ -17,8 +17,6 @@ type Float8 struct {
func (dst *Float8) Set(src interface{}) error {
switch value := src.(type) {
case Float8:
*dst = value
case float32:
*dst = Float8{Float: float64(value), Status: Present}
case float64:

@ -17,8 +17,6 @@ type Float8Array struct {
func (dst *Float8Array) Set(src interface{}) error {
switch value := src.(type) {
case Float8Array:
*dst = value
case []float64:
if value == nil {

@ -25,8 +25,6 @@ type Inet struct {
func (dst *Inet) Set(src interface{}) error {
switch value := src.(type) {
case Inet:
*dst = value
case net.IPNet:
*dst = Inet{IPNet: &value, Status: Present}
case *net.IPNet:

@ -18,8 +18,6 @@ type InetArray struct {
func (dst *InetArray) Set(src interface{}) error {
switch value := src.(type) {
case InetArray:
*dst = value
case []*net.IPNet:
if value == nil {

@ -31,7 +31,6 @@ func TestInetSet(t *testing.T) {
source interface{}
result pgtype.Inet
}{
{source: pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Null}, result: pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Null}},
{source: mustParseCidr(t, "127.0.0.1/32"), result: pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}},
{source: mustParseCidr(t, "127.0.0.1/32").IP, result: pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}},
{source: "127.0.0.1/32", result: pgtype.Inet{IPNet: mustParseCidr(t, "127.0.0.1/32"), Status: pgtype.Present}},

@ -17,8 +17,6 @@ type Int2 struct {
func (dst *Int2) Set(src interface{}) error {
switch value := src.(type) {
case Int2:
*dst = value
case int8:
*dst = Int2{Int: int16(value), Status: Present}
case uint8:

@ -17,8 +17,6 @@ type Int2Array struct {
func (dst *Int2Array) Set(src interface{}) error {
switch value := src.(type) {
case Int2Array:
*dst = value
case []int16:
if value == nil {

@ -17,8 +17,6 @@ type Int4 struct {
func (dst *Int4) Set(src interface{}) error {
switch value := src.(type) {
case Int4:
*dst = value
case int8:
*dst = Int4{Int: int32(value), Status: Present}
case uint8:

@ -17,8 +17,6 @@ type Int4Array struct {
func (dst *Int4Array) Set(src interface{}) error {
switch value := src.(type) {
case Int4Array:
*dst = value
case []int32:
if value == nil {

@ -17,8 +17,6 @@ type Int8 struct {
func (dst *Int8) Set(src interface{}) error {
switch value := src.(type) {
case Int8:
*dst = value
case int8:
*dst = Int8{Int: int64(value), Status: Present}
case uint8:

@ -17,8 +17,6 @@ type Int8Array struct {
func (dst *Int8Array) Set(src interface{}) error {
switch value := src.(type) {
case Int8Array:
*dst = value
case []int64:
if value == nil {

@ -25,8 +25,6 @@ type QChar struct {
func (dst *QChar) Set(src interface{}) error {
switch value := src.(type) {
case QChar:
*dst = value
case int8:
*dst = QChar{Int: value, Status: Present}
case uint8:

@ -13,8 +13,6 @@ type Text struct {
func (dst *Text) Set(src interface{}) error {
switch value := src.(type) {
case Text:
*dst = value
case string:
*dst = Text{String: value, Status: Present}
case *string:

@ -17,8 +17,6 @@ type TextArray struct {
func (dst *TextArray) Set(src interface{}) error {
switch value := src.(type) {
case TextArray:
*dst = value
case []string:
if value == nil {

@ -22,7 +22,6 @@ func TestTextSet(t *testing.T) {
source interface{}
result pgtype.Text
}{
{source: pgtype.Text{String: "foo", Status: pgtype.Present}, result: pgtype.Text{String: "foo", Status: pgtype.Present}},
{source: "foo", result: pgtype.Text{String: "foo", Status: pgtype.Present}},
{source: _string("bar"), result: pgtype.Text{String: "bar", Status: pgtype.Present}},
{source: (*string)(nil), result: pgtype.Text{Status: pgtype.Null}},

@ -27,8 +27,6 @@ type Timestamp struct {
// time.Time in a non-UTC time zone, the time zone is discarded.
func (dst *Timestamp) Set(src interface{}) error {
switch value := src.(type) {
case Timestamp:
*dst = value
case time.Time:
*dst = Timestamp{Time: time.Date(value.Year(), value.Month(), value.Day(), value.Hour(), value.Minute(), value.Second(), value.Nanosecond(), time.UTC), Status: Present}
default:

@ -18,8 +18,6 @@ type TimestampArray struct {
func (dst *TimestampArray) Set(src interface{}) error {
switch value := src.(type) {
case TimestampArray:
*dst = value
case []time.Time:
if value == nil {

@ -38,7 +38,6 @@ func TestTimestampSet(t *testing.T) {
source interface{}
result pgtype.Timestamp
}{
{source: pgtype.Timestamp{Time: time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}, result: pgtype.Timestamp{Time: time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}},
{source: time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC), result: pgtype.Timestamp{Time: time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}},
{source: time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC), result: pgtype.Timestamp{Time: time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC), Status: pgtype.Present}},
{source: time.Date(1999, 12, 31, 12, 59, 59, 0, time.UTC), result: pgtype.Timestamp{Time: time.Date(1999, 12, 31, 12, 59, 59, 0, time.UTC), Status: pgtype.Present}},

@ -28,8 +28,6 @@ type Timestamptz struct {
func (dst *Timestamptz) Set(src interface{}) error {
switch value := src.(type) {
case Timestamptz:
*dst = value
case time.Time:
*dst = Timestamptz{Time: value, Status: Present}
default:

@ -18,8 +18,6 @@ type TimestamptzArray struct {
func (dst *TimestamptzArray) Set(src interface{}) error {
switch value := src.(type) {
case TimestamptzArray:
*dst = value
case []time.Time:
if value == nil {

@ -38,7 +38,6 @@ func TestTimestamptzSet(t *testing.T) {
source interface{}
result pgtype.Timestamptz
}{
{source: pgtype.Timestamptz{Time: time.Date(1900, 1, 1, 0, 0, 0, 0, time.Local), Status: pgtype.Present}, result: pgtype.Timestamptz{Time: time.Date(1900, 1, 1, 0, 0, 0, 0, time.Local), Status: pgtype.Present}},
{source: time.Date(1900, 1, 1, 0, 0, 0, 0, time.Local), result: pgtype.Timestamptz{Time: time.Date(1900, 1, 1, 0, 0, 0, 0, time.Local), Status: pgtype.Present}},
{source: time.Date(1970, 1, 1, 0, 0, 0, 0, time.Local), result: pgtype.Timestamptz{Time: time.Date(1970, 1, 1, 0, 0, 0, 0, time.Local), Status: pgtype.Present}},
{source: time.Date(1999, 12, 31, 12, 59, 59, 0, time.Local), result: pgtype.Timestamptz{Time: time.Date(1999, 12, 31, 12, 59, 59, 0, time.Local), Status: pgtype.Present}},

@ -16,8 +16,6 @@ type <%= pgtype_array_type %> struct {
func (dst *<%= pgtype_array_type %>) Set(src interface{}) error {
switch value := src.(type) {
case <%= pgtype_array_type %>:
*dst = value
<% go_array_types.split(",").each do |t| %>
case <%= t %>:
if value == nil {