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

add option for path to cli #3

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion duck/duckdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"os/exec"
"strings"

sdk "github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana-plugin-sdk-go/data/framestruct"
Expand All @@ -17,13 +18,15 @@ type DuckDB struct {
Name string
Mode string
Format string
Path string
Chunk int
}

type Opts struct {
Mode string
Format string
Chunk int
Path string
}

const newline = "\n"
Expand All @@ -40,13 +43,15 @@ func NewDuckDB(name string, opts ...Opts) DuckDB {
Name: name,
Mode: defaultString(opts[0].Mode, "json"),
Format: defaultString(opts[0].Format, "parquet"),
Path: defaultString(opts[0].Path, "usr/local/bin/"),
Chunk: defaultInt(opts[0].Chunk, 0),
}
}
return DuckDB{
Name: name,
Mode: "json",
Format: "parquet",
Path: "usr/local/bin/",
Chunk: 0,
}
}
Expand All @@ -63,7 +68,8 @@ func (d *DuckDB) RunCommands(commands []string) (string, error) {
b.Write([]byte(cmd))
}

cmd := exec.Command("duckdb", d.Name)
cli := fmt.Sprintf("%sduckdb", strings.TrimSpace(d.Path))
cmd := exec.Command(cli, d.Name)
cmd.Stdin = &b
cmd.Stdout = &stdout
cmd.Stderr = &stderr
Expand Down