Created
October 5, 2023 18:20
-
-
Save sbatururimi/2ab8921ff7e0d205bd44b857dd30a81f to your computer and use it in GitHub Desktop.
problematic_supabase_num_type.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`amount` is of type: float4 | |
``` | |
import { Pool } from 'https://deno.land/x/[email protected]/mod.ts'; | |
export async function getDBPool() { | |
const POOL_CONNECTIONS = 20; | |
const dbPool = new Pool( | |
{ | |
tls: { enabled: false }, | |
// tls: { caCertificates: [Deno.env.get("DB_SSL_CERT")!] }, | |
user: Deno.env.get('USER_POSTGRES') ?? '', | |
database: Deno.env.get('DB_POSTGRES') ?? '', | |
hostname: Deno.env.get('HOSTNAME_POSTGRES') ?? '', | |
password: Deno.env.get('PASSWORD_POSTGRES') ?? '', | |
port: Deno.env.get('PORT_POSTGRES') ?? '', | |
}, | |
POOL_CONNECTIONS, | |
true, | |
); | |
return dbPool; | |
} | |
export async function runQuery(pool: Pool, query: string) { | |
const client = await pool.connect(); | |
let result; | |
try { | |
result = await client.queryObject(query); | |
} catch (e) { | |
console.log(e); | |
} finally { | |
client.release(); | |
} | |
return result; | |
} | |
``` | |
``` | |
const dbPool = await getDBPool(); | |
let query = ` | |
SELECT | |
tr.created_at, | |
tr.id, | |
tr.amount, | |
FROM transactions AS tr | |
`; | |
const op = await runQuery(dbPool, query); | |
if (op.rows.length != 1) { | |
throw new Error('Wrong request'); | |
} | |
const old_income: Income = op.rows[0]; | |
old_income.amount = parseFloat(old_income.amount); | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment