diff options
| author | Kujtim Hoxha <[email protected]> | 2025-04-03 15:20:15 +0200 |
|---|---|---|
| committer | Kujtim Hoxha <[email protected]> | 2025-04-03 17:23:41 +0200 |
| commit | cfdd687216799cb5b47f099f1e7cd5dd16b3bdd0 (patch) | |
| tree | a822bfde1463a7080c0ea06dd17796d7a1617d3d /internal/db | |
| parent | afd9ad0560d76c2a6d161dad52553b10ff428905 (diff) | |
| download | opencode-cfdd687216799cb5b47f099f1e7cd5dd16b3bdd0.tar.gz opencode-cfdd687216799cb5b47f099f1e7cd5dd16b3bdd0.zip | |
add initial lsp support
Diffstat (limited to 'internal/db')
| -rw-r--r-- | internal/db/messages.sql.go | 71 | ||||
| -rw-r--r-- | internal/db/migrations/000001_initial.up.sql | 6 | ||||
| -rw-r--r-- | internal/db/models.go | 16 | ||||
| -rw-r--r-- | internal/db/sql/messages.sql | 13 |
4 files changed, 27 insertions, 79 deletions
diff --git a/internal/db/messages.sql.go b/internal/db/messages.sql.go index 3f2846740..4309db181 100644 --- a/internal/db/messages.sql.go +++ b/internal/db/messages.sql.go @@ -7,7 +7,6 @@ package db import ( "context" - "database/sql" ) const createMessage = `-- name: CreateMessage :one @@ -15,26 +14,20 @@ INSERT INTO messages ( id, session_id, role, - finished, - content, - tool_calls, - tool_results, + parts, created_at, updated_at ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, strftime('%s', 'now'), strftime('%s', 'now') + ?, ?, ?, ?, strftime('%s', 'now'), strftime('%s', 'now') ) -RETURNING id, session_id, role, content, thinking, finished, tool_calls, tool_results, created_at, updated_at +RETURNING id, session_id, role, parts, created_at, updated_at ` type CreateMessageParams struct { - ID string `json:"id"` - SessionID string `json:"session_id"` - Role string `json:"role"` - Finished bool `json:"finished"` - Content string `json:"content"` - ToolCalls sql.NullString `json:"tool_calls"` - ToolResults sql.NullString `json:"tool_results"` + ID string `json:"id"` + SessionID string `json:"session_id"` + Role string `json:"role"` + Parts string `json:"parts"` } func (q *Queries) CreateMessage(ctx context.Context, arg CreateMessageParams) (Message, error) { @@ -42,21 +35,14 @@ func (q *Queries) CreateMessage(ctx context.Context, arg CreateMessageParams) (M arg.ID, arg.SessionID, arg.Role, - arg.Finished, - arg.Content, - arg.ToolCalls, - arg.ToolResults, + arg.Parts, ) var i Message err := row.Scan( &i.ID, &i.SessionID, &i.Role, - &i.Content, - &i.Thinking, - &i.Finished, - &i.ToolCalls, - &i.ToolResults, + &i.Parts, &i.CreatedAt, &i.UpdatedAt, ) @@ -84,7 +70,7 @@ func (q *Queries) DeleteSessionMessages(ctx context.Context, sessionID string) e } const getMessage = `-- name: GetMessage :one -SELECT id, session_id, role, content, thinking, finished, tool_calls, tool_results, created_at, updated_at +SELECT id, session_id, role, parts, created_at, updated_at FROM messages WHERE id = ? LIMIT 1 ` @@ -96,11 +82,7 @@ func (q *Queries) GetMessage(ctx context.Context, id string) (Message, error) { &i.ID, &i.SessionID, &i.Role, - &i.Content, - &i.Thinking, - &i.Finished, - &i.ToolCalls, - &i.ToolResults, + &i.Parts, &i.CreatedAt, &i.UpdatedAt, ) @@ -108,7 +90,7 @@ func (q *Queries) GetMessage(ctx context.Context, id string) (Message, error) { } const listMessagesBySession = `-- name: ListMessagesBySession :many -SELECT id, session_id, role, content, thinking, finished, tool_calls, tool_results, created_at, updated_at +SELECT id, session_id, role, parts, created_at, updated_at FROM messages WHERE session_id = ? ORDER BY created_at ASC @@ -127,11 +109,7 @@ func (q *Queries) ListMessagesBySession(ctx context.Context, sessionID string) ( &i.ID, &i.SessionID, &i.Role, - &i.Content, - &i.Thinking, - &i.Finished, - &i.ToolCalls, - &i.ToolResults, + &i.Parts, &i.CreatedAt, &i.UpdatedAt, ); err != nil { @@ -151,32 +129,17 @@ func (q *Queries) ListMessagesBySession(ctx context.Context, sessionID string) ( const updateMessage = `-- name: UpdateMessage :exec UPDATE messages SET - content = ?, - thinking = ?, - tool_calls = ?, - tool_results = ?, - finished = ?, + parts = ?, updated_at = strftime('%s', 'now') WHERE id = ? ` type UpdateMessageParams struct { - Content string `json:"content"` - Thinking string `json:"thinking"` - ToolCalls sql.NullString `json:"tool_calls"` - ToolResults sql.NullString `json:"tool_results"` - Finished bool `json:"finished"` - ID string `json:"id"` + Parts string `json:"parts"` + ID string `json:"id"` } func (q *Queries) UpdateMessage(ctx context.Context, arg UpdateMessageParams) error { - _, err := q.exec(ctx, q.updateMessageStmt, updateMessage, - arg.Content, - arg.Thinking, - arg.ToolCalls, - arg.ToolResults, - arg.Finished, - arg.ID, - ) + _, err := q.exec(ctx, q.updateMessageStmt, updateMessage, arg.Parts, arg.ID) return err } diff --git a/internal/db/migrations/000001_initial.up.sql b/internal/db/migrations/000001_initial.up.sql index d4a5e39fe..2fbe5547e 100644 --- a/internal/db/migrations/000001_initial.up.sql +++ b/internal/db/migrations/000001_initial.up.sql @@ -23,11 +23,7 @@ CREATE TABLE IF NOT EXISTS messages ( id TEXT PRIMARY KEY, session_id TEXT NOT NULL, role TEXT NOT NULL, - content TEXT NOT NULL, - thinking Text NOT NULL DEFAULT '', - finished BOOLEAN NOT NULL DEFAULT 0, - tool_calls TEXT, - tool_results TEXT, + parts TEXT NOT NULL default '[]', created_at INTEGER NOT NULL, -- Unix timestamp in milliseconds updated_at INTEGER NOT NULL, -- Unix timestamp in milliseconds FOREIGN KEY (session_id) REFERENCES sessions (id) ON DELETE CASCADE diff --git a/internal/db/models.go b/internal/db/models.go index fc3140a13..1ad8607a9 100644 --- a/internal/db/models.go +++ b/internal/db/models.go @@ -9,16 +9,12 @@ import ( ) type Message struct { - ID string `json:"id"` - SessionID string `json:"session_id"` - Role string `json:"role"` - Content string `json:"content"` - Thinking string `json:"thinking"` - Finished bool `json:"finished"` - ToolCalls sql.NullString `json:"tool_calls"` - ToolResults sql.NullString `json:"tool_results"` - CreatedAt int64 `json:"created_at"` - UpdatedAt int64 `json:"updated_at"` + ID string `json:"id"` + SessionID string `json:"session_id"` + Role string `json:"role"` + Parts string `json:"parts"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` } type Session struct { diff --git a/internal/db/sql/messages.sql b/internal/db/sql/messages.sql index 0674e62c1..64571158f 100644 --- a/internal/db/sql/messages.sql +++ b/internal/db/sql/messages.sql @@ -14,25 +14,18 @@ INSERT INTO messages ( id, session_id, role, - finished, - content, - tool_calls, - tool_results, + parts, created_at, updated_at ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, strftime('%s', 'now'), strftime('%s', 'now') + ?, ?, ?, ?, strftime('%s', 'now'), strftime('%s', 'now') ) RETURNING *; -- name: UpdateMessage :exec UPDATE messages SET - content = ?, - thinking = ?, - tool_calls = ?, - tool_results = ?, - finished = ?, + parts = ?, updated_at = strftime('%s', 'now') WHERE id = ?; |
