Skip to content

Commit feee775

Browse files
authored
Merge pull request #114 from Flux159/pr114
More adapter fixes for spanner typehints
2 parents e6f7cb1 + 16aeaf3 commit feee775

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/spanner/adapter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,15 @@ function generateTypeHintsFromParams(params?: Record<string, any>): Record<strin
249249
if (!params) return undefined;
250250

251251
const typeHints: Record<string, string> = {};
252+
let hasKeys = false;
252253
for (const key in params) {
253254
if (Object.prototype.hasOwnProperty.call(params, key)) {
254255
typeHints[key] = inferSpannerTypeFromValue(params[key]);
256+
hasKeys = true;
255257
}
256258
}
257-
return typeHints;
259+
// Return undefined if params is empty to avoid sending empty types object to Spanner
260+
return hasKeys ? typeHints : undefined;
258261
}
259262

260263
// Helper function to merge provided hints with inferred hints

test/spanner/adapter-type-hints.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,15 @@ class TestableSpannerAdapter {
167167
if (!params) return undefined;
168168

169169
const typeHints: Record<string, string> = {};
170+
let hasKeys = false;
170171
for (const key in params) {
171172
if (Object.prototype.hasOwnProperty.call(params, key)) {
172173
typeHints[key] = this.inferSpannerTypeFromValue(params[key]);
174+
hasKeys = true;
173175
}
174176
}
175-
return typeHints;
177+
// Return undefined if params is empty to avoid sending empty types object to Spanner
178+
return hasKeys ? typeHints : undefined;
176179
}
177180

178181
// Helper function to merge provided hints with inferred hints
@@ -673,6 +676,17 @@ describe("SpannerAdapter Type Hints", () => {
673676
});
674677

675678
describe("Automatic Type Inference", () => {
679+
it("should handle queries without parameters correctly", async () => {
680+
// No parameters at all
681+
const result1 = await adapter.query("SELECT * FROM test");
682+
// Mock returns "no_types" when no types are passed
683+
expect(result1).toEqual([{ result: "no_types" }]);
684+
685+
// Empty parameters object
686+
const result2 = await adapter.query("SELECT * FROM test", {});
687+
expect(result2).toEqual([{ result: "no_types" }]);
688+
});
689+
676690
it("should automatically infer types when no hints provided", async () => {
677691
const params = {
678692
stringParam: "test",

0 commit comments

Comments
 (0)