add duckdb-ui-client & other ts pkgs (#10)
* add duckdb-ui-client & other ts pkgs * workflow fixes * fix working dir * no sparse checkout; specify package.json path * path to pnpm-lock.yaml * add check & build test * workflow step descriptions * use comments & names * one more naming tweak
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { DuckDBData } from '@duckdb/data-reader';
|
||||
import { DuckDBType } from '@duckdb/data-types';
|
||||
import { DuckDBValue } from '@duckdb/data-values';
|
||||
import { duckDBTypeFromTypeIdAndInfo } from '../../conversion/functions/duckDBTypeFromTypeIdAndInfo.js';
|
||||
import { duckDBValueFromVector } from '../../conversion/functions/duckDBValueFromVector.js';
|
||||
import { ColumnNamesAndTypes } from '../../serialization/types/ColumnNamesAndTypes.js';
|
||||
import { DataChunk } from '../../serialization/types/DataChunk.js';
|
||||
|
||||
export class DuckDBDataChunk extends DuckDBData {
|
||||
constructor(
|
||||
private columnNamesAndTypes: ColumnNamesAndTypes,
|
||||
private chunk: DataChunk,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
get columnCount() {
|
||||
return this.columnNamesAndTypes.names.length;
|
||||
}
|
||||
|
||||
get rowCount() {
|
||||
return this.chunk.rowCount;
|
||||
}
|
||||
|
||||
columnName(columnIndex: number): string {
|
||||
return this.columnNamesAndTypes.names[columnIndex];
|
||||
}
|
||||
|
||||
columnType(columnIndex: number): DuckDBType {
|
||||
return duckDBTypeFromTypeIdAndInfo(
|
||||
this.columnNamesAndTypes.types[columnIndex],
|
||||
);
|
||||
}
|
||||
|
||||
value(columnIndex: number, rowIndex: number): DuckDBValue {
|
||||
return duckDBValueFromVector(
|
||||
this.columnNamesAndTypes.types[columnIndex],
|
||||
this.chunk.vectors[columnIndex],
|
||||
rowIndex,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
AsyncDuckDBDataBatchIterator,
|
||||
DuckDBData,
|
||||
DuckDBDataBatchIteratorResult,
|
||||
} from '@duckdb/data-reader';
|
||||
import { SuccessQueryResult } from '../../serialization/types/QueryResult.js';
|
||||
import { DuckDBDataChunk } from './DuckDBDataChunk.js';
|
||||
|
||||
const ITERATOR_DONE: DuckDBDataBatchIteratorResult = Object.freeze({
|
||||
done: true,
|
||||
value: undefined,
|
||||
});
|
||||
|
||||
export class DuckDBDataChunkIterator implements AsyncDuckDBDataBatchIterator {
|
||||
private result: SuccessQueryResult;
|
||||
|
||||
private index: number;
|
||||
|
||||
constructor(result: SuccessQueryResult) {
|
||||
this.result = result;
|
||||
this.index = 0;
|
||||
}
|
||||
|
||||
async next(): Promise<DuckDBDataBatchIteratorResult> {
|
||||
if (this.index < this.result.chunks.length) {
|
||||
return {
|
||||
done: false,
|
||||
value: new DuckDBDataChunk(
|
||||
this.result.columnNamesAndTypes,
|
||||
this.result.chunks[this.index++],
|
||||
),
|
||||
};
|
||||
}
|
||||
return ITERATOR_DONE;
|
||||
}
|
||||
|
||||
async return(value?: DuckDBData): Promise<DuckDBDataBatchIteratorResult> {
|
||||
if (value) {
|
||||
return { done: true, value };
|
||||
}
|
||||
return ITERATOR_DONE;
|
||||
}
|
||||
|
||||
async throw(_e?: unknown): Promise<DuckDBDataBatchIteratorResult> {
|
||||
return ITERATOR_DONE;
|
||||
}
|
||||
|
||||
[Symbol.asyncIterator](): AsyncDuckDBDataBatchIterator {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user