Creating a deno app http server from a crash course, with Oak and deno-postgres modules , i'm trying to add some data to postgre, everything works fine until send data to database. I get 500 interval server error in Postman :
Json response in Postman after post request:
{
"success": false,
"msg": "PostgresError: syntax error at or near 'table'"
}
my code :
import { Client } from "https://deno.land/x/postgres@v0.14.3/mod.ts";
import { dbCreds } from '../config.ts'
//deno run --allow-net --allow-read --allow-env server.ts
// Init client
const client = new Client(dbCreds)
const addProduct = async ({ request, response }: { request: any, response: any }) => {
const body = await request.body()
const product = body.value
if (!request.hasBody) {
response.status = 400
response.body = {
success: false,
msg: 'No data'
}
} else {
try {
await client.connect()
const result = await client.queryObject("INSERT INTO table (name,description,price) VALUES ($1,$2,$3);",
product.name,
product.description,
product.price)
response.status = 201
response.body = {
success: true,
data: product
}
} catch (err) {
response.status = 500
response.body = {
success: false,
msg: err.toString()
}
} finally {
await client.end()
}
}
}
Is it the right syntax to insert data with deno-postgres?
I'm using postgres@v0.14.3 and oak (https://deno.land/x/oak/mod.ts)