feat: string-unpack api
This commit is contained in:
32
string-unpack/internal/sql/db.go
Normal file
32
string-unpack/internal/sql/db.go
Normal file
@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.26.0
|
||||
|
||||
package sql
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
9
string-unpack/internal/sql/insert.sql
Normal file
9
string-unpack/internal/sql/insert.sql
Normal file
@ -0,0 +1,9 @@
|
||||
-- name: Insert :one
|
||||
INSERT INTO unpack_history (input, result)
|
||||
VALUES (@input, @result)
|
||||
RETURNING
|
||||
id,
|
||||
input,
|
||||
result,
|
||||
created_at
|
||||
;
|
37
string-unpack/internal/sql/insert.sql.go
Normal file
37
string-unpack/internal/sql/insert.sql.go
Normal file
@ -0,0 +1,37 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.26.0
|
||||
// source: insert.sql
|
||||
|
||||
package sql
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const insert = `-- name: Insert :one
|
||||
INSERT INTO unpack_history (input, result)
|
||||
VALUES ($1, $2)
|
||||
RETURNING
|
||||
id,
|
||||
input,
|
||||
result,
|
||||
created_at
|
||||
`
|
||||
|
||||
type InsertParams struct {
|
||||
Input string `db:"input" json:"input"`
|
||||
Result string `db:"result" json:"result"`
|
||||
}
|
||||
|
||||
func (q *Queries) Insert(ctx context.Context, arg InsertParams) (UnpackHistory, error) {
|
||||
row := q.db.QueryRow(ctx, insert, arg.Input, arg.Result)
|
||||
var i UnpackHistory
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Input,
|
||||
&i.Result,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
9
string-unpack/internal/sql/latest.sql
Normal file
9
string-unpack/internal/sql/latest.sql
Normal file
@ -0,0 +1,9 @@
|
||||
-- name: Latest :many
|
||||
SELECT id,
|
||||
input,
|
||||
result,
|
||||
created_at
|
||||
FROM unpack_history
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 15
|
||||
;
|
45
string-unpack/internal/sql/latest.sql.go
Normal file
45
string-unpack/internal/sql/latest.sql.go
Normal file
@ -0,0 +1,45 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.26.0
|
||||
// source: latest.sql
|
||||
|
||||
package sql
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const latest = `-- name: Latest :many
|
||||
SELECT id,
|
||||
input,
|
||||
result,
|
||||
created_at
|
||||
FROM unpack_history
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 15
|
||||
`
|
||||
|
||||
func (q *Queries) Latest(ctx context.Context) ([]UnpackHistory, error) {
|
||||
rows, err := q.db.Query(ctx, latest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []UnpackHistory
|
||||
for rows.Next() {
|
||||
var i UnpackHistory
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Input,
|
||||
&i.Result,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
16
string-unpack/internal/sql/models.go
Normal file
16
string-unpack/internal/sql/models.go
Normal file
@ -0,0 +1,16 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.26.0
|
||||
|
||||
package sql
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type UnpackHistory struct {
|
||||
ID pgtype.UUID `db:"id" json:"id"`
|
||||
Input string `db:"input" json:"input"`
|
||||
Result string `db:"result" json:"result"`
|
||||
CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"`
|
||||
}
|
16
string-unpack/internal/sql/querier.go
Normal file
16
string-unpack/internal/sql/querier.go
Normal file
@ -0,0 +1,16 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.26.0
|
||||
|
||||
package sql
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type Querier interface {
|
||||
Insert(ctx context.Context, arg InsertParams) (UnpackHistory, error)
|
||||
Latest(ctx context.Context) ([]UnpackHistory, error)
|
||||
}
|
||||
|
||||
var _ Querier = (*Queries)(nil)
|
Reference in New Issue
Block a user