Skip to content

Commit

Permalink
Merge branch 'bwilmoth/bigquery-dialect' of github.com:outerbase/sdk …
Browse files Browse the repository at this point in the history
…into bwilmoth/bigquery-dialect
  • Loading branch information
caleb-mabry committed Aug 29, 2024
2 parents 1ad333d + 5cf13a1 commit 8c0cfb8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/connections/motherduck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TableIndex,
TableIndexType,
} from '../models/database'
import { DefaultDialect } from '../query-builder/dialects/default'
import { DuckDbDialect } from '../query-builder/dialects/duckdb'
import duckDB from 'duckdb'

type DuckDBParameters = {
Expand All @@ -24,7 +24,7 @@ export class DuckDBConnection implements Connection {
queryType = QueryType.positional

// Default dialect for MotherDuck
dialect = new DefaultDialect()
dialect = new DuckDbDialect()

constructor(private _: DuckDBParameters) {
this.duckDB = new duckDB.Database(_.path, {
Expand Down
10 changes: 10 additions & 0 deletions src/query-builder/dialects/duckdb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { QueryBuilder } from 'src/client';
import { Query } from 'src/query';
import { QueryType } from 'src/query-params';
import { AbstractDialect } from '../index';

export class DuckDbDialect extends AbstractDialect {
formatSchemaAndTable(schema: string | undefined, table: string): string {
return table;
}
}
11 changes: 9 additions & 2 deletions src/query-builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@ export abstract class AbstractDialect implements Dialect {
* @returns The formatted schema and table combination.
*/
formatSchemaAndTable(schema: string | undefined, table: string): string {
// Default implementation (can be overridden by specific dialects)
if (schema) {
return `"${schema}".${table}`;
}
return table;
}

formatFromSchemaAndTable(schema: string | undefined, table: string): string {
if (schema) {
return `"${schema}".${table}`;
}
Expand All @@ -202,6 +208,7 @@ export abstract class AbstractDialect implements Dialect {
}

const formattedTable = this.formatSchemaAndTable(set.schema, set.table);
const formattedFromTable = this.formatFromSchemaAndTable(set.schema, set.table);
const columns = set.columns.map((column) => {
let useColumn = column

Expand All @@ -215,7 +222,7 @@ export abstract class AbstractDialect implements Dialect {
selectColumns += columns.join(', ')

if (index === 0) {
fromTable = formattedTable
fromTable = formattedFromTable
}
})

Expand Down

0 comments on commit 8c0cfb8

Please sign in to comment.