任何人都知道像Squiggle这样的一些优秀的SQL构建器库(似乎不再维护).优选地,正在积极开发的项目.
最好使用类似Zend_Db_Select的语法,这样可以进行类似的查询
String query = db.select().from('products').order('product_id');
Run Code Online (Sandbox Code Playgroud) 我试图使用querydsl为动态模式构建动态查询.我试图获得只是查询而不必实际执行它.
到目前为止,我遇到了两个问题: - schema.table符号不存在.相反,我只得到表名. - 我已经能够得到查询,但它将变量分开并放入'?' 相反,这是可以理解的.但我想知道是否有某种方法可以获得完全具体化的查询,包括参数.
这是我当前的尝试和结果(我使用MySQLTemplates来创建配置):
private SQLTemplates templates = new MySQLTemplates();
private Configuration configuration = new Configuration(templates);
String table = "sometable"
Path<Object> userPath = new PathImpl<Object>(Object.class, table);
StringPath usernamePath = Expressions.stringPath(userPath, "username");
NumberPath<Long> idPath = Expressions.numberPath(Long.class, userPath, "id");
SQLQuery sqlQuery = new SQLQuery(connection, configuration)
.from(userPath).where(idPath.eq(1l)).limit(10);
String query = sqlQuery.getSQL(usernamePath).getSQL();
return query;
Run Code Online (Sandbox Code Playgroud)
而我得到的是:
select sometable.username
from sometable
where sometable.id = ?
limit ?
Run Code Online (Sandbox Code Playgroud)
我想得到的是:
select sometable.username
from someschema.sometable
where sometable.id = ?
limit ?
Run Code Online (Sandbox Code Playgroud)
更新:我想出了这种黑客来获取参数实现(不理想,并希望更好的解决方案)但仍然 …