Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Use managed databases in PostgreSQL getting started guide #2892

Merged
merged 1 commit into from
Oct 20, 2023
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
17 changes: 14 additions & 3 deletions docs/tutorials/getting-started-mysql.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Getting started with MySQL

This tutorial assumes that the latest version of sqlc is
[installed](../overview/install.md) and ready to use. And we'll
be generating Go code, but other
[language plugins](../reference/language-support.rst) are available.
[installed](../overview/install.md) and ready to use.

We'll generate Go code here, but other
[language plugins](../reference/language-support.rst) are available. You'll
naturally need the Go toolchain if you want to build and run a program with the
code sqlc generates, but sqlc itself has no dependencies.

## Setting up

Create a new directory called `sqlc-tutorial` and open it up.

Expand All @@ -29,6 +34,8 @@ sql:
out: "tutorial"
```

## Schema and queries

sqlc needs to know your database schema and queries in order to generate code.
In the same directory, create a file named `schema.sql` with the following
content:
Expand Down Expand Up @@ -64,6 +71,8 @@ DELETE FROM authors
WHERE id = ?;
```

## Generating code

You are now ready to generate code. You shouldn't see any output when you run
the `generate` subcommand, unless something goes wrong:

Expand All @@ -85,6 +94,8 @@ source code. These files comprise a Go package named `tutorial`:
└── query.sql.go
```

## Using generated code

You can use your newly-generated `tutorial` package from any Go program.
Create a file named `tutorial.go` and add the following contents:

Expand Down
34 changes: 31 additions & 3 deletions docs/tutorials/getting-started-postgresql.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
# Getting started with PostgreSQL

This tutorial assumes that the latest version of sqlc is
[installed](../overview/install.md) and ready to use. And we'll
be generating Go code, but other
[language plugins](../reference/language-support.rst) are available.
[installed](../overview/install.md) and ready to use.

We'll generate Go code here, but other
[language plugins](../reference/language-support.rst) are available. You'll
naturally need the Go toolchain if you want to build and run a program with the
code sqlc generates, but sqlc itself has no dependencies.

We'll also rely on sqlc's [managed databases](../howto/managed-databases.md),
which require a sqlc Cloud project and auth token. You can get those from
the [sqlc Cloud dashboard](https://dashboard.sqlc.dev/). Managed databases are
an optional feature that improves sqlc's query analysis in many cases, but you
can turn it off simply by removing the `cloud` and `database` sections of your
configuration.

## Setting up

Create a new directory called `sqlc-tutorial` and open it up.

Expand All @@ -19,17 +31,29 @@ following contents:

```yaml
version: "2"
cloud:
project: "<your project id>"
sql:
- engine: "postgresql"
queries: "query.sql"
schema: "schema.sql"
database:
managed: true
gen:
go:
package: "tutorial"
out: "tutorial"
sql_package: "pgx/v5"
```

And finally, set the `SQLC_AUTH_TOKEN` environment variable:

```shell
export SQLC_AUTH_TOKEN="<your sqlc auth token>"
```

## Schema and queries

sqlc needs to know your database schema and queries in order to generate code.
In the same directory, create a file named `schema.sql` with the following
content:
Expand Down Expand Up @@ -84,6 +108,8 @@ WHERE id = $1
RETURNING *;
```

## Generating code

You are now ready to generate code. You shouldn't see any output when you run
the `generate` subcommand, unless something goes wrong:

Expand All @@ -105,6 +131,8 @@ source code. These files comprise a Go package named `tutorial`:
└── query.sql.go
```

## Using generated code

You can use your newly-generated `tutorial` package from any Go program.
Create a file named `tutorial.go` and add the following contents:

Expand Down
17 changes: 14 additions & 3 deletions docs/tutorials/getting-started-sqlite.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Getting started with SQLite

This tutorial assumes that the latest version of sqlc is
[installed](../overview/install.md) and ready to use. And we'll
be generating Go code, but other
[language plugins](../reference/language-support.rst) are available.
[installed](../overview/install.md) and ready to use.

We'll generate Go code here, but other
[language plugins](../reference/language-support.rst) are available. You'll
naturally need the Go toolchain if you want to build and run a program with the
code sqlc generates, but sqlc itself has no dependencies.

## Setting up

Create a new directory called `sqlc-tutorial` and open it up.

Expand All @@ -29,6 +34,8 @@ sql:
out: "tutorial"
```

## Schema and queries

sqlc needs to know your database schema and queries in order to generate code.
In the same directory, create a file named `schema.sql` with the following
content:
Expand Down Expand Up @@ -83,6 +90,8 @@ WHERE id = ?
RETURNING *;
```

## Generating code

You are now ready to generate code. You shouldn't see any output when you run
the `generate` subcommand, unless something goes wrong:

Expand All @@ -104,6 +113,8 @@ source code. These files comprise a Go package named `tutorial`:
└── query.sql.go
```

## Using generated code

You can use your newly-generated `tutorial` package from any Go program.
Create a file named `tutorial.go` and add the following contents:

Expand Down
Loading