use single row for cursor
This commit is contained in:
Vendored
+5
-3
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user