https://github.com/scottlepp/go-duck
A Golang DuckDB library that doesn't require CGO
https://github.com/scottlepp/go-duck
analytics dataframe dataframes duckdb golang grafana sql
Last synced: 8 months ago
JSON representation
A Golang DuckDB library that doesn't require CGO
- Host: GitHub
- URL: https://github.com/scottlepp/go-duck
- Owner: scottlepp
- License: mit
- Created: 2024-02-20T21:36:55.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-24T00:01:58.000Z (11 months ago)
- Last Synced: 2025-05-07T03:46:56.613Z (8 months ago)
- Topics: analytics, dataframe, dataframes, duckdb, golang, grafana, sql
- Language: Go
- Homepage:
- Size: 155 KB
- Stars: 18
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Go wrapper for [DuckDB CLI](https://duckdb.org/docs/api/cli/overview)
* Doesn't require CGO.
* Requires duckdb cli to be in the path.
## In Memory Database
```
db := NewInMemoryDB()
commands := []string{
"CREATE TABLE t1 (i INTEGER, j INTEGER);",
"INSERT INTO t1 VALUES (1, 5);",
"SELECT * from t1;",
}
res, err := db.RunCommands(commands)
```
## File based Database
```
db := NewDuckDB("foo")
commands := []string{
"CREATE TABLE t1 (i INTEGER, j INTEGER);",
"INSERT INTO t1 VALUES (1, 5);",
}
_, err := db.RunCommands(commands)
res, err := db.Query("SELECT * from t1;")
```
## Dataframes
* Allows querying dataframes using SQL, with all the aggregate/window/analytics functions from DuckDB.
## Query Dataframes
```
db := NewInMemoryDB()
var values = []string{"test"}
frame := data.NewFrame("foo", data.NewField("value", nil, values))
frame.RefID = "foo"
frames := []*data.Frame{frame}
res, err := db.QueryFrames("foo", "select * from foo", frames)
```