Compare commits
4 commits
e1a4c1234f
...
6fea1a4695
| Author | SHA1 | Date | |
|---|---|---|---|
| 6fea1a4695 | |||
| cc6ac32324 | |||
| 2dd5f6fa60 | |||
| 945e3be683 |
4 changed files with 55 additions and 0 deletions
12
README.md
12
README.md
|
|
@ -27,3 +27,15 @@ $ tern new --migrations ./internal/store/pgstore/migrations create_messages_tabl
|
||||||
|
|
||||||
`tern.config` does not read `.env` file directly so a wrapper was created to be
|
`tern.config` does not read `.env` file directly so a wrapper was created to be
|
||||||
able to load environment variables.
|
able to load environment variables.
|
||||||
|
|
||||||
|
### Installing sqlc
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
|
||||||
|
```
|
||||||
|
|
||||||
|
### Generate sql types
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sqlc generate -f ./internal/store/pgstore/sqlc.yaml
|
||||||
|
```
|
||||||
|
|
|
||||||
2
go.sum
Normal file
2
go.sum
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
26
internal/store/pgstore/queries.sql.go
Normal file
26
internal/store/pgstore/queries.sql.go
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.27.0
|
||||||
|
// source: queries.sql
|
||||||
|
|
||||||
|
package pgstore
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
const getRoom = `-- name: GetRoom :one
|
||||||
|
SELECT
|
||||||
|
"id", "theme"
|
||||||
|
FROM rooms
|
||||||
|
WHERE id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetRoom(ctx context.Context, id uuid.UUID) (Room, error) {
|
||||||
|
row := q.db.QueryRow(ctx, getRoom, id)
|
||||||
|
var i Room
|
||||||
|
err := row.Scan(&i.ID, &i.Theme)
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
15
internal/store/pgstore/sqlc.yaml
Normal file
15
internal/store/pgstore/sqlc.yaml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
version: "2"
|
||||||
|
sql:
|
||||||
|
- engine: "postgresql"
|
||||||
|
queries: "./queries"
|
||||||
|
schema: "./migrations"
|
||||||
|
gen:
|
||||||
|
go:
|
||||||
|
out: "."
|
||||||
|
package: "pgstore"
|
||||||
|
sql_package: "pgx/v5"
|
||||||
|
overrides:
|
||||||
|
- db_type: "uuid"
|
||||||
|
go_type:
|
||||||
|
import: "github.com/google/uuid"
|
||||||
|
type: "UUID"
|
||||||
Loading…
Reference in a new issue