Skip to content

Commit 2a39eb0

Browse files
committed
Merge remote-tracking branch 'upstream/master' into kotlin
2 parents ada4dfc + 3e2e83d commit 2a39eb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2662
-199
lines changed

.github/workflows/equinox.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
env:
2222
EQUINOX_API_TOKEN: ${{ secrets.EQUINOX_API_TOKEN }}
2323
EQUINOX_SIGNING_KEY: ${{ secrets.EQUINOX_SIGNING_KEY }}
24-
run: equinox release --channel devel --version=$GITHUB_SHA --draft --platforms=darwin_amd64 --app=app_i4iCp1SuYfZ --token=$EQUINOX_API_TOKEN ./cmd/sqlc
24+
run: go run scripts/release.go -draft devel darwin_amd64
2525

2626
linux:
2727
name: Build on Linux
@@ -39,6 +39,6 @@ jobs:
3939
env:
4040
EQUINOX_API_TOKEN: ${{ secrets.EQUINOX_API_TOKEN }}
4141
EQUINOX_SIGNING_KEY: ${{ secrets.EQUINOX_SIGNING_KEY }}
42-
run: ./equinox release --channel devel --version=$GITHUB_SHA --platforms=linux_amd64 --app=app_i4iCp1SuYfZ --token=$EQUINOX_API_TOKEN ./cmd/sqlc
42+
run: go run scripts/release.go devel linux_amd64
4343

4444

README.md

Lines changed: 51 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
> 🚨
2-
>
3-
> sqlc is **new** and under rapid development.
4-
>
5-
> The code it generates is correct and safe for production use, but there is
6-
> currently no guarantee of stability or backwards-compatibility of the command
7-
> line interface, configuration file format or generated code.
8-
>
9-
> 🚨
10-
111
# sqlc: A SQL Compiler
122

133
> And lo, the Great One looked down upon the people and proclaimed:
@@ -232,6 +222,7 @@ Your favorite PostgreSQL / Go features are supported:
232222
- [Query annotations](./docs/annotations.md)
233223
- [Transactions](./docs/transactions.md)
234224
- [Prepared queries](./docs/prepared_query.md)
225+
- [Named parameters](./docs/named_parameters.md)
235226
- [SELECT](./docs/query_one.md)
236227
- [NULL](./docs/null.md)
237228
- [COUNT](./docs/query_count.md)
@@ -265,7 +256,7 @@ Available Commands:
265256
compile Statically check SQL for syntax and type errors
266257
generate Generate Go code from SQL
267258
help Help about any command
268-
init Create an empty sqlc.json settings file
259+
init Create an empty sqlc.yaml settings file
269260
version Print the sqlc version number
270261
271262
Flags:
@@ -276,24 +267,19 @@ Use "sqlc [command] --help" for more information about a command.
276267

277268
## Settings
278269

279-
The `sqlc` tool is configured via a `sqlc.json` file. This file must be
270+
The `sqlc` tool is configured via a `sqlc.yaml` file. This file must be
280271
in the directory where the `sqlc` command is run.
281272

282-
```json
283-
{
284-
"version": "1",
285-
"packages": [
286-
{
287-
"name": "db",
288-
"emit_json_tags": true,
289-
"emit_prepared_queries": false,
290-
"emit_interface": true,
291-
"path": "internal/db",
292-
"queries": "./sql/query/",
293-
"schema": "./sql/schema/"
294-
}
295-
]
296-
}
273+
```yaml
274+
version: "1"
275+
packages:
276+
- name: "db",
277+
emit_json_tags: true
278+
emit_prepared_queries: false
279+
emit_interface: true
280+
path: "internal/db"
281+
queries: "./sql/query/"
282+
schema: "./sql/schema/"
297283
```
298284
299285
Each package document has the following keys:
@@ -324,17 +310,12 @@ If a different Go package for UUIDs is required, specify the package in the
324310
`overrides` array. In this case, I'm going to use the `github.com/gofrs/uuid`
325311
instead.
326312

327-
```
328-
{
329-
"version": "1",
330-
"packages": [...],
331-
"overrides": [
332-
{
333-
"go_type": "github.com/gofrs/uuid.UUID",
334-
"db_type": "uuid"
335-
}
336-
]
337-
}
313+
```yaml
314+
version: "1"
315+
packages: [...]
316+
overrides:
317+
- go_type: "github.com/gofrs/uuid.UUID"
318+
db_type: "uuid"
338319
```
339320

340321
Each override document has the following keys:
@@ -354,36 +335,24 @@ This may be configured by specifying the `column` property in the override defin
354335
should be of the form `table.column` buy you may be even more specify by specifying `schema.table.column`
355336
or `catalog.schema.table.column`.
356337

357-
```
358-
{
359-
"version": "1",
360-
"packages": [...],
361-
"overrides": [
362-
{
363-
"column": "authors.id",
364-
"go_type": "github.com/segmentio/ksuid.KSUID"
365-
}
366-
]
367-
}
338+
```yaml
339+
version: "1"
340+
packages: [...]
341+
overrides:
342+
- column: "authors.id"
343+
go_type: "github.com/segmentio/ksuid.KSUID"
368344
```
369345

370346
### Package Level Overrides
371347

372348
Overrides can be configured globally, as demonstrated in the previous sections, or they can be configured on a per-package which
373349
scopes the override behavior to just a single package:
374350

351+
```yaml
352+
version: "1"
353+
packages:
354+
- overrides: [...]
375355
```
376-
{
377-
"version": "1",
378-
"packages": [
379-
{
380-
...
381-
"overrides": [...]
382-
}
383-
],
384-
}
385-
```
386-
387356

388357
### Renaming Struct Fields
389358

@@ -401,14 +370,11 @@ If you're not happy with a field's generated name, use the `rename` dictionary
401370
to pick a new name. The keys are column names and the values are the struct
402371
field name to use.
403372
404-
```json
405-
{
406-
"version": "1",
407-
"packages": [...],
408-
"rename": {
409-
"spotify_url": "SpotifyURL"
410-
}
411-
}
373+
```yaml
374+
version: "1"
375+
packages: [...]
376+
rename:
377+
spotify_url: "SpotifyURL"
412378
```
413379

414380
## Downloads
@@ -420,7 +386,8 @@ Each commit is deployed to the [`devel` channel on Equinox](https://dl.equinox.i
420386
## Other Databases and Languages
421387

422388
sqlc currently only supports PostgreSQL / Go. MySQL support has been merged,
423-
but it's marked as experimental. SQLite and TypeScript support are planned.
389+
but it's marked as experimental. SQLite, TypeScript, and Kotlin support are
390+
planned.
424391

425392
| Language | PostgreSQL | MySQL | SQLite |
426393
| ------------ |:----------------:|:----------------:|:----------------:|
@@ -429,6 +396,21 @@ but it's marked as experimental. SQLite and TypeScript support are planned.
429396

430397
If you'd like to add another database or language, we'd welcome a contribution.
431398

399+
## Sponsors
400+
401+
sqlc development is funded by our generous sponsors.
402+
403+
- Companies
404+
- [Meter](https://meter.com)
405+
- [ngrok](https://ngrok.com)
406+
- Individuals
407+
- [CyberAx](https://github.com/Cyberax)
408+
409+
If you use sqlc at your company, please consider [becoming a
410+
sponsor](https://github.com/sponsors/kyleconroy) today.
411+
412+
Sponsors receive priority support via the sqlc Slack organization.
413+
432414
## Acknowledgements
433415

434416
sqlc was inspired by [PugSQL](https://pugsql.org/) and

docs/migrations.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ sqlc will ignore rollback statements when parsing migration SQL files. The follo
55
- [goose](https://github.com/pressly/goose)
66
- [sql-migrate](https://github.com/rubenv/sql-migrate)
77
- [tern](https://github.com/jackc/tern)
8+
- [golang-migrate](https://github.com/golang-migrate/migrate)
89

910
## goose
1011

@@ -67,4 +68,32 @@ type Comment struct {
6768
ID int32
6869
Text string
6970
}
70-
```
71+
```
72+
73+
## golang-migrate
74+
75+
In `20060102.up.sql`:
76+
77+
```sql
78+
CREATE TABLE post (
79+
id int NOT NULL,
80+
title text,
81+
body text,
82+
PRIMARY KEY(id)
83+
);
84+
```
85+
86+
In `20060102.down.sql`:
87+
```sql
88+
DROP TABLE post;
89+
```
90+
91+
```go
92+
package db
93+
94+
type Post struct {
95+
ID int
96+
Title sql.NullString
97+
Body sql.NullString
98+
}
99+
```

docs/named_parameters.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Named parameters
2+
3+
sqlc tried to generate good names for positional parameters, but sometimes it
4+
lacks enough context. The following SQL generates parameters with less than
5+
ideal names:
6+
7+
```sql
8+
-- name: UpsertAuthorName :one
9+
UPDATE author
10+
SET
11+
name = CASE WHEN $1::bool
12+
THEN $2::text
13+
ELSE name
14+
END
15+
RETURNING *;
16+
```
17+
18+
```go
19+
type UpdateAuthorNameParams struct {
20+
Column1 bool `json:""`
21+
Column2_2 string `json:"_2"`
22+
}
23+
```
24+
25+
In these cases, named parameters give you the control over field names on the
26+
Params struct.
27+
28+
```sql
29+
-- name: UpsertAuthorName :one
30+
UPDATE author
31+
SET
32+
name = CASE WHEN sqlc.arg(set_name)::bool
33+
THEN sqlc.arg(name)::text
34+
ELSE name
35+
END
36+
RETURNING *;
37+
```
38+
39+
```go
40+
type UpdateAuthorNameParams struct {
41+
SetName bool `json:"set_name"`
42+
Name string `json:"name"`
43+
}
44+
```
45+
46+
If the `sqlc.arg()` syntax is too verbose for your taste, you can use the `@`
47+
operator as a shortcut.
48+
49+
```sql
50+
-- name: UpsertAuthorName :one
51+
UPDATE author
52+
SET
53+
name = CASE WHEN @set_name::bool
54+
THEN @name::text
55+
ELSE name
56+
END
57+
RETURNING *;
58+
```

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ require (
1313
golang.org/x/sys v0.0.0-20191220220014-0732a990476f // indirect
1414
google.golang.org/genproto v0.0.0-20191223191004-3caeed10a8bf // indirect
1515
google.golang.org/grpc v1.26.0 // indirect
16+
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71
1617
vitess.io/vitess v0.0.0-20200119095853-bd8205ebca4a
1718
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
515515
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
516516
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
517517
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
518+
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71 h1:Xe2gvTZUJpsvOWUnvmL/tmhVBZUmHSvLbMjRj6NUUKo=
519+
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
518520
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
519521
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
520522
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

0 commit comments

Comments
 (0)