Skip to content

Commit

Permalink
Merge pull request #23 from duckdb/jray/api-for-appender
Browse files Browse the repository at this point in the history
api for appender & other tweaks
  • Loading branch information
jraymakers authored Oct 12, 2024
2 parents be1c3e7 + 613b35a commit ee3101f
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 26 deletions.
91 changes: 88 additions & 3 deletions api/src/DuckDBAppender.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,100 @@
import duckdb from '@duckdb/node-bindings';
import { DuckDBType } from './DuckDBType';
import { DuckDBLogicalType } from './DuckDBLogicalType';
import { Date_, Interval, Time, Timestamp } from './DuckDBValue';
import { DuckDBDataChunk } from './DuckDBDataChunk';

export class DuckDBAppender {
private readonly appender: duckdb.Appender;
constructor(appender: duckdb.Appender) {
this.appender = appender;
}
public async dispose() {
public dispose() {
duckdb.appender_destroy(this.appender);
}
public async flush() {
public close() {
duckdb.appender_close(this.appender);
}
public flush() {
duckdb.appender_flush(this.appender);
}
// TODO
public get columnCount(): number {
return duckdb.appender_column_count(this.appender);
}
public columnType(columnIndex: number): DuckDBType {
return DuckDBLogicalType.consumeAsType(duckdb.appender_column_type(this.appender, columnIndex));
}
public endRow() {
duckdb.appender_end_row(this.appender);
}
public appendBoolean(value: boolean) {
duckdb.append_bool(this.appender, value);
}
public appendTinyInt(value: number) {
duckdb.append_int8(this.appender, value);
}
public appendSmallInt(value: number) {
duckdb.append_int16(this.appender, value);
}
public appendInteger(value: number) {
duckdb.append_int32(this.appender, value);
}
public appendBigInt(value: bigint) {
duckdb.append_int64(this.appender, value);
}
public appendHugeInt(value: bigint) {
duckdb.append_hugeint(this.appender, value);
}
public appendUTinyInt(value: number) {
duckdb.append_uint8(this.appender, value);
}
public appendUSmallInt(value: number) {
duckdb.append_uint16(this.appender, value);
}
public appendUInteger(value: number) {
duckdb.append_uint32(this.appender, value);
}
public appendUBigInt(value: bigint) {
duckdb.append_uint64(this.appender, value);
}
public appendUHugeInt(value: bigint) {
duckdb.append_uhugeint(this.appender, value);
}
// TODO: append DECIMAL?
public appendFloat(value: number) {
duckdb.append_float(this.appender, value);
}
public appendDouble(value: number) {
duckdb.append_double(this.appender, value);
}
public appendDate(value: Date_) {
duckdb.append_date(this.appender, value);
}
public appendTime(value: Time) {
duckdb.append_time(this.appender, value);
}
public appendTimestamp(value: Timestamp) {
duckdb.append_timestamp(this.appender, value);
}
// TODO: append TIMESTAMPS_S/_MS/_NS?
// TODO: append TIME_TZ/TIMESTAMP_TZ?
public appendInterval(value: Interval) {
duckdb.append_interval(this.appender, value);
}
public appendVarchar(value: string) {
duckdb.append_varchar(this.appender, value);
}
public appendBlob(value: Uint8Array) {
duckdb.append_blob(this.appender, value);
}
// TODO: append ENUM?
// TODO: append nested types? (ARRAY, LIST, STRUCT, MAP, UNION)
// TODO: append UUID?
// TODO: append BIT?
public appendNull() {
duckdb.append_null(this.appender);
}
public appendDataChunk(dataChunk: DuckDBDataChunk) {
duckdb.append_data_chunk(this.appender, dataChunk.chunk);
}
}
2 changes: 1 addition & 1 deletion api/src/DuckDBDataChunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import duckdb from '@duckdb/node-bindings';
import { DuckDBVector } from './DuckDBVector';

export class DuckDBDataChunk {
private readonly chunk: duckdb.DataChunk;
public readonly chunk: duckdb.DataChunk;
constructor(chunk: duckdb.DataChunk) {
this.chunk = chunk;
}
Expand Down
27 changes: 10 additions & 17 deletions api/src/DuckDBPreparedStatement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@ import duckdb from '@duckdb/node-bindings';
import { DuckDBPendingResult } from './DuckDBPendingResult';
import { DuckDBResult } from './DuckDBResult';
import { DuckDBTypeId } from './DuckDBTypeId';

type Date_ = duckdb.Date_;
type Decimal = duckdb.Decimal;
type Interval = duckdb.Interval;
type Time = duckdb.Time;
type Timestamp = duckdb.Timestamp;

type StatementType = duckdb.StatementType;

export type { Date_, Decimal, Interval, Time, Timestamp };
import { Date_, Decimal, Interval, Time, Timestamp } from './DuckDBValue';
import { StatementType } from './enums';

export class DuckDBPreparedStatement {
private readonly prepared_statement: duckdb.PreparedStatement;
Expand Down Expand Up @@ -60,12 +52,6 @@ export class DuckDBPreparedStatement {
public bindHugeInt(parameterIndex: number, value: bigint) {
duckdb.bind_hugeint(this.prepared_statement, parameterIndex, value);
}
public bindUHugeInt(parameterIndex: number, value: bigint) {
duckdb.bind_uhugeint(this.prepared_statement, parameterIndex, value);
}
public bindDecimal(parameterIndex: number, value: Decimal) {
duckdb.bind_decimal(this.prepared_statement, parameterIndex, value);
}
public bindUTinyInt(parameterIndex: number, value: number) {
duckdb.bind_uint8(this.prepared_statement, parameterIndex, value);
}
Expand All @@ -78,6 +64,12 @@ export class DuckDBPreparedStatement {
public bindUBigInt(parameterIndex: number, value: bigint) {
duckdb.bind_uint64(this.prepared_statement, parameterIndex, value);
}
public bindUHugeInt(parameterIndex: number, value: bigint) {
duckdb.bind_uhugeint(this.prepared_statement, parameterIndex, value);
}
public bindDecimal(parameterIndex: number, value: Decimal) {
duckdb.bind_decimal(this.prepared_statement, parameterIndex, value);
}
public bindFloat(parameterIndex: number, value: number) {
duckdb.bind_float(this.prepared_statement, parameterIndex, value);
}
Expand All @@ -94,6 +86,7 @@ export class DuckDBPreparedStatement {
duckdb.bind_timestamp(this.prepared_statement, parameterIndex, value);
}
// TODO: bind TIMESTAMPS_S/_MS/_NS?
// TODO: bind TIME_TZ/TIMESTAMP_TZ?
public bindInterval(parameterIndex: number, value: Interval) {
duckdb.bind_interval(this.prepared_statement, parameterIndex, value);
}
Expand All @@ -104,7 +97,7 @@ export class DuckDBPreparedStatement {
duckdb.bind_blob(this.prepared_statement, parameterIndex, value);
}
// TODO: bind ENUM?
// TODO: bind nested types? (LIST, STRUCT, MAP, UNION) (using bindValue?)
// TODO: bind nested types? (ARRAY, LIST, STRUCT, MAP, UNION) (using bindValue?)
// TODO: bind UUID?
// TODO: bind BIT?
public bindNull(parameterIndex: number) {
Expand Down
6 changes: 1 addition & 5 deletions api/src/DuckDBResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { DuckDBDataChunk } from './DuckDBDataChunk';
import { DuckDBLogicalType } from './DuckDBLogicalType';
import { DuckDBType } from './DuckDBType';
import { DuckDBTypeId } from './DuckDBTypeId';

type ResultReturnType = duckdb.ResultType;
type StatementType = duckdb.StatementType;

export type { ResultReturnType, StatementType };
import { ResultReturnType, StatementType } from './enums';

export class DuckDBResult {
private readonly result: duckdb.Result;
Expand Down
23 changes: 23 additions & 0 deletions api/src/DuckDBValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import duckdb from '@duckdb/node-bindings';

type Date_ = duckdb.Date_;
type Decimal = duckdb.Decimal;
type Interval = duckdb.Interval;
type Time = duckdb.Time;
type Timestamp = duckdb.Timestamp;

export type { Date_, Decimal, Interval, Time, Timestamp };

export type DuckDBValue =
| null
| boolean
| number
| bigint
| string
| Uint8Array
| Date_
| Decimal
| Interval
| Time
| Timestamp
;
6 changes: 6 additions & 0 deletions api/src/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import duckdb from '@duckdb/node-bindings';

type ResultReturnType = duckdb.ResultType;
type StatementType = duckdb.StatementType;

export type { ResultReturnType, StatementType };
2 changes: 2 additions & 0 deletions api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ export * from './DuckDBPreparedStatement';
export * from './DuckDBResult';
export * from './DuckDBType';
export * from './DuckDBTypeId';
export * from './DuckDBValue';
export * from './DuckDBVector';
export * from './enums';
export * from './version';

0 comments on commit ee3101f

Please sign in to comment.