use single row for cursor

This commit is contained in:
Hailey
2025-09-01 10:07:50 -07:00
parent 6d73e3ed3c
commit 4da6bd5b95
3 changed files with 10 additions and 8 deletions
+5 -3
View File
@@ -227,8 +227,7 @@ export class SafelinkClient {
const res = await this.db.db
.selectFrom('safelink_cursor')
.selectAll()
.orderBy('createdAt', 'desc')
.limit(1)
.where('id', '=', 1)
.executeTakeFirst()
if (!res) {
return ''
@@ -239,13 +238,16 @@ export class SafelinkClient {
}
private async setCursor(cursor: string) {
const updatedAt = new Date()
try {
await this.db.db
.insertInto('safelink_cursor')
.values({
id: 1,
cursor,
createdAt: new Date(),
updatedAt,
})
.onConflict(oc => oc.column('id').doUpdateSet({cursor, updatedAt}))
.execute()
this.cursor = cursor
} catch (err) {
+2 -2
View File
@@ -16,9 +16,9 @@ export async function up(db: Kysely<unknown>): Promise<void> {
await db.schema
.createTable('safelink_cursor')
.addColumn('id', 'bigserial', col => col.primaryKey())
.addColumn('id', 'bigserial', col => col.notNull())
.addColumn('cursor', 'varchar', col => col.notNull())
.addColumn('createdAt', 'timestamptz', col => col.notNull())
.addColumn('updatedAt', 'timestamptz', col => col.notNull())
.execute()
await db.schema
+3 -3
View File
@@ -1,4 +1,4 @@
import {type GeneratedAlways, type Selectable} from 'kysely'
import {type Selectable} from 'kysely'
export type DbSchema = {
link: Link
@@ -43,9 +43,9 @@ export interface SafelinkRule {
}
export interface SafelinkCursor {
id: GeneratedAlways<number>
id: number
cursor: string
createdAt: Date
updatedAt: Date
}
export type LinkEntry = Selectable<Link>