go - 使用可选查询参数构造 SQL 查询
问题描述
我正在尝试针对来自端点的可选查询参数构建一个 sql 查询。
例如我有一个网址 http://localhost/api?one=1
现在形成上面的 url,我需要构建类似 .. 的查询
SELECT DISTINCT tb_one.id as id, tb_one.title as title from tb_one
JOIN
tb_one ON tb_main.id = tb_one.id
where other_id in (1) and tb_one.id in (2)
还有例如我有一个网址 http://localhost/api?one=1&two=1
SELECT DISTINCT tb_one.id as id, tb_one.title as title from tb_one
JOIN
tb_one ON tb_main.id = tb_one.id
JOIN
tb_two ON tb_main.id = tb_wo.id
where other_id in (1)
它可以是具有不同组合的 n 个参数。
我们可以在 Go 中构造这样的查询吗?
解决方案
推荐阅读
- javascript - 表格中的进度条
- python - 使用 tweepy 和情绪分析的流式推文问题
- c# - 需要显示存储在 AspNetUser 表中的某些值
- jquery - Jssor 完全适合 div 中的图像
- typescript - 来自对象属性的动态 Typescript 函数参数
- netsuite - 批量解锁 Netsuite 记录
- linkedin - 什么 API 方法可用于获取所有最新的 LinkedIn 帖子?
- javascript - 无法读取属性“addEventListener”
- netflix-eureka - 遵循 Eureka API 文档注册非 Java 应用程序 - 问题
- javascript - 如何进一步破坏所有以父类开头的变量集?