# DuckDB with Go

import { Tabs, TabsContent, TabsList, TabsTrigger } from "zudoku/ui/Tabs"

{/* vale off */}
{/* THIS FILE WAS AUTOGENERATED FROM THE PUBLIC EXAMPLE REPOSITORY. DO NOT EDIT THIS FILE DIRECTLY. */}


This guide shows you how to use [DuckDB](https://duckdb.org), an in-process SQL OLAP database management system, in your Go project.

To run this example, follow these steps:

1. Install the CLI.
   Use the [unikraft CLI](/cli/unikraft) or the legacy [kraft CLI](https://unikraft.org/docs/cli/install).
   You need a [BuildKit](https://github.com/moby/buildkit) builder. The easiest way to get one is via [Docker](https://docs.docker.com/engine/install/).
   Alternatively, you can also directly set up and use BuildKit, see the [quick start](https://github.com/moby/buildkit#quick-start).

   :::note
   The unikraft CLI is the current standard, while kraft is the legacy version.
   Choose one of the CLIs below and only run the commands associated with it for the rest of this guide.
   :::

2. Clone the [`examples` repository](https://github.com/unikraft-cloud/examples) and `cd` into the `examples/duckdb-go1.21/` directory:

   ```bash
   git clone https://github.com/unikraft-cloud/examples
   cd examples/duckdb-go1.21/
   ```

Make sure to log into Unikraft Cloud and pick a [metro](/platform/metros) close to you.
This guide uses `fra` (Frankfurt, 🇩🇪):

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft login
```

```bash title="kraft"
# Set Unikraft Cloud access token
export UKC_TOKEN=token
# Set metro to Frankfurt, DE
export UKC_METRO=fra
```

</CodeTabs>

When done, invoke the following command to deploy this app on Unikraft Cloud:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft build . --output <my-org>/duckdb-go121:latest
unikraft run --scale-to-zero policy=on,cooldown-time=1000,stateful=true --metro fra -p 443:8080/tls+http -m 256M --image <my-org>/duckdb-go121:latest
```

```bash title="kraft"
kraft cloud deploy --scale-to-zero on --scale-to-zero-stateful --scale-to-zero-cooldown 1s -p 443:8080/tls+http -M 256Mi .
```

</CodeTabs>

The output shows the instance address and other details:

<CodeTabs syncKey="cli">

```ansi title="unikraft"
[1mmetro[22m:        fra
[1mname[22m:         duckdb-go121-qfd8x
[1muuid[22m:         90960d27-458b-4dd7-a037-2a9a3a47f095
[1mstate[22m:        [38;2;144;161;185mstarting[0m
[1mimage[22m:        <my-org>/duckdb-go121
[1mresources[22m:
[3m  memory[23m:     256MiB
[3m  vcpus[23m:      1
[1mservice[22m:
[3m  uuid[23m:       0e3c61f1-5ad3-7d75-ceaf-079ea83394f6
[3m  name[23m:       autumn-gorilla-hg4h6sup
[3m  domains[23m:
[3m  - fqdn[23m:     autumn-gorilla-hg4h6sup.fra.unikraft.app
[1mnetworks[22m:
[3m- uuid[23m:       0f66c51a-dcad-94fc-d0a8-b0570e3d1b97
[3m  private-ip[23m: 10.0.6.2
[3m  mac[23m:        12:b0:31:d1:4b:90
[1mtimestamps[22m:
[3m  created[23m:    just now
```

```ansi title="kraft"
[38;5;245m[[0m[92m●[0m[38;5;245m][0m Deployed successfully!
 [38;5;245m│[0m
 [38;5;245m├[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m [38;5;245mname[0m: duckdb-go121-qfd8x
 [38;5;245m├[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m [38;5;245muuid[0m: 90960d27-458b-4dd7-a037-2a9a3a47f095
 [38;5;245m├[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m [38;5;245mmetro[0m: https://api.fra.unikraft.cloud/v1
 [38;5;245m├[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m [38;5;245mstate[0m: [92mstarting[0m
 [38;5;245m├[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m [38;5;245mdomain[0m: https://autumn-gorilla-hg4h6sup.fra.unikraft.app
 [38;5;245m├[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m [38;5;245mimage[0m: oci://unikraft.io/<my-org>/duckdb-go121@sha256:6999293f8694ac00beb6a1d639fab8f96f78c2e6ecb8ccb2311539908895a699
 [38;5;245m├[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m [38;5;245mmemory[0m: 256 MiB
 [38;5;245m├[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m [38;5;245mservice[0m: autumn-gorilla-hg4h6sup
 [38;5;245m├[0m[38;5;245m─[0m [38;5;245mprivate fqdn[0m: duckdb-go121-qfd8x.internal
 [38;5;245m└[0m[38;5;245m─[0m[38;5;245m─[0m[38;5;245m─[0m [38;5;245mprivate ip[0m: 10.0.6.2
```

</CodeTabs>

In this case, the instance name is `duckdb-go121-qfd8x` and the address is `https://autumn-gorilla-hg4h6sup.fra.unikraft.app`.
They're different for each run.

Use `curl` to query the Unikraft Cloud instance of DuckDB.

```bash
curl https://autumn-gorilla-hg4h6sup.fra.unikraft.app
```

```text
id: %d, name: %s 42 John
```

You can list information about the instance by running:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft instances list
```

```bash title="kraft"
kraft cloud instance list
```

</CodeTabs>

<div style={{ marginTop: '0.8em' }} />

<CodeTabs syncKey="cli">

```ansi title="unikraft"
[1mMETRO[22m  [1mNAME[22m                [1mSTATE[22m    [1mIMAGE[22m                  [1mARGS[22m  [1mMEMORY[22m  [1mVCPUS[22m  [1mFQDN[22m                                      [1mCREATED[22m
fra    duckdb-go121-qfd8x  [38;2;0;188;125mrunning[0m  <my-org>/duckdb-go121        256MiB  1      autumn-gorilla-hg4h6sup.fra.unikraft.app  2 minutes ago
```

```ansi title="kraft"
[0;1;39mNAME[0m                [0;1;39mFQDN[0m                                      [0;1;39mSTATE[0m    [0;1;39mSTATUS[0m        [0;1;39mIMAGE[0m                                               [0;1;39mMEMORY[0m   [0;1;39mVCPUS[0m  [0;1;39mARGS[0m  [0;1;39mBOOT TIME[0m
duckdb-go121-qfd8x  autumn-gorilla-hg4h6sup.fra.unikraft.app  [0;32mrunning[0m  1 minute ago  oci://unikraft.io/<my-org>/duckdb-go121@sha256:...  256 MiB  1            32.12 ms
```

</CodeTabs>

When done, you can remove the instance:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft instances delete duckdb-go121-qfd8x
```

```bash title="kraft"
kraft cloud instance remove duckdb-go121-qfd8x
```

</CodeTabs>

## Customize your app

To customize the app, update the files in the repository, listed below:

* `src/main.go`: the Go web server frontend
* `Kraftfile`: the Unikraft Cloud specification, including command-line arguments
* `Dockerfile`: the Docker-specified app filesystem

The following options are available for customizing the app:

* If you only update the implementation in the `main.go` source file, you don't need to make any other changes.

* If you create any new source files, copy them into the app filesystem by using the `COPY` command in the `Dockerfile`.

* If you add new source code files, build them using the corresponding `go build` command.

* If you build a new executable, update the `cmd` line in the `Kraftfile` and replace `/server` with the path to the new executable.

* More extensive changes may require extending the `Dockerfile` ([see `Dockerfile` syntax reference](https://docs.docker.com/engine/reference/builder/)).

## Learn more

Use the `--help` option for detailed information on using Unikraft Cloud:

<CodeTabs syncKey="cli">

```bash title="unikraft"
unikraft --help
```

```bash title="kraft"
kraft cloud --help
```

</CodeTabs>

Or visit the [CLI Reference](/cli/unikraft) or the [legacy CLI Reference](/cli/kraft/overview).
{/* vale on */}
