Skip to content

Commit 944efcd

Browse files
committed
feat(spanner): support for type UUID
1 parent f23a248 commit 944efcd

File tree

6 files changed

+458
-4
lines changed

6 files changed

+458
-4
lines changed

src/codec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {Big} from 'big.js';
3333
import {common as p} from 'protobufjs';
3434
import {google as spannerClient} from '../protos/protos';
3535
import {GoogleError} from 'google-gax';
36+
import * as uuid from 'uuid';
3637

3738
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3839
export type Value = any;
@@ -1034,6 +1035,7 @@ const TypeCode: {
10341035
bool: 'BOOL',
10351036
int64: 'INT64',
10361037
pgOid: 'INT64',
1038+
uuid: 'UUID',
10371039
float32: 'FLOAT32',
10381040
float64: 'FLOAT64',
10391041
numeric: 'NUMERIC',
@@ -1075,6 +1077,7 @@ interface FieldType extends Type {
10751077
/**
10761078
* @typedef {object} ParamType
10771079
* @property {string} type The param type. Must be one of the following:
1080+
* - uuid
10781081
* - float32
10791082
* - float64
10801083
* - int64
@@ -1157,6 +1160,10 @@ function getType(value: Value): Type {
11571160
return {type: 'bool'};
11581161
}
11591162

1163+
if (uuid.validate(value)) {
1164+
return {type: 'unspecified'};
1165+
}
1166+
11601167
if (isString(value)) {
11611168
return {type: 'string'};
11621169
}

src/transaction.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,15 @@ export class Snapshot extends EventEmitter {
17281728
if (!isEmpty(typeMap)) {
17291729
Object.keys(typeMap).forEach(param => {
17301730
const type = typeMap[param];
1731-
paramTypes[param] = codec.createTypeObject(type);
1731+
const typeObject = codec.createTypeObject(type);
1732+
if (
1733+
(type.child &&
1734+
typeObject.code === 'ARRAY' &&
1735+
typeObject.arrayElementType?.code !== 'TYPE_CODE_UNSPECIFIED') ||
1736+
(!type.child && typeObject.code !== 'TYPE_CODE_UNSPECIFIED')
1737+
) {
1738+
paramTypes[param] = codec.createTypeObject(type);
1739+
}
17321740
});
17331741
}
17341742

0 commit comments

Comments
 (0)