Skip to content

Commit 83475b8

Browse files
committed
fixing starbase does not show column of empty table
1 parent d005281 commit 83475b8

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/drivers/sqlite-base-driver.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,31 @@ export abstract class SqliteLikeBaseDriver extends CommonSQLImplement {
329329
const orderPart =
330330
options.orderBy && options.orderBy.length > 0
331331
? options.orderBy
332-
.map((r) => `${this.escapeId(r.columnName)} ${r.by}`)
333-
.join(", ")
332+
.map((r) => `${this.escapeId(r.columnName)} ${r.by}`)
333+
.join(", ")
334334
: "";
335335

336-
const sql = `SELECT ${injectRowIdColumn ? "rowid, " : ""}* FROM ${this.escapeId(schemaName)}.${this.escapeId(tableName)}${
337-
whereRaw ? ` WHERE ${whereRaw} ` : ""
338-
} ${orderPart ? ` ORDER BY ${orderPart}` : ""} LIMIT ${escapeSqlValue(options.limit)} OFFSET ${escapeSqlValue(options.offset)};`;
336+
const sql = `SELECT ${injectRowIdColumn ? "rowid, " : ""}* FROM ${this.escapeId(schemaName)}.${this.escapeId(tableName)}${whereRaw ? ` WHERE ${whereRaw} ` : ""
337+
} ${orderPart ? ` ORDER BY ${orderPart}` : ""} LIMIT ${escapeSqlValue(options.limit)} OFFSET ${escapeSqlValue(options.offset)};`;
338+
339+
let data = await this.query(sql);
340+
341+
// If data does not have any header, we will inject the header from schema
342+
if (data.headers.length === 0 && data.rows.length === 0) {
343+
data = {
344+
...data,
345+
headers: schema.columns.map((col) => {
346+
return {
347+
name: col.name,
348+
originalType: col.type,
349+
displayName: col.name,
350+
};
351+
}),
352+
};
353+
}
339354

340355
return {
341-
data: await this.query(sql),
356+
data,
342357
schema,
343358
};
344359
}

0 commit comments

Comments
 (0)