44 StreamOptions ,
55 QueryOptions , StreamTableData ,
66} from '@cubejs-backend/base-driver' ;
7- import { assertDataSource , getEnv } from '@cubejs-backend/shared' ;
7+ import { getEnv } from '@cubejs-backend/shared' ;
88import { promisify } from 'util' ;
99import * as stream from 'stream' ;
1010// eslint-disable-next-line import/no-extraneous-dependencies
@@ -15,28 +15,16 @@ import { HydrationStream, transformRow } from './HydrationStream';
1515
1616export type DuckDBDriverConfiguration = {
1717 dataSource ?: string ,
18- enableHttpFs ?: boolean ,
1918 initSql ?: string ,
2019} ;
2120
2221export class DuckDBDriver extends BaseDriver implements DriverInterface {
23- protected readonly config : DuckDBDriverConfiguration ;
24-
2522 protected initPromise : Promise < Database > | null = null ;
2623
2724 public constructor (
28- config : DuckDBDriverConfiguration = { } ,
25+ protected readonly config : DuckDBDriverConfiguration = { } ,
2926 ) {
3027 super ( ) ;
31-
32- const dataSource =
33- config . dataSource ||
34- assertDataSource ( 'default' ) ;
35-
36- this . config = {
37- enableHttpFs : getEnv ( 'duckdbHttpFs' , { dataSource } ) || true ,
38- ...config ,
39- } ;
4028 }
4129
4230 protected async initDatabase ( ) : Promise < Database > {
@@ -45,16 +33,47 @@ export class DuckDBDriver extends BaseDriver implements DriverInterface {
4533 const db = new Database ( token ? `md:?motherduck_token=${ token } ` : ':memory:' ) ;
4634 const conn = db . connect ( ) ;
4735
48- if ( this . config . enableHttpFs ) {
49- try {
50- await this . handleQuery ( conn , 'INSTALL httpfs' , [ ] ) ;
51- } catch ( e ) {
52- if ( this . logger ) {
53- console . error ( 'DuckDB - error on httpfs installation' , {
54- e
55- } ) ;
36+ const s3InitQuries = [
37+ {
38+ key : 's3_region' ,
39+ value : getEnv ( 'duckdbS3Region' , this . config ) ,
40+ } ,
41+ {
42+ key : 's3_endpoint' ,
43+ value : getEnv ( 'duckdbS3Endpoint' , this . config ) ,
44+ } ,
45+ {
46+ key : 's3_access_key_id' ,
47+ value : getEnv ( 'duckdbS3AccessKeyId' , this . config ) ,
48+ } ,
49+ {
50+ key : 's3_secret_access_key' ,
51+ value : getEnv ( 'duckdbS3SecretAccessKeyId' , this . config ) ,
52+ } ,
53+ ] ;
54+
55+ try {
56+ await this . handleQuery ( conn , 'INSTALL httpfs' , [ ] ) ;
57+ } catch ( e ) {
58+ if ( this . logger ) {
59+ console . error ( 'DuckDB - error on httpfs installation' , {
60+ e
61+ } ) ;
62+ }
63+ }
64+
65+ try {
66+ for ( const { key, value } of s3InitQuries ) {
67+ if ( value ) {
68+ await this . handleQuery ( conn , `SET ${ key } ='${ value } '` , [ ] ) ;
5669 }
5770 }
71+ } catch ( e ) {
72+ if ( this . logger ) {
73+ console . error ( 'DuckDB - error on s3 configuration' , {
74+ e
75+ } ) ;
76+ }
5877 }
5978
6079 if ( this . config . initSql ) {
0 commit comments