feat: add generated query
This commit is contained in:
parent
b6819e8205
commit
034be9f4ae
3 changed files with 80 additions and 0 deletions
32
internal/store/pgstore/db.go
Normal file
32
internal/store/pgstore/db.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.27.0
|
||||
|
||||
package pgstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
22
internal/store/pgstore/models.go
Normal file
22
internal/store/pgstore/models.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.27.0
|
||||
|
||||
package pgstore
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
ID uuid.UUID
|
||||
RoomID uuid.UUID
|
||||
Message string
|
||||
ReactionCount int64
|
||||
Answered bool
|
||||
}
|
||||
|
||||
type Room struct {
|
||||
ID uuid.UUID
|
||||
Theme string
|
||||
}
|
||||
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
|
||||
}
|
||||
Loading…
Reference in a new issue