Skip to content

Commit bd0b490

Browse files
authored
Merge pull request #67 from openclaw/refactor/sqlc-store
refactor: move stable store SQL to sqlc
2 parents f7a8fa2 + 5b5afe9 commit bd0b490

17 files changed

Lines changed: 3337 additions & 651 deletions

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,15 @@ jobs:
7272
- name: Test with coverage
7373
run: go test -count=1 ./... -coverprofile=coverage.out
7474

75+
- name: Exclude generated code from coverage
76+
run: grep -v '^github.com/openclaw/discrawl/internal/store/storedb/' coverage.out > coverage.filtered.out
77+
7578
- name: Test with race detector
7679
run: go test -count=1 -race ./...
7780

7881
- name: Enforce coverage floor
7982
run: |
80-
total="$(go tool cover -func=coverage.out | awk '/^total:/ { sub(/%$/, "", $3); print $3 }')"
83+
total="$(go tool cover -func=coverage.filtered.out | awk '/^total:/ { sub(/%$/, "", $3); print $3 }')"
8184
awk -v total="$total" 'BEGIN {
8285
if (total == "") {
8386
print "missing coverage total"

internal/store/attachments.go

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"strings"
66
"time"
7+
8+
"github.com/openclaw/discrawl/internal/store/storedb"
79
)
810

911
type AttachmentListOptions struct {
@@ -241,29 +243,24 @@ func (s *Store) ExpandAttachmentChannelIDs(ctx context.Context, channelIDs []str
241243
}
242244

243245
func (s *Store) UpdateAttachmentMedia(ctx context.Context, update AttachmentMediaUpdate) error {
244-
_, err := s.db.ExecContext(ctx, `
245-
update message_attachments
246-
set media_path = ?,
247-
content_sha256 = ?,
248-
content_size = ?,
249-
fetched_at = ?,
250-
fetch_status = ?,
251-
fetch_error = ?,
252-
updated_at = ?
253-
where attachment_id = ?
254-
`, nullable(update.MediaPath), nullable(update.ContentSHA256), update.ContentSize, nullable(update.FetchedAt),
255-
update.FetchStatus, update.FetchError, time.Now().UTC().Format(timeLayout), update.AttachmentID)
256-
return err
246+
return s.q.UpdateAttachmentMedia(ctx, storedb.UpdateAttachmentMediaParams{
247+
MediaPath: nullString(update.MediaPath),
248+
ContentSha256: nullString(update.ContentSHA256),
249+
ContentSize: update.ContentSize,
250+
FetchedAt: nullString(update.FetchedAt),
251+
FetchStatus: update.FetchStatus,
252+
FetchError: update.FetchError,
253+
UpdatedAt: time.Now().UTC().Format(timeLayout),
254+
AttachmentID: update.AttachmentID,
255+
})
257256
}
258257

259258
func (s *Store) UpdateAttachmentFetchStatus(ctx context.Context, attachmentID, fetchedAt, status, message string) error {
260-
_, err := s.db.ExecContext(ctx, `
261-
update message_attachments
262-
set fetched_at = ?,
263-
fetch_status = ?,
264-
fetch_error = ?,
265-
updated_at = ?
266-
where attachment_id = ?
267-
`, nullable(fetchedAt), status, message, time.Now().UTC().Format(timeLayout), attachmentID)
268-
return err
259+
return s.q.UpdateAttachmentFetchStatus(ctx, storedb.UpdateAttachmentFetchStatusParams{
260+
FetchedAt: nullString(fetchedAt),
261+
FetchStatus: status,
262+
FetchError: message,
263+
UpdatedAt: time.Now().UTC().Format(timeLayout),
264+
AttachmentID: attachmentID,
265+
})
269266
}

internal/store/attachments_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func TestAttachmentMediaUpdatesAndFilters(t *testing.T) {
5656
FetchStatus: "fetched",
5757
}))
5858
require.NoError(t, s.UpdateAttachmentFetchStatus(ctx, "a2", "2026-05-15T12:06:00Z", "failed", "boom"))
59+
require.NoError(t, seedAttachmentForGuild(ctx, s, "g1", "c1", "m1", "a1"))
5960

6061
rows, err := s.ListAttachments(ctx, AttachmentListOptions{MissingOnly: true})
6162
require.NoError(t, err)

0 commit comments

Comments
 (0)