Skip to content

Commit

Permalink
Merge branch 'main' into windows
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/tests.yaml
#	deps/darwin_amd64/libduckdb.a
#	deps/darwin_arm64/libduckdb.a
#	deps/freebsd_amd64/libduckdb.a
#	duckdb.h
#	duckdb_test.go
  • Loading branch information
taniabogatsch committed Sep 20, 2024
2 parents b802aae + 7accec1 commit 45a129e
Show file tree
Hide file tree
Showing 34 changed files with 2,901 additions and 1,283 deletions.
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2
updates:
# Enable version updates for GitHub action workflows
- package-ecosystem: github-actions
directory: /
# Check for updates to GitHub Actions every weekday
schedule:
interval: daily
time: "19:00"
open-pull-requests-limit: 10
# Enable version updates for Go modules
- package-ecosystem: gomod
directory: /
# Check for updates to GitHub Actions every weekday
schedule:
interval: daily
time: "20:00"
open-pull-requests-limit: 10
40 changes: 20 additions & 20 deletions .github/workflows/deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
prepare:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- shell: bash
run: make deps.header
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: duckdb_h
path: duckdb.h
Expand All @@ -26,12 +26,12 @@ jobs:
needs: prepare
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- shell: bash
run: make deps.darwin.amd64
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: darwin_amd64
path: deps/darwin_amd64/libduckdb.a
Expand All @@ -40,12 +40,12 @@ jobs:
needs: prepare
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- shell: bash
run: make deps.darwin.arm64
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: darwin_arm64
path: deps/darwin_arm64/libduckdb.a
Expand All @@ -54,12 +54,12 @@ jobs:
needs: prepare
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- shell: bash
run: make deps.linux.amd64
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: linux_amd64
path: deps/linux_amd64/libduckdb.a
Expand All @@ -68,7 +68,7 @@ jobs:
needs: prepare
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Install cross compile toolchain
Expand All @@ -78,7 +78,7 @@ jobs:
sudo apt install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- shell: bash
run: make deps.linux.arm64
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: linux_arm64
path: deps/linux_arm64/libduckdb.a
Expand All @@ -87,7 +87,7 @@ jobs:
needs: prepare
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- uses: vmactions/freebsd-vm@v1
Expand All @@ -100,7 +100,7 @@ jobs:
git
run: gmake deps.freebsd.amd64
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: freebsd_amd64
path: deps/freebsd_amd64/libduckdb.a
Expand All @@ -123,7 +123,7 @@ jobs:
runs-on: ubuntu-latest
needs: [darwin_amd64, darwin_arm64, linux_amd64, linux_arm64, windows_amd64, freebsd_amd64]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- shell: bash
Expand All @@ -135,27 +135,27 @@ jobs:
rm -f deps/windows_amd64/libduckdb.a
rm -f deps/freebsd_amd64/libduckdb.a
rm -f duckdb.h
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: duckdb_h
path: .
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: darwin_amd64
path: deps/darwin_amd64
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: darwin_arm64
path: deps/darwin_arm64
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: linux_amd64
path: deps/linux_amd64
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: linux_arm64
path: deps/linux_arm64
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: windows_amd64
path: deps/windows_amd64
Expand All @@ -164,6 +164,6 @@ jobs:
name: freebsd_amd64
path: deps/freebsd_amd64
- name: Push static libraries
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Re-build static libraries
9 changes: 5 additions & 4 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: "1.23"
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: latest
version: latest

7 changes: 3 additions & 4 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go: ["1.21"]
go: ["1.23"]
fail-fast: false

steps:
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

- uses: actions/checkout@v4

- name: "Run Tests"
run: make test
- uses: actions/upload-artifact@v3
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
DUCKDB_REPO=https://github.com/duckdb/duckdb.git
DUCKDB_BRANCH=v1.0.0
DUCKDB_BRANCH=v1.1.0

.PHONY: install
install:
go install .

.PHONY: examples
examples:
go run examples/simple.go
go run examples/simple/main.go
go run examples/appender/main.go

.PHONY: test
test:
Expand Down Expand Up @@ -88,4 +89,4 @@ deps.freebsd.amd64: duckdb

cd duckdb && \
CFLAGS="-O3" CXXFLAGS="-O3" ${DUCKDB_COMMON_BUILD_FLAGS} gmake bundle-library -j 2
cp duckdb/build/release/libduckdb_bundle.a deps/freebsd_amd64/libduckdb.a
cp duckdb/build/release/libduckdb_bundle.a deps/freebsd_amd64/libduckdb.a
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ defer db.Close()
This creates an in-memory instance of DuckDB. To open a persistent database, you need to specify a filepath to the database file. If
the file does not exist, then DuckDB creates it.


```go
db, err := sql.Open("duckdb", "/path/to/foo.db")
if err != nil {
...
...
}
defer db.Close()
```
Expand All @@ -46,7 +45,7 @@ if err != nil {
defer db.Close()
```

Alternatively, you can use [sql.OpenDB](https://cs.opensource.google/go/go/+/go1.21.6:src/database/sql/sql.go;l=781). That way, you can perform initialization steps in a callback function before opening the database.
Alternatively, you can use [sql.OpenDB](https://cs.opensource.google/go/go/+/refs/tags/go1.23.0:src/database/sql/sql.go;l=824). That way, you can perform initialization steps in a callback function before opening the database.
Here's an example that installs and loads the JSON extension when opening a database with `sql.OpenDB(connector)`.

Note that on windows, the `json` extension is pre-installed. Explicitly installing it will return an error
Expand Down Expand Up @@ -81,6 +80,7 @@ Please refer to the [database/sql](https://godoc.org/database/sql) documentation
DuckDB lives in-process. Therefore, all its memory lives in the driver. All allocations live in the host process, which
is the Go application. Especially for long-running applications, it is crucial to call the corresponding `Close`-functions as specified
in [database/sql](https://godoc.org/database/sql). The following is a list of examples.

```go
db, err := sql.Open("duckdb", "")
defer db.Close()
Expand All @@ -102,32 +102,32 @@ defer connector.Close()

## DuckDB Appender API

If you want to use the [DuckDB Appender API](https://duckdb.org/docs/data/appender.html), you can obtain a new `Appender` by passing a DuckDB connection to `NewAppenderFromConn()`.
If you want to use the [DuckDB Appender API](https://duckdb.org/docs/data/appender.html), you can obtain a new `Appender` by passing a DuckDB connection to `NewAppenderFromConn()`. See `examples/appender.go` for a complete example.

```go
connector, err := duckdb.NewConnector("test.db", nil)
if err != nil {
...
...
}
defer connector.Close()

conn, err := connector.Connect(context.Background())
if err != nil {
...
...
}
defer conn.Close()

// obtain an appender from the connection
// NOTE: the table 'test_tbl' must exist in test.db
appender, err := NewAppenderFromConn(conn, "", "test_tbl")
if err != nil {
...
...
}
defer appender.Close()

err = appender.AppendRow(...)
if err != nil {
...
...
}
```

Expand All @@ -138,25 +138,25 @@ If you want to use the [DuckDB Arrow Interface](https://duckdb.org/docs/api/c/ap
```go
connector, err := duckdb.NewConnector("", nil)
if err != nil {
...
...
}
defer connector.Close()

conn, err := connector.Connect(context.Background())
if err != nil {
...
...
}
defer conn.Close()

// obtain the Arrow from the connection
arrow, err := duckdb.NewArrowFromConn(conn)
if err != nil {
...
...
}

rdr, err := arrow.QueryContext(context.Background(), "SELECT * FROM generate_series(1, 10)")
if err != nil {
...
...
}
defer rdr.Release()

Expand Down Expand Up @@ -203,7 +203,7 @@ DYLD_LIBRARY_PATH=/path/to/libs ./main
`TIMESTAMP vs. TIMESTAMP_TZ`

In the C API, DuckDB stores both `TIMESTAMP` and `TIMESTAMP_TZ` as `duckdb_timestamp`, which holds the number of
microseconds elapsed since January 1, 1970 UTC (i.e., an instant without offset information).
When passing a `time.Time` to go-duckdb, go-duckdb transforms it to an instant with `UnixMicro()`,
even when using `TIMESTAMP_TZ`. Later, scanning either type of value returns an instant, as SQL types do not model
microseconds elapsed since January 1, 1970 UTC (i.e., an instant without offset information).
When passing a `time.Time` to go-duckdb, go-duckdb transforms it to an instant with `UnixMicro()`,
even when using `TIMESTAMP_TZ`. Later, scanning either type of value returns an instant, as SQL types do not model
time zone information for individual values.
Loading

0 comments on commit 45a129e

Please sign in to comment.