Compare commits

..

4 commits

4 changed files with 55 additions and 0 deletions

View file

@ -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
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
View 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=

View 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
}

View 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"