-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (38 loc) · 974 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"context"
"database/sql"
"errors"
"fmt"
"log/slog"
"os"
_ "github.com/marcboeker/go-duckdb"
)
func main() {
ctx := context.Background()
l := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelInfo,
}))
currentTimestamp, err := run(ctx)
if err != nil {
l.Error("error", "ERROR", err)
os.Exit(1)
}
l.Info("current timestamp", "timestamp", currentTimestamp)
}
func run(ctx context.Context) (currentTimestamp string, ferr error) {
db, err := sql.Open("duckdb", "")
if err != nil {
return "", fmt.Errorf("opening duckdb connection: %w", err)
}
defer func(db *sql.DB) {
if cerr := db.Close(); cerr != nil {
ferr = errors.Join(ferr, fmt.Errorf("closing duckdb connection: %w", cerr))
}
}(db)
row := db.QueryRowContext(ctx, "SELECT current_timestamp")
if err = row.Scan(¤tTimestamp); err != nil {
return "", fmt.Errorf("scanning row: %w", err)
}
return currentTimestamp, nil
}