大佬教程收集整理的这篇文章主要介绍了Graphql Mysql - 从 JSON 格式的表中获取行,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 TypeGraphQL 和 NodePOSTGRes 开发后端。 用户将传递数据库 ID 和表名。我需要以 JsON 格式发送数据。
我尝试了下面的代码,但它没有返回任何内容,也没有抛出任何错误。
服务:
import { service } from 'typedi'
import { ClIEnt } from 'pg'
import { databases } from './db'
import { Payload } from './models'
@service()
export class Payloadservice {
fetchPayload(ID: number,tablename: String): Payload {
const databaseCredentials = databases.find((d) => d.ID && +d.ID === ID)
if (!databaseCredentials) throw new Error('InvalID ID!')
const clIEnt = new ClIEnt({
host: databaseCredentials.host,port: +(databaseCredentials.port || 5432),user: databaseCredentials.username,password: databaseCredentials.password,database: databaseCredentials.database,ssl: {
rejectUnauthorized: false,},})
console.log('before clIEnt')
clIEnt.query("SELEct * from pg_tables where schemaname='public'",(err,res) => {
if (err) {
console.log(err.stack)
} else {
console.log(res.rows[0])
}
console.log(`callBACk`)
})
console.log('after clIEnt')
return {
ID,data: [],}
}
}
解析器:
import { Arg,query,Resolver } from 'type-graphql'
import { Inject } from 'typedi'
import { Payload } from './models'
import { Payloadservice } from './services'
@Resolver(Payload)
export class PayloadResolver {
@Inject()
private Payloadservice: Payloadservice
@query((returns) => Payload)
payload(@Arg('databasEID') databasEID: number,@Arg('tablename') tablename: String) {
return this.Payloadservice.fetchPayload(databasEID,tableName)
}
}
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的Graphql Mysql - 从 JSON 格式的表中获取行全部内容,希望文章能够帮你解决Graphql Mysql - 从 JSON 格式的表中获取行所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。