diff options
| author | adamdottv <[email protected]> | 2025-05-13 10:27:09 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-05-13 10:27:09 -0500 |
| commit | ae86ef519c5dc557914c29bd1786b1c87d8dcb95 (patch) | |
| tree | e1b5f7bbeb74739c74055d205ad62181230f0b12 /internal/db | |
| parent | 2391e338b4e41726e7233e2bf027a62476140130 (diff) | |
| download | opencode-ae86ef519c5dc557914c29bd1786b1c87d8dcb95.tar.gz opencode-ae86ef519c5dc557914c29bd1786b1c87d8dcb95.zip | |
chore: refactoring
Diffstat (limited to 'internal/db')
| -rw-r--r-- | internal/db/logs.sql.go | 20 | ||||
| -rw-r--r-- | internal/db/querier.go | 2 | ||||
| -rw-r--r-- | internal/db/sql/logs.sql | 6 |
3 files changed, 19 insertions, 9 deletions
diff --git a/internal/db/logs.sql.go b/internal/db/logs.sql.go index d227b472a..aa89d7d22 100644 --- a/internal/db/logs.sql.go +++ b/internal/db/logs.sql.go @@ -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 diff --git a/internal/db/querier.go b/internal/db/querier.go index 08ad41ec7..7b089f021 100644 --- a/internal/db/querier.go +++ b/internal/db/querier.go @@ -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 diff --git a/internal/db/sql/logs.sql b/internal/db/sql/logs.sql index 1a0655f7e..58414f88a 100644 --- a/internal/db/sql/logs.sql +++ b/internal/db/sql/logs.sql @@ -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 ?;
\ No newline at end of file +LIMIT ?; |
