import { QueryResult, QueryResultRow} from "pg"
import client from "./config"
export const execute = async <T>(
query: string,
prepared?: T[]
): Promise<{
data: QueryResult<T[]>
count: number | null
}> => {
try {
const pool = await client.connect()
const res: QueryResultRow = await pool.query(query, prepared)
pool.release()
return {
data: res.rows,
count: res.rowCount,
}
} catch (error: any) {
throw new Error(error)
}
}
this is my function I created to do queries
const result = <{ data: User }>(
(<unknown>(
await execute(`SELECT username, password FROM users WHERE username=$1`, [
username,
])
))
)
This is how I am using the function.
Is there anyway I can do this without using "unknown"?