Skip to content

Commit

Permalink
Finish implementing initial support for DuckDB
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenwindflower committed Apr 14, 2024
1 parent 1501f11 commit 2fe1b08
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*.dll
*.so
*.dylib

*.bin
# Test binary, built with `go test -c`
*.test

Expand Down
3 changes: 2 additions & 1 deletion forms.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ You'll need:
)
duckdb_form := huh.NewForm(
huh.NewGroup(
huh.NewInput().Title("What is the path to your DuckDB database?").
huh.NewInput().Title(`What is the path to your DuckDB database?
Relative to pwd e.g. if db is in this dir -> cool_ducks.db`).
Value(&formResponse.Path).Placeholder("/path/to/duckdb.db"),
huh.NewInput().Title("What is the DuckDB database you want to generate?").
Value(&formResponse.Database).Placeholder("duckdb"),
Expand Down
1 change: 1 addition & 0 deletions get_dbt_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type DbtProfile struct {
Schema string `yaml:"schema"`
Project string `yaml:"project"`
Dataset string `yaml:"dataset"`
Path string `yaml:"path"`
Threads int `yaml:"threads"`
} `yaml:"outputs"`
}
Expand Down
2 changes: 2 additions & 0 deletions set_connection_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func SetConnectionDetails(formResponse FormResponse) shared.ConnectionDetails {
{
connectionDetails = shared.ConnectionDetails{
ConnType: profile.Outputs[formResponse.DbtProfileOutput].ConnType,
Path: profile.Outputs[formResponse.DbtProfileOutput].Path,
Database: profile.Outputs[formResponse.DbtProfileOutput].Database,
Schema: formResponse.Schema,
}
Expand Down Expand Up @@ -69,6 +70,7 @@ func SetConnectionDetails(formResponse FormResponse) shared.ConnectionDetails {
{
connectionDetails = shared.ConnectionDetails{
ConnType: formResponse.Warehouse,
Path: formResponse.Path,
Database: formResponse.Database,
Schema: formResponse.Schema,
}
Expand Down
4 changes: 4 additions & 0 deletions sourcerer/connect_to_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"fmt"
"log"
"os"
"time"

"cloud.google.com/go/bigquery"
Expand Down Expand Up @@ -43,6 +44,9 @@ func (bqc *BqConn) ConnectToDB(ctx context.Context) (err error) {
func (dc *DuckConn) ConnectToDB(ctx context.Context) (err error) {
_, dc.Cancel = context.WithTimeout(ctx, 1*time.Minute)
defer dc.Cancel()
if _, err := os.Stat(dc.Path); os.IsNotExist(err) {
log.Fatalf("Path does not exist: %v\n", err)
}
dc.Db, err = sql.Open("duckdb", dc.Path)
if err != nil {
log.Fatalf("Could not connect to DuckDB %v\n", err)
Expand Down
9 changes: 8 additions & 1 deletion sourcerer/get_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"database/sql"
"errors"
"os"
"path/filepath"
"strings"

"github.com/gwenwindflower/tbd/shared"
Expand Down Expand Up @@ -59,8 +61,13 @@ func GetConn(cd shared.ConnectionDetails) (DbConn, error) {
}, nil
case "duckdb":
{
wd, err := os.Getwd()
if err != nil {
return nil, err
}
p := filepath.Join(wd, cd.Path)
return &DuckConn{
Path: cd.Path,
Path: p,
Database: cd.Database,
Schema: cd.Schema,
}, nil
Expand Down

0 comments on commit 2fe1b08

Please sign in to comment.