Postgres关于邮差中使用 deno-postgres 的语句语法的错误
从速成课程创建一个 deno 应用程序 http 服务器,使用 Oak 和 deno-postgres 模块,我试图向 postgre 添加一些数据,一切正常,直到将数据发送到数据库。我在 Postman 中收到 500 间隔服务器错误:
发布请求后 Postman 中的 Json 响应:
{
"success": false,
"msg": "PostgresError: syntax error at or near 'table'"
}
我的代码:
import { Client } from "https://deno.land/x/[email protected]/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()
}
}
}
使用 eno-postgres 插入数据的语法是否正确?
我正在使用 [email protected] 和 Oak (https://deno.land/x/oak/mod.ts)
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/[email protected]/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 [email protected] and oak (https://deno.land/x/oak/mod.ts)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论