Skip to content

Commit e4262c9

Browse files
committed
fix(storage): persistir threadPosts en SQLite — columna threadPostsJson con migración automática
1 parent 2befb70 commit e4262c9

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/lib/storage/sqlite.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ interface SqlitePostRow {
2323
extractedText: string | null
2424
canonicalUrl: string | null
2525
mediaJson: string | null
26+
threadPostsJson: string | null
2627
}
2728

2829
interface SqliteCategoryRow {
@@ -76,6 +77,7 @@ export class SqliteStorage implements StorageAdapter {
7677
await this._ensureColumn('posts', 'extractedText', 'TEXT')
7778
await this._ensureColumn('posts', 'canonicalUrl', 'TEXT')
7879
await this._ensureColumn('posts', 'mediaJson', 'TEXT')
80+
await this._ensureColumn('posts', 'threadPostsJson', 'TEXT')
7981
await this._ensureColumn('categories', 'emoji', 'TEXT')
8082
await this._ensureColumn('categories', 'sortOrder', 'INTEGER NOT NULL DEFAULT 0')
8183
}
@@ -107,6 +109,15 @@ export class SqliteStorage implements StorageAdapter {
107109
}
108110
}
109111

112+
let threadPosts = undefined
113+
if (row.threadPostsJson) {
114+
try {
115+
threadPosts = JSON.parse(row.threadPostsJson)
116+
} catch {
117+
threadPosts = undefined
118+
}
119+
}
120+
110121
return {
111122
id: row.id,
112123
url: row.url,
@@ -120,6 +131,7 @@ export class SqliteStorage implements StorageAdapter {
120131
extractedText: row.extractedText ?? undefined,
121132
canonicalUrl: row.canonicalUrl ?? undefined,
122133
media,
134+
threadPosts,
123135
}
124136
}
125137

@@ -136,8 +148,8 @@ export class SqliteStorage implements StorageAdapter {
136148
async savePost(post: Post): Promise<void> {
137149
await this.db.execute(
138150
`INSERT OR REPLACE INTO posts
139-
(id, url, author, note, categoryId, savedAt, previewTitle, previewImage, previewVideo, extractedText, canonicalUrl, mediaJson)
140-
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)`,
151+
(id, url, author, note, categoryId, savedAt, previewTitle, previewImage, previewVideo, extractedText, canonicalUrl, mediaJson, threadPostsJson)
152+
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)`,
141153
[
142154
post.id,
143155
post.url,
@@ -151,6 +163,7 @@ export class SqliteStorage implements StorageAdapter {
151163
post.extractedText ?? null,
152164
post.canonicalUrl ?? null,
153165
post.media?.length ? JSON.stringify(post.media) : null,
166+
post.threadPosts?.length ? JSON.stringify(post.threadPosts) : null,
154167
]
155168
)
156169
}

0 commit comments

Comments
 (0)