Skip to content

Commit e9e8d0c

Browse files
authored
Better handling of column names with setTypes method (#1025)
1 parent 9a2a575 commit e9e8d0c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/class/SimpleTable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export default class SimpleTable extends Simple {
277277
Object.keys(
278278
types,
279279
)
280-
.map((d) => `${d} ${parseType(types[d])}`)
280+
.map((d) => `"${d}" ${parseType(types[d])}`)
281281
.join(", ")
282282
});`,
283283
mergeOptions(this, {

test/unit/methods/setTypes.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,29 @@ Deno.test("should create a new SimpleTable with geometry in types", async () =>
2525
);
2626
await sdb.done();
2727
});
28+
29+
Deno.test("should create a new SimpleTable with types and column names containing spaces", async () => {
30+
const sdb = new SimpleDB();
31+
const table = sdb.newTable("data");
32+
await table.setTypes({ "first name": "string", age: "number" });
33+
const types = await table.getTypes();
34+
assertEquals(types, { "first name": "VARCHAR", age: "DOUBLE" });
35+
await sdb.done();
36+
});
37+
38+
Deno.test("should create a new SimpleTable with types and column names with special uses", async () => {
39+
const sdb = new SimpleDB();
40+
const table = sdb.newTable("data");
41+
await table.setTypes({
42+
"first name": "string",
43+
age: "number",
44+
Group: "string",
45+
});
46+
const types = await table.getTypes();
47+
assertEquals(types, {
48+
"first name": "VARCHAR",
49+
age: "DOUBLE",
50+
Group: "VARCHAR",
51+
});
52+
await sdb.done();
53+
});

0 commit comments

Comments
 (0)