This commit is contained in:
@@ -7,6 +7,11 @@ export interface Column {
|
||||
type: string;
|
||||
}
|
||||
|
||||
export interface SortColumn {
|
||||
name: string;
|
||||
sortType: 'asc' | 'desc';
|
||||
}
|
||||
|
||||
export interface RowsResponse {
|
||||
rows: any[];
|
||||
totalRows: bigint;
|
||||
@@ -98,6 +103,7 @@ export class DuckdbService {
|
||||
start: number,
|
||||
numRows: number,
|
||||
columns: Column[],
|
||||
sorts: SortColumn[],
|
||||
filters: unknown[],
|
||||
aggregations: unknown[],
|
||||
): Promise<RowsResponse> {
|
||||
@@ -107,9 +113,12 @@ export class DuckdbService {
|
||||
`SELECT COUNT(1) totalRows FROM ${sanitisedFileName(file)}`,
|
||||
);
|
||||
const { totalRows } = totalRowResponse.get(0)?.toJSON()!;
|
||||
const response = await conn.query(
|
||||
`SELECT ${columns.map((column) => `"${column.name}"`).join(', ')} FROM ${sanitisedFileName(file)} LIMIT ${numRows} OFFSET ${start}`,
|
||||
);
|
||||
let query = `SELECT ${columns.map((column) => `"${column.name}"`).join(', ')} FROM ${sanitisedFileName(file)} `;
|
||||
if (sorts.length > 0) {
|
||||
query += ` ORDER BY ${sorts.map((sort) => `"${sort.name}" ${sort.sortType}`).join(', ')}`;
|
||||
}
|
||||
query += ` LIMIT ${numRows} OFFSET ${start}`;
|
||||
const response = await conn.query(query);
|
||||
const rows = [];
|
||||
for (let i = 0; i < response.numRows; i++) {
|
||||
rows.push(response.get(i)?.toJSON()!);
|
||||
|
||||
Reference in New Issue
Block a user