Add multidimensional array and slice support.
Adds array support - previously only slices were supported. Adds new test cases for multidimensional arrays and slices. All previous test cases are unmodified and passed (fully backwards compatible). Removes hard-coded type conversions for arrays, instead now relies on the type support of the array element's type conversion support. Less maintenance for arrays, new type conversions are automatically supported when array's element gains new type support. Simplifies typed_array_gen.sh generator script by removing the hard-coded single-dimensional types for arrays. Only typed_array.go.erb and typed_array_gen.sh have been changed + 1 new auxiliary function in array.go file + additional tests in test files for each array. Other changes are from generated code.
This commit is contained in:
@@ -68,6 +68,54 @@ func TestByteaArraySet(t *testing.T) {
|
||||
source: (([][]byte)(nil)),
|
||||
result: pgtype.ByteaArray{Status: pgtype.Null},
|
||||
},
|
||||
{
|
||||
source: [][][]byte{{{1}}, {{2}}},
|
||||
result: pgtype.ByteaArray{
|
||||
Elements: []pgtype.Bytea{{Bytes: []byte{1}, Status: pgtype.Present}, {Bytes: []byte{2}, Status: pgtype.Present}},
|
||||
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 2}, {LowerBound: 1, Length: 1}},
|
||||
Status: pgtype.Present},
|
||||
},
|
||||
{
|
||||
source: [][][][][]byte{{{{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}}}, {{{{10, 11, 12}, {13, 14, 15}, {16, 17, 18}}}}},
|
||||
result: pgtype.ByteaArray{
|
||||
Elements: []pgtype.Bytea{
|
||||
{Bytes: []byte{1, 2, 3}, Status: pgtype.Present},
|
||||
{Bytes: []byte{4, 5, 6}, Status: pgtype.Present},
|
||||
{Bytes: []byte{7, 8, 9}, Status: pgtype.Present},
|
||||
{Bytes: []byte{10, 11, 12}, Status: pgtype.Present},
|
||||
{Bytes: []byte{13, 14, 15}, Status: pgtype.Present},
|
||||
{Bytes: []byte{16, 17, 18}, Status: pgtype.Present}},
|
||||
Dimensions: []pgtype.ArrayDimension{
|
||||
{LowerBound: 1, Length: 2},
|
||||
{LowerBound: 1, Length: 1},
|
||||
{LowerBound: 1, Length: 1},
|
||||
{LowerBound: 1, Length: 3}},
|
||||
Status: pgtype.Present},
|
||||
},
|
||||
{
|
||||
source: [2][1][]byte{{{1}}, {{2}}},
|
||||
result: pgtype.ByteaArray{
|
||||
Elements: []pgtype.Bytea{{Bytes: []byte{1}, Status: pgtype.Present}, {Bytes: []byte{2}, Status: pgtype.Present}},
|
||||
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 2}, {LowerBound: 1, Length: 1}},
|
||||
Status: pgtype.Present},
|
||||
},
|
||||
{
|
||||
source: [2][1][1][3][]byte{{{{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}}}, {{{{10, 11, 12}, {13, 14, 15}, {16, 17, 18}}}}},
|
||||
result: pgtype.ByteaArray{
|
||||
Elements: []pgtype.Bytea{
|
||||
{Bytes: []byte{1, 2, 3}, Status: pgtype.Present},
|
||||
{Bytes: []byte{4, 5, 6}, Status: pgtype.Present},
|
||||
{Bytes: []byte{7, 8, 9}, Status: pgtype.Present},
|
||||
{Bytes: []byte{10, 11, 12}, Status: pgtype.Present},
|
||||
{Bytes: []byte{13, 14, 15}, Status: pgtype.Present},
|
||||
{Bytes: []byte{16, 17, 18}, Status: pgtype.Present}},
|
||||
Dimensions: []pgtype.ArrayDimension{
|
||||
{LowerBound: 1, Length: 2},
|
||||
{LowerBound: 1, Length: 1},
|
||||
{LowerBound: 1, Length: 1},
|
||||
{LowerBound: 1, Length: 3}},
|
||||
Status: pgtype.Present},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range successfulTests {
|
||||
@@ -85,6 +133,10 @@ func TestByteaArraySet(t *testing.T) {
|
||||
|
||||
func TestByteaArrayAssignTo(t *testing.T) {
|
||||
var byteByteSlice [][]byte
|
||||
var byteByteSliceDim2 [][][]byte
|
||||
var byteByteSliceDim4 [][][][][]byte
|
||||
var byteByteArraySliceDim2 [2][1][]byte
|
||||
var byteByteArraySliceDim4 [2][1][1][3][]byte
|
||||
|
||||
simpleTests := []struct {
|
||||
src pgtype.ByteaArray
|
||||
@@ -105,6 +157,58 @@ func TestByteaArrayAssignTo(t *testing.T) {
|
||||
dst: &byteByteSlice,
|
||||
expected: (([][]byte)(nil)),
|
||||
},
|
||||
{
|
||||
src: pgtype.ByteaArray{
|
||||
Elements: []pgtype.Bytea{{Bytes: []byte{1}, Status: pgtype.Present}, {Bytes: []byte{2}, Status: pgtype.Present}},
|
||||
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 2}, {LowerBound: 1, Length: 1}},
|
||||
Status: pgtype.Present},
|
||||
dst: &byteByteSliceDim2,
|
||||
expected: [][][]byte{{{1}}, {{2}}},
|
||||
},
|
||||
{
|
||||
src: pgtype.ByteaArray{
|
||||
Elements: []pgtype.Bytea{
|
||||
{Bytes: []byte{1, 2, 3}, Status: pgtype.Present},
|
||||
{Bytes: []byte{4, 5, 6}, Status: pgtype.Present},
|
||||
{Bytes: []byte{7, 8, 9}, Status: pgtype.Present},
|
||||
{Bytes: []byte{10, 11, 12}, Status: pgtype.Present},
|
||||
{Bytes: []byte{13, 14, 15}, Status: pgtype.Present},
|
||||
{Bytes: []byte{16, 17, 18}, Status: pgtype.Present}},
|
||||
Dimensions: []pgtype.ArrayDimension{
|
||||
{LowerBound: 1, Length: 2},
|
||||
{LowerBound: 1, Length: 1},
|
||||
{LowerBound: 1, Length: 1},
|
||||
{LowerBound: 1, Length: 3}},
|
||||
Status: pgtype.Present},
|
||||
dst: &byteByteSliceDim4,
|
||||
expected: [][][][][]byte{{{{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}}}, {{{{10, 11, 12}, {13, 14, 15}, {16, 17, 18}}}}},
|
||||
},
|
||||
{
|
||||
src: pgtype.ByteaArray{
|
||||
Elements: []pgtype.Bytea{{Bytes: []byte{1}, Status: pgtype.Present}, {Bytes: []byte{2}, Status: pgtype.Present}},
|
||||
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 2}, {LowerBound: 1, Length: 1}},
|
||||
Status: pgtype.Present},
|
||||
dst: &byteByteArraySliceDim2,
|
||||
expected: [2][1][]byte{{{1}}, {{2}}},
|
||||
},
|
||||
{
|
||||
src: pgtype.ByteaArray{
|
||||
Elements: []pgtype.Bytea{
|
||||
{Bytes: []byte{1, 2, 3}, Status: pgtype.Present},
|
||||
{Bytes: []byte{4, 5, 6}, Status: pgtype.Present},
|
||||
{Bytes: []byte{7, 8, 9}, Status: pgtype.Present},
|
||||
{Bytes: []byte{10, 11, 12}, Status: pgtype.Present},
|
||||
{Bytes: []byte{13, 14, 15}, Status: pgtype.Present},
|
||||
{Bytes: []byte{16, 17, 18}, Status: pgtype.Present}},
|
||||
Dimensions: []pgtype.ArrayDimension{
|
||||
{LowerBound: 1, Length: 2},
|
||||
{LowerBound: 1, Length: 1},
|
||||
{LowerBound: 1, Length: 1},
|
||||
{LowerBound: 1, Length: 3}},
|
||||
Status: pgtype.Present},
|
||||
dst: &byteByteArraySliceDim4,
|
||||
expected: [2][1][1][3][]byte{{{{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}}}, {{{{10, 11, 12}, {13, 14, 15}, {16, 17, 18}}}}},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range simpleTests {
|
||||
|
||||
Reference in New Issue
Block a user