deno_pg/index.js

25 lines
749 B
JavaScript

import { Client } from "https://deno.land/x/postgres/mod.ts";
//import { Client } from "https://raw.githubusercontent.com/snsinfu/deno-postgres/feat-scram/mod.ts";
import { config } from "https://deno.land/x/dotenv/mod.ts";
import CustomServer from "./server.tsx";
//load the .env file
const env = config();
const client = new Client({
user: env.DB_USER,
database: env.DB_DATABASE,
password: env.DB_PASSWORD,
hostname: env.DB_HOSTNAME,
port: env.DB_PORT,
});
await client.connect();
const sql = await Deno.readTextFile("get.sql");
const object_result = await client.queryObject(sql);
console.log(object_result.rows); // [{id: 1, name: 'Carlos'}, {id: 2, name: 'John'}, ...]
await client.end();
CustomServer(object_result.rows, 8085);