且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PL/PostgreSQL 如何将变量转换为表名

更新时间:2022-12-04 21:43:49

经过几个小时的尝试,多亏了 Adrian 的评论,我发现 MassiveJS(我如何连接到我的 PostgreSQL 服务器)有 内联函数进行查询.在我的服务器中的控制器文件中,我能够创建一个这样的单行函数:

After many hours of trying to figure it out, thanks to Adrian's comment, I found MassiveJS (how I'm connecting to my PostgreSQL server) has inline functions to do queries. In my controller file in my server I was able to create a one line function as such:

const data = await db[tableName].where("user_id=$1", [userId])

不知道 MassiveJS 中存在内联 SQL,所以发现它很棒!

Didn't know inline SQL existed in MassiveJS, so that was great to find out!