Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: untyped param types #1869

Merged
merged 15 commits into from
Feb 13, 2024
15 changes: 15 additions & 0 deletions samples/dml.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,21 @@ function updateUsingDmlWithStruct(instanceId, databaseId, projectId) {
params: {
name: nameStruct,
},
types: {
surbhigarg92 marked this conversation as resolved.
Show resolved Hide resolved
name: {
type: 'struct',
fields: [
{
name: 'FirstName',
type: 'string',
},
{
name: 'LastName',
type: 'string',
},
],
},
},
});

console.log(`Successfully updated ${rowCount} record.`);
Expand Down
30 changes: 30 additions & 0 deletions samples/struct.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ async function queryDataWithStruct(instanceId, databaseId, projectId) {
params: {
name: nameStruct,
},
types: {
name: {
type: 'struct',
fields: [
{
name: 'FirstName',
type: 'string',
},
{
name: 'LastName',
type: 'string',
},
],
},
},
};

// Queries rows from the Singers table
Expand Down Expand Up @@ -250,6 +265,21 @@ async function queryStructField(instanceId, databaseId, projectId) {
params: {
name: nameStruct,
},
types: {
name: {
type: 'struct',
fields: [
{
name: 'FirstName',
type: 'string',
},
{
name: 'LastName',
type: 'string',
},
],
},
},
};

// Queries rows from the Singers table
Expand Down
5 changes: 1 addition & 4 deletions src/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,6 @@ function getType(value: Value): Type {
return {type: 'bool'};
}

if (is.string(value)) {
return {type: 'string'};
}

if (Buffer.isBuffer(value)) {
return {type: 'bytes'};
}
Expand Down Expand Up @@ -643,6 +639,7 @@ function getType(value: Value): Type {
return {type: 'json'};
}

// String type is also returned as unspecified to allow untyped parameters
return {type: 'unspecified'};
}

Expand Down
5 changes: 4 additions & 1 deletion src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,10 @@ export class Snapshot extends EventEmitter {
if (!is.empty(typeMap)) {
Object.keys(typeMap).forEach(param => {
const type = typeMap[param];
paramTypes[param] = codec.createTypeObject(type);
const typeObject = codec.createTypeObject(type);
if (typeObject.code !== 'TYPE_CODE_UNSPECIFIED') {
paramTypes[param] = codec.createTypeObject(type);
}
});
}

Expand Down
Loading
Loading