mirror of
https://github.com/KoalaSat/nostros.git
synced 2024-09-29 14:40:43 +00:00
31 lines
967 B
TypeScript
31 lines
967 B
TypeScript
import { QuickSQLiteConnection } from 'react-native-quick-sqlite'
|
|
import { getItems } from '..'
|
|
|
|
export interface Relay {
|
|
url: string
|
|
name?: string
|
|
}
|
|
|
|
const databaseToEntity: (object: any) => Relay = (object) => {
|
|
return object as Relay
|
|
}
|
|
|
|
export const searchRelays: (
|
|
relayUrl: string,
|
|
db: QuickSQLiteConnection,
|
|
) => Promise<Relay[]> = async (relayUrl, db) => {
|
|
const searchQuery = `SELECT * FROM nostros_relays WHERE url = '${relayUrl}';`
|
|
const results = await db.execute(searchQuery)
|
|
const items: object[] = getItems(results)
|
|
const notes: Relay[] = items.map((object) => databaseToEntity(object))
|
|
return notes
|
|
}
|
|
|
|
export const getRelays: (db: QuickSQLiteConnection) => Promise<Relay[]> = async (db) => {
|
|
const notesQuery = 'SELECT * FROM nostros_relays;'
|
|
const resultSet = await db.execute(notesQuery)
|
|
const items: object[] = getItems(resultSet)
|
|
const relays: Relay[] = items.map((object) => databaseToEntity(object))
|
|
return relays
|
|
}
|