60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import { Application, Router } from 'https://deno.land/x/oak/mod.ts';
|
|
import { Client } from "https://deno.land/x/postgres@v0.17.0/mod.ts";
|
|
import { load } from "https://deno.land/std/dotenv/mod.ts";
|
|
|
|
const app = new Application();
|
|
const router = new Router();
|
|
|
|
const env = await load();
|
|
const hostname = env["HOSTNAME"];
|
|
const port = env["PORT"];
|
|
const user = env["USER"];
|
|
const password = env["PASSWORD"];
|
|
const database = env["DATABASE"];
|
|
const app_port = env["APP_PORT"];
|
|
|
|
// Configure database connection
|
|
const client = new Client({
|
|
hostname:hostname
|
|
,port: port
|
|
,user: user
|
|
,password:password
|
|
,database:database
|
|
});
|
|
|
|
await client.connect();
|
|
|
|
// Load SQL from file
|
|
const query = await Deno.readTextFile("sql/write_note.sql");
|
|
|
|
// Define a route to retrieve values from the database using parameters
|
|
router.get('/sales_walk/write_note/:ship_cust/:bucket/:notes', async (ctx) => {
|
|
|
|
const bucket = ctx.params.bucket; // Extract the bucket parameter from the route
|
|
const notes = ctx.params.notes; // Extract the bucket parameter from the route
|
|
const ship_cust = ctx.params.ship_cust; // Extract the ship_cust parameter from the route
|
|
|
|
//console.log(bucket)
|
|
//console.log(ship_cust)
|
|
|
|
const result = await client.queryObject({args: [ship_cust, bucket, notes], text: query} );
|
|
|
|
|
|
const currentTime = Date.now();
|
|
const dateObject = new Date(currentTime);
|
|
const currentDateTime = dateObject.toLocaleString(); //Output: 2/20/2023, 7:41:42 AM
|
|
console.log("posted: ", currentDateTime);
|
|
|
|
//ctx.response.body = result.rows;
|
|
ctx.response.body = currentDateTime;
|
|
|
|
});
|
|
|
|
app.use(router.routes());
|
|
app.use(router.allowedMethods());
|
|
|
|
// Start the server
|
|
console.log('Server is running on http://localhost:8085');
|
|
await app.listen({ port: 8085 });
|
|
|