chore: refactoring
This commit is contained in:
parent
2391e338b4
commit
ae86ef519c
7 changed files with 87 additions and 75 deletions
|
|
@ -10,7 +10,7 @@ import (
|
|||
"database/sql"
|
||||
)
|
||||
|
||||
const createLog = `-- name: CreateLog :exec
|
||||
const createLog = `-- name: CreateLog :one
|
||||
INSERT INTO logs (
|
||||
id,
|
||||
session_id,
|
||||
|
|
@ -27,7 +27,7 @@ INSERT INTO logs (
|
|||
?,
|
||||
?,
|
||||
?
|
||||
)
|
||||
) RETURNING id, session_id, timestamp, level, message, attributes, created_at
|
||||
`
|
||||
|
||||
type CreateLogParams struct {
|
||||
|
|
@ -40,8 +40,8 @@ type CreateLogParams struct {
|
|||
CreatedAt int64 `json:"created_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateLog(ctx context.Context, arg CreateLogParams) error {
|
||||
_, err := q.exec(ctx, q.createLogStmt, createLog,
|
||||
func (q *Queries) CreateLog(ctx context.Context, arg CreateLogParams) (Log, error) {
|
||||
row := q.queryRow(ctx, q.createLogStmt, createLog,
|
||||
arg.ID,
|
||||
arg.SessionID,
|
||||
arg.Timestamp,
|
||||
|
|
@ -50,7 +50,17 @@ func (q *Queries) CreateLog(ctx context.Context, arg CreateLogParams) error {
|
|||
arg.Attributes,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
return err
|
||||
var i Log
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SessionID,
|
||||
&i.Timestamp,
|
||||
&i.Level,
|
||||
&i.Message,
|
||||
&i.Attributes,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listAllLogs = `-- name: ListAllLogs :many
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
type Querier interface {
|
||||
CreateFile(ctx context.Context, arg CreateFileParams) (File, error)
|
||||
CreateLog(ctx context.Context, arg CreateLogParams) error
|
||||
CreateLog(ctx context.Context, arg CreateLogParams) (Log, error)
|
||||
CreateMessage(ctx context.Context, arg CreateMessageParams) (Message, error)
|
||||
CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error)
|
||||
DeleteFile(ctx context.Context, id string) error
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
-- name: CreateLog :exec
|
||||
-- name: CreateLog :one
|
||||
INSERT INTO logs (
|
||||
id,
|
||||
session_id,
|
||||
|
|
@ -15,7 +15,7 @@ INSERT INTO logs (
|
|||
?,
|
||||
?,
|
||||
?
|
||||
);
|
||||
) RETURNING *;
|
||||
|
||||
-- name: ListLogsBySession :many
|
||||
SELECT * FROM logs
|
||||
|
|
@ -25,4 +25,4 @@ ORDER BY timestamp ASC;
|
|||
-- name: ListAllLogs :many
|
||||
SELECT * FROM logs
|
||||
ORDER BY timestamp DESC
|
||||
LIMIT ?;
|
||||
LIMIT ?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue