Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,4 @@ updates:
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "pip"
directory: "/docs"
schedule:
interval: "daily"
ignore:
# sphinx-rtd-theme does not support the latest versions of docutils and
# sphinx
- dependency-name: "docutils"
- dependency-name: "sphinx"
groups:
production-dependencies:
dependency-type: "production"
development-dependencies:
dependency-type: "development"

1 change: 0 additions & 1 deletion .github/workflows/buf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
pull_request:
paths-ignore:
- 'docs/**'
- '.readthedocs.yaml'
jobs:
build:
runs-on: ubuntu-latest
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci-kotlin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ on:
- main
paths-ignore:
- 'docs/**'
- '.readthedocs.yaml'
pull_request:
paths-ignore:
- 'docs/**'
- '.readthedocs.yaml'
jobs:
build:
if: false
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ on:
- main
paths-ignore:
- 'docs/**'
- '.readthedocs.yaml'
pull_request:
paths-ignore:
- 'docs/**'
- '.readthedocs.yaml'
jobs:
build:
if: false
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/ci-typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ on:
- main
paths-ignore:
- 'docs/**'
- '.readthedocs.yaml'
pull_request:
paths-ignore:
- 'docs/**'
- '.readthedocs.yaml'
jobs:
build:
if: false
Expand Down
30 changes: 0 additions & 30 deletions .readthedocs.yaml

This file was deleted.

28 changes: 0 additions & 28 deletions docs/Makefile

This file was deleted.

17 changes: 0 additions & 17 deletions docs/_static/customize.css

This file was deleted.

Binary file removed docs/_static/favicon.png
Binary file not shown.
Binary file removed docs/_static/logo.png
Binary file not shown.
7 changes: 0 additions & 7 deletions docs/_templates/breadcrumbs.html

This file was deleted.

6 changes: 0 additions & 6 deletions docs/_templates/layout.html

This file was deleted.

83 changes: 0 additions & 83 deletions docs/conf.py

This file was deleted.

125 changes: 125 additions & 0 deletions docs/guides/using-go-and-pgx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Using Go and pgx

> [!NOTE]
> `pgx/v5` is supported starting from v1.18.0.

pgx is a pure Go driver and toolkit for PostgreSQL. It's become the default
PostgreSQL package for many Gophers since lib/pq was put into maintenance mode.

## Getting started

To start generating code that uses pgx, set the `sql_package` field in
your `sqlc.yaml` configuration file. Valid options are `pgx/v4` or
`pgx/v5`

```yaml
version: "2"
sql:
- engine: "postgresql"
queries: "query.sql"
schema: "query.sql"
gen:
go:
package: "db"
sql_package: "pgx/v5"
out: "db"
```

If you don't have an existing sqlc project on hand, create a directory with the
configuration file above and the following `query.sql` file.

```sql
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text
);

-- name: GetAuthor :one
SELECT * FROM authors
WHERE id = $1 LIMIT 1;

-- name: ListAuthors :many
SELECT * FROM authors
ORDER BY name;

-- name: CreateAuthor :one
INSERT INTO authors (
name, bio
) VALUES (
$1, $2
)
RETURNING *;

-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE id = $1;
```

Generating the code will now give you pgx-compatible database access methods.

```bash
sqlc generate
```

## Generated code walkthrough

The generated code is very similar to the code generated when using
`lib/pq`. However, instead of using `database/sql`, the code uses
pgx types directly.

```go
package main

import (
"context"
"fmt"
"os"

"github.com/jackc/pgx/v5"

"example.com/sqlc-tutorial/db"
)

func main() {
// urlExample := "postgres://username:password@localhost:5432/database_name"
conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
os.Exit(1)
}
defer conn.Close(context.Background())

q := db.New(conn)

author, err := q.GetAuthor(context.Background(), 1)
if err != nil {
fmt.Fprintf(os.Stderr, "GetAuthor failed: %v\n", err)
os.Exit(1)
}

fmt.Println(author.Name)
}
```

> [!NOTE]
> For production applications, consider using pgxpool for connection pooling:
>
> ```go
> import (
> "github.com/jackc/pgx/v5/pgxpool"
> "example.com/sqlc-tutorial/db"
> )
>
> func main() {
> pool, err := pgxpool.New(context.Background(), os.Getenv("DATABASE_URL"))
> if err != nil {
> fmt.Fprintf(os.Stderr, "Unable to create connection pool: %v\n", err)
> os.Exit(1)
> }
> defer pool.Close()
>
> q := db.New(pool)
> // Use q the same way as with single connections
> }
> ```
Loading
Loading