commit ff8694a9cc4a95475c6ef3b2835860fc50f74b43 Author: Paul Trowbridge Date: Sat Mar 26 00:34:22 2022 -0400 squash history diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..0e30fe1 --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +DB_USER= +DB_DATABASE= +DB_PASSWORD= +DB_HOSTNAME= +DB_PORT= diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..200bf3d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.swp +.env diff --git a/get.sql b/get.sql new file mode 100644 index 0000000..d433e87 --- /dev/null +++ b/get.sql @@ -0,0 +1,9 @@ +SELECT + "Description" descr + ,"Amount" amount + ,id +FROM + tpsv.dcard_mapped +ORDER BY + "Trans. Date" Desc + ,id Desc diff --git a/index.js b/index.js new file mode 100644 index 0000000..1e3993b --- /dev/null +++ b/index.js @@ -0,0 +1,24 @@ +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); diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..bc960d4 --- /dev/null +++ b/readme.md @@ -0,0 +1,10 @@ +sometimes you need to run `deno cache -r index.js` due to stale code sitting in the cache. +The database uses a cert to encrypt traffic. if the cert is expired it will need dealt with. + +otherwise... +* install deno + * curl -fsSL https://deno.land/x/install/install.sh | sh + * copy the .bashrc stuff per the instructions at the end of the install + * exec bash to use the .bashrc changes +* copy `.env.example` to `.env` and update the parameters in it +* run `deno run --allow-read --allow-net --unstable --allow-env index.js` diff --git a/scripts.yaml b/scripts.yaml new file mode 100644 index 0000000..5fab0e0 --- /dev/null +++ b/scripts.yaml @@ -0,0 +1,4 @@ +# 1.) "install" velociraptor 'deno install -qA -n vr https://deno.land/x/velociraptor@1.0.0-beta.16/cli.ts' +# 2.) run script from this yaml in terminal 'vr dev' +scripts: + dev: "deno run -A --watch --unstable index.js" \ No newline at end of file diff --git a/server.tsx b/server.tsx new file mode 100644 index 0000000..5b4f806 --- /dev/null +++ b/server.tsx @@ -0,0 +1,91 @@ +//// "Oak" server +import { Application, Router } from "https://deno.land/x/oak/mod.ts"; + +//// "React" stuff +// @deno-types="https://deno.land/x/servest/types/react/index.d.ts" +import React from "https://dev.jspm.io/react/index.js"; +// @deno-types="https://deno.land/x/servest/types/react-dom/server/index.d.ts" +import ReactDOMServer from "https://dev.jspm.io/react-dom/server.js"; + +//attemp conversion to a table + +const CustomItemList = (props: any) => { + return ( +
+

Items

+

{props.items.length} total

+ + + + + + + + + {props.items.map((inItem: any) => { + return ( + + ); + })} +
DescritpionAmountLog ID
+
+ ); +}; + +const CustomItem = (props: any) => { + return ( + + {props.description} + {props.amount} + {props.id} + + + ); +}; + +/* +const CustomItem = (props: any) => { + return ( +
+
+ Description: {props.description} +
+
+ Amount: {props.amount} +
+
+ Key: {props.id} +
+
+ ); +}; +*/ + +export default (inState: any, inPort: number) => { + let app, router; + let state: any; + + router = new Router(); + router.get("/api/all", (ctx: any) => { + ctx.response.body = JSON.stringify(inState); + }); + router.get("/", (ctx: any) => { + ctx.response.body = ReactDOMServer.renderToString( + + + +

Welcome!

+ + + + ); + }); + app = new Application(); + app.use(router.routes()); + app.listen({ port: inPort }); +};