Skip to content

Commit

Permalink
Fixing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiehewitt15 committed Aug 8, 2024
1 parent 9329a7a commit 6eb4ec6
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/components/database/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { schemas, Schema } from './schemas.js'
import sqlite3 from 'sqlite3'

interface DatabaseProvider {
create(address: string, nonce: number): Promise<void>
retrieve(address: string): Promise<any>
update(address: string, nonce: number): Promise<void>
delete(address: string): Promise<void>
create(address: string, nonce: number): Promise<{ id: string; nonce: number }>
retrieve(address: string): Promise<{ id: string; nonce: number | null }>
update(address: string, nonce: number): Promise<{ id: string; nonce: number }>
delete(address: string): Promise<{ id: string; nonce: null }>
}

export class SQLiteProvider implements DatabaseProvider {
Expand Down Expand Up @@ -40,10 +40,10 @@ export class SQLiteProvider implements DatabaseProvider {
VALUES (?, ?)
ON CONFLICT(id) DO UPDATE SET nonce=excluded.nonce;
`
return new Promise<void>((resolve, reject) => {
return new Promise<{ id: string; nonce: number }>((resolve, reject) => {
this.db.run(insertSQL, [address, nonce], (err) => {
if (err) reject(err)
else resolve()
else resolve({ id: address, nonce })
})
})
}
Expand All @@ -53,10 +53,11 @@ export class SQLiteProvider implements DatabaseProvider {
const selectSQL = `
SELECT * FROM ${this.schema.name} WHERE id = ?
`
return new Promise<any>((resolve, reject) => {
this.db.get(selectSQL, [address], (err, row) => {
return new Promise<{ id: string; nonce: number | null }>((resolve, reject) => {
this.db.get(selectSQL, [address], (err, row: { nonce: number } | undefined) => {
if (err) reject(err)
else resolve(row)
else
resolve(row ? { id: address, nonce: row.nonce } : { id: address, nonce: null })
})
})
}
Expand All @@ -71,10 +72,10 @@ export class SQLiteProvider implements DatabaseProvider {
const deleteSQL = `
DELETE FROM ${this.schema.name} WHERE id = ?
`
return new Promise<void>((resolve, reject) => {
return new Promise<{ id: string; nonce: null }>((resolve, reject) => {
this.db.run(deleteSQL, [address], (err) => {
if (err) reject(err)
else resolve()
else resolve({ id: address, nonce: null })
})
})
}
Expand Down

0 comments on commit 6eb4ec6

Please sign in to comment.