2022-11-15 14:07:17 +00:00
|
|
|
import { QuickSQLiteConnection } from 'react-native-quick-sqlite'
|
2022-10-31 00:37:42 +00:00
|
|
|
import { getItems } from '..'
|
2022-10-24 17:27:31 +00:00
|
|
|
|
|
|
|
export interface Relay {
|
2022-10-31 00:37:42 +00:00
|
|
|
url: string
|
|
|
|
name?: string
|
2022-10-24 17:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const databaseToEntity: (object: any) => Relay = (object) => {
|
2022-10-31 00:37:42 +00:00
|
|
|
return object as Relay
|
|
|
|
}
|
2022-10-24 17:27:31 +00:00
|
|
|
|
2022-11-04 14:01:02 +00:00
|
|
|
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
|
2022-10-31 00:37:42 +00:00
|
|
|
}
|
2022-10-24 17:27:31 +00:00
|
|
|
|
2022-11-04 14:01:02 +00:00
|
|
|
export const getRelays: (db: QuickSQLiteConnection) => Promise<Relay[]> = async (db) => {
|
2022-10-31 00:37:42 +00:00
|
|
|
const notesQuery = 'SELECT * FROM nostros_relays;'
|
2022-11-04 14:01:02 +00:00
|
|
|
const resultSet = await db.execute(notesQuery)
|
|
|
|
const items: object[] = getItems(resultSet)
|
|
|
|
const relays: Relay[] = items.map((object) => databaseToEntity(object))
|
|
|
|
return relays
|
2022-10-31 00:37:42 +00:00
|
|
|
}
|