Skip to content

Commit 876c7c8

Browse files
docs: Use managed databases in PostgreSQL getting started guide (#2892)
1 parent bd9167e commit 876c7c8

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

docs/tutorials/getting-started-mysql.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# Getting started with MySQL
22

33
This tutorial assumes that the latest version of sqlc is
4-
[installed](../overview/install.md) and ready to use. And we'll
5-
be generating Go code, but other
6-
[language plugins](../reference/language-support.rst) are available.
4+
[installed](../overview/install.md) and ready to use.
5+
6+
We'll generate Go code here, but other
7+
[language plugins](../reference/language-support.rst) are available. You'll
8+
naturally need the Go toolchain if you want to build and run a program with the
9+
code sqlc generates, but sqlc itself has no dependencies.
10+
11+
## Setting up
712

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

@@ -29,6 +34,8 @@ sql:
2934
out: "tutorial"
3035
```
3136
37+
## Schema and queries
38+
3239
sqlc needs to know your database schema and queries in order to generate code.
3340
In the same directory, create a file named `schema.sql` with the following
3441
content:
@@ -64,6 +71,8 @@ DELETE FROM authors
6471
WHERE id = ?;
6572
```
6673

74+
## Generating code
75+
6776
You are now ready to generate code. You shouldn't see any output when you run
6877
the `generate` subcommand, unless something goes wrong:
6978

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

97+
## Using generated code
98+
8899
You can use your newly-generated `tutorial` package from any Go program.
89100
Create a file named `tutorial.go` and add the following contents:
90101

docs/tutorials/getting-started-postgresql.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
# Getting started with PostgreSQL
22

33
This tutorial assumes that the latest version of sqlc is
4-
[installed](../overview/install.md) and ready to use. And we'll
5-
be generating Go code, but other
6-
[language plugins](../reference/language-support.rst) are available.
4+
[installed](../overview/install.md) and ready to use.
5+
6+
We'll generate Go code here, but other
7+
[language plugins](../reference/language-support.rst) are available. You'll
8+
naturally need the Go toolchain if you want to build and run a program with the
9+
code sqlc generates, but sqlc itself has no dependencies.
10+
11+
We'll also rely on sqlc's [managed databases](../howto/managed-databases.md),
12+
which require a sqlc Cloud project and auth token. You can get those from
13+
the [sqlc Cloud dashboard](https://dashboard.sqlc.dev/). Managed databases are
14+
an optional feature that improves sqlc's query analysis in many cases, but you
15+
can turn it off simply by removing the `cloud` and `database` sections of your
16+
configuration.
17+
18+
## Setting up
719

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

@@ -19,17 +31,29 @@ following contents:
1931

2032
```yaml
2133
version: "2"
34+
cloud:
35+
project: "<your project id>"
2236
sql:
2337
- engine: "postgresql"
2438
queries: "query.sql"
2539
schema: "schema.sql"
40+
database:
41+
managed: true
2642
gen:
2743
go:
2844
package: "tutorial"
2945
out: "tutorial"
3046
sql_package: "pgx/v5"
3147
```
3248
49+
And finally, set the `SQLC_AUTH_TOKEN` environment variable:
50+
51+
```shell
52+
export SQLC_AUTH_TOKEN="<your sqlc auth token>"
53+
```
54+
55+
## Schema and queries
56+
3357
sqlc needs to know your database schema and queries in order to generate code.
3458
In the same directory, create a file named `schema.sql` with the following
3559
content:
@@ -84,6 +108,8 @@ WHERE id = $1
84108
RETURNING *;
85109
```
86110

111+
## Generating code
112+
87113
You are now ready to generate code. You shouldn't see any output when you run
88114
the `generate` subcommand, unless something goes wrong:
89115

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

134+
## Using generated code
135+
108136
You can use your newly-generated `tutorial` package from any Go program.
109137
Create a file named `tutorial.go` and add the following contents:
110138

docs/tutorials/getting-started-sqlite.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# Getting started with SQLite
22

33
This tutorial assumes that the latest version of sqlc is
4-
[installed](../overview/install.md) and ready to use. And we'll
5-
be generating Go code, but other
6-
[language plugins](../reference/language-support.rst) are available.
4+
[installed](../overview/install.md) and ready to use.
5+
6+
We'll generate Go code here, but other
7+
[language plugins](../reference/language-support.rst) are available. You'll
8+
naturally need the Go toolchain if you want to build and run a program with the
9+
code sqlc generates, but sqlc itself has no dependencies.
10+
11+
## Setting up
712

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

@@ -29,6 +34,8 @@ sql:
2934
out: "tutorial"
3035
```
3136
37+
## Schema and queries
38+
3239
sqlc needs to know your database schema and queries in order to generate code.
3340
In the same directory, create a file named `schema.sql` with the following
3441
content:
@@ -83,6 +90,8 @@ WHERE id = ?
8390
RETURNING *;
8491
```
8592

93+
## Generating code
94+
8695
You are now ready to generate code. You shouldn't see any output when you run
8796
the `generate` subcommand, unless something goes wrong:
8897

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

116+
## Using generated code
117+
107118
You can use your newly-generated `tutorial` package from any Go program.
108119
Create a file named `tutorial.go` and add the following contents:
109120

0 commit comments

Comments
 (0)