Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate typescript definitions #42

Merged
merged 37 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4148620
generate typescript definitions
jraymakers Jan 8, 2024
7cfbcc6
test typescript definitions
jraymakers Jan 8, 2024
d59ccc1
commit typescript defs
jraymakers Jan 8, 2024
76f5b17
handle function args
jraymakers Jan 10, 2024
e214383
rename result to cpp_result
jraymakers Jan 10, 2024
c2ef285
remove unnecessary format strings
jraymakers Jan 10, 2024
d3f0aa5
port test.js to test.ts
jraymakers Jan 10, 2024
119bfec
make test.js and test.ts as close as possible
jraymakers Jan 10, 2024
d0cef94
fix indent
jraymakers Jan 10, 2024
586c86e
update test.ts for test.js changes
jraymakers Jan 10, 2024
e88bba3
update test.js and test.ts to be closer togetehr
jraymakers Jan 10, 2024
9a9ba59
start of higher-level api
jraymakers Jan 12, 2024
9531c2e
update generated files
jraymakers Jan 12, 2024
6d2e4ec
format generated cpp
jraymakers Jan 12, 2024
3726e3e
add back duckdb_validity_row_is_valid
jraymakers Jan 12, 2024
44d2716
deprecate duckdb_vector_ensure_validity_writable
jraymakers Jan 12, 2024
4c6ac46
start at vector
jraymakers Jan 13, 2024
9eeda9d
add files to index
jraymakers Jan 13, 2024
237affc
change Buffer to UInt8Array
jraymakers Jan 19, 2024
3f97710
fix uint64_t* conversion
jraymakers Jan 19, 2024
62eb2ae
add test for nested list access
jraymakers Jan 19, 2024
4371681
refactor of DuckDBVector to support validity and nested lists
jraymakers Jan 20, 2024
7752e16
primitive vector types
jraymakers Jan 20, 2024
3471539
struct vector
jraymakers Jan 20, 2024
3f2d21e
map vector
jraymakers Jan 20, 2024
6898b17
map vector validity
jraymakers Jan 20, 2024
a7e5ac2
union vector
jraymakers Jan 26, 2024
ef4e235
test union
jraymakers Jan 26, 2024
68b48f7
destroy config after open
jraymakers Jan 26, 2024
bc65ff3
basic api test
jraymakers Jan 26, 2024
e165690
test name change
jraymakers Jan 29, 2024
e1bd809
prepared statement & pending result
jraymakers Jan 30, 2024
b8ab1a4
streaming result
jraymakers Jan 30, 2024
732a9ea
fix typo in comment
jraymakers Jan 30, 2024
57a758b
prepared statement test
jraymakers Jan 30, 2024
f0afbb5
add pending result to index
jraymakers Jan 30, 2024
3abc7cf
global function tests
jraymakers Jan 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions api/src/DuckDBAppender.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as ddb from '../..';
import { throwOnFailure } from './throwOnFailure';

export class DuckDBAppender {
private readonly appender: ddb.duckdb_appender;
constructor(appender: ddb.duckdb_appender) {
this.appender = appender;
}
public async dispose() {
throwOnFailure(await ddb.duckdb_appender_destroy(this.appender),
'Failed to destroy appender', () => ddb.duckdb_appender_error(this.appender));
}
public async flush() {
throwOnFailure(await ddb.duckdb_appender_flush(this.appender),
'Failed to flush appender', () => ddb.duckdb_appender_error(this.appender));
}
// TODO
}
63 changes: 63 additions & 0 deletions api/src/DuckDBConnection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as ddb from '../..';
import { DuckDBAppender } from './DuckDBAppender';
import { DuckDBExtractedStatements } from './DuckDBExtractedStatements';
import { DuckDBInstance } from './DuckDBInstance';
import { DuckDBPreparedStatement } from './DuckDBPreparedStatement';
import { DuckDBMaterializedResult } from './DuckDBResult';
import { throwOnFailure } from './throwOnFailure';

export class DuckDBConnection {
private readonly connection: ddb.duckdb_connection;
constructor(connection: ddb.duckdb_connection) {
this.connection = connection;
}
public static async create(instance: DuckDBInstance): Promise<DuckDBConnection> {
return instance.connect();
}
public dispose(): Promise<void> {
return ddb.duckdb_disconnect(this.connection);
}
public interrupt() {
ddb.duckdb_interrupt(this.connection);
}
/** Returns -1 if no progress or a percentage of the progress. */
public get progress(): number {
return ddb.duckdb_query_progress(this.connection);
}
public get finished(): boolean {
return ddb.duckdb_execution_is_finished(this.connection);
}
public async run(sql: string): Promise<DuckDBMaterializedResult> {
const result = new ddb.duckdb_result;
throwOnFailure(await ddb.duckdb_query(this.connection, sql, result),
'Failed to query', () => ddb.duckdb_result_error(result),
() => ddb.duckdb_destroy_result(result));
return new DuckDBMaterializedResult(result);
}
public async prepare(sql: string): Promise<DuckDBPreparedStatement> {
const prepared_statement = new ddb.duckdb_prepared_statement;
throwOnFailure(await ddb.duckdb_prepare(this.connection, sql, prepared_statement),
'Failed to prepare', () => ddb.duckdb_prepare_error(prepared_statement),
() => ddb.duckdb_destroy_prepare(prepared_statement));
return new DuckDBPreparedStatement(prepared_statement);
}
public async extractStatements(sql: string): Promise<DuckDBExtractedStatements> {
const extracted_statements = new ddb.duckdb_extracted_statements;
const statementCount = await ddb.duckdb_extract_statements(this.connection, sql, extracted_statements);
if (statementCount === 0) {
try {
throw new Error(`Failed to extract statements: ${ddb.duckdb_extract_statements_error(extracted_statements)}`);
} finally {
ddb.duckdb_destroy_extracted(extracted_statements);
}
}
return new DuckDBExtractedStatements(this.connection, extracted_statements, statementCount);
}
public async createAppender(schema: string, table: string): Promise<DuckDBAppender> {
const appender = new ddb.duckdb_appender;
throwOnFailure(await ddb.duckdb_appender_create(this.connection, schema, table, appender),
'Failed to create appender', () => ddb.duckdb_appender_error(appender),
() => ddb.duckdb_appender_destroy(appender));
return new DuckDBAppender(appender);
}
}
32 changes: 32 additions & 0 deletions api/src/DuckDBDataChunk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as ddb from '../..';
import { DuckDBVector } from './DuckDBVector';

export class DuckDBDataChunk {
private readonly chunk: ddb.duckdb_data_chunk;
constructor(chunk: ddb.duckdb_data_chunk) {
this.chunk = chunk;
}
public static create(): DuckDBDataChunk {
// TODO: C API takes raw pointer (list of types)
throw new Error('not implemented');
}
public dispose() {
ddb.duckdb_destroy_data_chunk(this.chunk);
}
public reset() {
ddb.duckdb_data_chunk_reset(this.chunk);
}
public get columnCount(): number {
return ddb.duckdb_data_chunk_get_column_count(this.chunk);
}
public getColumn(columnIndex: number): DuckDBVector<any> {
// TODO: cache vectors?
return DuckDBVector.create(ddb.duckdb_data_chunk_get_vector(this.chunk, columnIndex), this.rowCount);
}
public get rowCount(): number {
return ddb.duckdb_data_chunk_get_size(this.chunk);
}
public set rowCount(count: number) {
ddb.duckdb_data_chunk_set_size(this.chunk, count);
}
}
28 changes: 28 additions & 0 deletions api/src/DuckDBExtractedStatements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as ddb from '../..';
import { DuckDBPreparedStatement } from './DuckDBPreparedStatement';
import { throwOnFailure } from './throwOnFailure';

export class DuckDBExtractedStatements {
private readonly connection: ddb.duckdb_connection;
private readonly extracted_statements: ddb.duckdb_extracted_statements;
private readonly statementCount: number;
constructor(connection: ddb.duckdb_connection, extracted_statements: ddb.duckdb_extracted_statements, statementCount: number) {
this.connection = connection;
this.extracted_statements = extracted_statements;
this.statementCount = statementCount;
}
public dispose() {
ddb.duckdb_destroy_extracted(this.extracted_statements);
}
public get count(): number {
return this.statementCount;
}
public async prepare(index: number): Promise<DuckDBPreparedStatement> {
const prepared_statement = new ddb.duckdb_prepared_statement;
throwOnFailure(await ddb.duckdb_prepare_extracted_statement(this.connection, this.extracted_statements, index, prepared_statement),
'Failed to prepare extracted statement', () => ddb.duckdb_prepare_error(prepared_statement),
() => ddb.duckdb_destroy_prepare(prepared_statement));
return new DuckDBPreparedStatement(prepared_statement);
}
// TODO
}
40 changes: 40 additions & 0 deletions api/src/DuckDBInstance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as ddb from '../..';
import { DuckDBConnection } from './DuckDBConnection';
import { throwOnFailure } from './throwOnFailure';

export class DuckDBInstance {
private readonly db: ddb.duckdb_database;
constructor(db: ddb.duckdb_database) {
this.db = db;
}
public static async create(path: string = ':memory:', options?: Record<string, string>): Promise<DuckDBInstance> {
const db = new ddb.duckdb_database;
if (options) {
const config = new ddb.duckdb_config;
throwOnFailure(ddb.duckdb_create_config(config),
'Failed to create config', undefined,
() => ddb.duckdb_destroy_config(config));
for (const optionName in options) {
const optionValue = options[optionName];
throwOnFailure(ddb.duckdb_set_config(config, optionName, optionValue),
'Failed to set config option', () => optionName,
() => ddb.duckdb_destroy_config(config));
}
const errorWrapper = new ddb.out_string_wrapper;
throwOnFailure(await ddb.duckdb_open_ext(path, db, config, errorWrapper),
'Failed to open', () => ddb.out_get_string(errorWrapper),
() => ddb.duckdb_destroy_config(config));
} else {
throwOnFailure(await ddb.duckdb_open(path, db), 'Failed to open');
}
return new DuckDBInstance(db);
}
public dispose(): Promise<void> {
return ddb.duckdb_close(this.db);
}
public async connect(): Promise<DuckDBConnection> {
const connection = new ddb.duckdb_connection;
throwOnFailure(await ddb.duckdb_connect(this.db, connection), 'Failed to connect');
return new DuckDBConnection(connection);
}
}
Loading
Loading