@@ -192,6 +192,35 @@ describe('codec', () => {
192
192
} ) ;
193
193
} ) ;
194
194
195
+ describe ( 'PGOid' , ( ) => {
196
+ it ( 'should stringify the value' , ( ) => {
197
+ const value = 8 ;
198
+ const oid = new codec . PGOid ( value ) ;
199
+
200
+ assert . strictEqual ( oid . value , '8' ) ;
201
+ } ) ;
202
+
203
+ it ( 'should return as a number' , ( ) => {
204
+ const value = 8 ;
205
+ const oid = new codec . PGOid ( value ) ;
206
+
207
+ assert . strictEqual ( oid . valueOf ( ) , 8 ) ;
208
+ assert . strictEqual ( oid + 2 , 10 ) ;
209
+ } ) ;
210
+
211
+ it ( 'should throw if number is out of bounds' , ( ) => {
212
+ const value = '9223372036854775807' ;
213
+ const oid = new codec . PGOid ( value ) ;
214
+
215
+ assert . throws (
216
+ ( ) => {
217
+ oid . valueOf ( ) ;
218
+ } ,
219
+ new RegExp ( 'PG.OID ' + value + ' is out of bounds.' )
220
+ ) ;
221
+ } ) ;
222
+ } ) ;
223
+
195
224
describe ( 'Numeric' , ( ) => {
196
225
it ( 'should store value as a string' , ( ) => {
197
226
const value = '8.01911' ;
@@ -601,6 +630,18 @@ describe('codec', () => {
601
630
assert . deepStrictEqual ( decoded . toString ( ) , expected ) ;
602
631
} ) ;
603
632
633
+ it ( 'should decode PG OID' , ( ) => {
634
+ const value = '64' ;
635
+
636
+ const decoded = codec . decode ( value , {
637
+ code : google . spanner . v1 . TypeCode . INT64 ,
638
+ typeAnnotation : google . spanner . v1 . TypeAnnotationCode . PG_OID ,
639
+ } ) ;
640
+
641
+ assert ( decoded instanceof codec . PGOid ) ;
642
+ assert . strictEqual ( decoded . value , value ) ;
643
+ } ) ;
644
+
604
645
it ( 'should decode TIMESTAMP' , ( ) => {
605
646
const value = new Date ( ) ;
606
647
const expected = new PreciseDate ( value . getTime ( ) ) ;
@@ -821,6 +862,14 @@ describe('codec', () => {
821
862
assert . strictEqual ( encoded , '10' ) ;
822
863
} ) ;
823
864
865
+ it ( 'should encode PG OID' , ( ) => {
866
+ const value = new codec . PGOid ( 10 ) ;
867
+
868
+ const encoded = codec . encode ( value ) ;
869
+
870
+ assert . strictEqual ( encoded , '10' ) ;
871
+ } ) ;
872
+
824
873
it ( 'should encode FLOAT64' , ( ) => {
825
874
const value = new codec . Float ( 10 ) ;
826
875
@@ -986,6 +1035,12 @@ describe('codec', () => {
986
1035
type : 'pgNumeric' ,
987
1036
} ) ;
988
1037
} ) ;
1038
+
1039
+ it ( 'should determine if the value is a PGOid' , ( ) => {
1040
+ assert . deepStrictEqual ( codec . getType ( new codec . PGOid ( 5678 ) ) , {
1041
+ type : 'pgOid' ,
1042
+ } ) ;
1043
+ } ) ;
989
1044
} ) ;
990
1045
991
1046
describe ( 'convertToListValue' , ( ) => {
@@ -1211,5 +1266,23 @@ describe('codec', () => {
1211
1266
typeAnnotation : google . spanner . v1 . TypeAnnotationCode . PG_NUMERIC ,
1212
1267
} ) ;
1213
1268
} ) ;
1269
+
1270
+ it ( 'should set code and typeAnnotation for pgOid string' , ( ) => {
1271
+ const type = codec . createTypeObject ( 'pgOid' ) ;
1272
+
1273
+ assert . deepStrictEqual ( type , {
1274
+ code : google . spanner . v1 . TypeCode [ google . spanner . v1 . TypeCode . INT64 ] ,
1275
+ typeAnnotation : google . spanner . v1 . TypeAnnotationCode . PG_OID ,
1276
+ } ) ;
1277
+ } ) ;
1278
+
1279
+ it ( 'should set code and typeAnnotation for pgOid friendlyType object' , ( ) => {
1280
+ const type = codec . createTypeObject ( { type : 'pgOid' } ) ;
1281
+
1282
+ assert . deepStrictEqual ( type , {
1283
+ code : google . spanner . v1 . TypeCode [ google . spanner . v1 . TypeCode . INT64 ] ,
1284
+ typeAnnotation : google . spanner . v1 . TypeAnnotationCode . PG_OID ,
1285
+ } ) ;
1286
+ } ) ;
1214
1287
} ) ;
1215
1288
} ) ;
0 commit comments