Skip to content

Commit 76c79c2

Browse files
committed
Driver/Go: Add dedicated page
1 parent 9227a39 commit 76c79c2

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

docs/connect/go.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
(connect-go)=
2+
3+
# Go
4+
5+
:::{include} /_include/links.md
6+
:::
7+
8+
:::{div} sd-text-muted
9+
Use pgx to connect to CrateDB from Go applications.
10+
:::
11+
12+
:::{rubric} About
13+
:::
14+
15+
[pgx] is a pure Go driver and toolkit for PostgreSQL.
16+
17+
:::{rubric} Synopsis
18+
:::
19+
20+
```golang
21+
package main
22+
23+
import (
24+
"context"
25+
"fmt"
26+
"os"
27+
28+
"github.com/jackc/pgx/v5"
29+
)
30+
31+
func main() {
32+
// urlExample := "postgres://username:password@localhost:5432/schema_name"
33+
conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
34+
if err != nil {
35+
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
36+
os.Exit(1)
37+
}
38+
defer conn.Close(context.Background())
39+
40+
err = conn.QueryRow(context.Background(), "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3").Scan()
41+
if err != nil {
42+
fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
43+
os.Exit(1)
44+
}
45+
46+
fmt.Println(name, weight)
47+
}
48+
```
49+
50+
51+
## Example
52+
53+
:::{card}
54+
:link: https://github.com/crate/cratedb-examples/tree/main/by-language/go-pgx
55+
:link-type: url
56+
{material-outlined}`play_arrow;2em`
57+
Connect to CrateDB and CrateDB Cloud using Go.
58+
+++
59+
Demonstrates basic examples and bulk insert operations using the pgx driver.
60+
:::
61+
62+
[![Go pgx](https://github.com/crate/cratedb-examples/actions/workflows/lang-go-pgx.yml/badge.svg)](https://github.com/crate/cratedb-examples/actions/workflows/lang-go-pgx.yml)
63+
64+
65+
[pgx]: https://github.com/jackc/pgx

docs/connect/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ CrateDB drivers and adapters for supported programming languages, frameworks, an
4949
:margin: 4 4 0 0
5050
:padding: 0
5151

52+
::::{grid-item-card} Go
53+
:link: connect-go
54+
:link-type: ref
55+
:link-alt: Connect to CrateDB using Go
56+
:padding: 3
57+
:text-align: center
58+
:class-card: sd-pt-3
59+
:class-body: sd-fs-1
60+
:class-title: sd-fs-6
61+
{fab}`golang`
62+
::::
63+
5264
::::{grid-item-card} Java
5365
:link: connect-java
5466
:link-type: ref
@@ -182,6 +194,7 @@ application
182194
:maxdepth: 1
183195
:hidden:
184196
197+
go
185198
java
186199
javascript
187200
php

0 commit comments

Comments
 (0)