英文:
Generate sql statements with flyway placeholders
问题
我试图将一些 SQL 插入语句保存到文件中,以便在测试时使用。我想使用 flyway 占位符 来实现,但是我找不到任何相关信息。
以下是 Java 的一些示例代码:
var sqlTXT = sql.insertInto(table("TBLNAME"))
.set(field("strCol"), field("strVal").toString())
.set(field("placeHolderCol"), field(inline("${flyway:user}")))
.getSQL(ParamType.INLINED);
这将生成类似于以下 SQL 字符串:
insert into TBLNAME (strCol, placeHolderCol) values ('strVal', '${flyway:user}')
我希望得到类似这样的结果:
insert into TBLNAME (strCol, placeHolderCol) values ('strVal', ${flyway:user})
这样 Flyway 就可以替换 ${flyway:user}
并插入用户名。是否有办法实现这样的 SQL 渲染,还是我必须要进行"手动"处理?
英文:
I trying to save some sql insert statements to files to use them for testing.
I would like to use flyway placeholders for that but I'm not able to find any.
Some example in Java:
var sqlTXT = sql.insertInto(table("TBLNAME"))
.set(field("strCol"), field("strVal").toString())
.set(field("placeHolderCol"), field(inline("${flyway:user}")))
.getSQL(ParamType.INLINED);
This will produce SQL string like this one:
insert into TBLNAME (strCol, placeHolderCol) values ('strVal', '${flyway:user}')
and I'm looking for something like this
insert into TBLNAME (strCol, placeHolderCol) values ('strVal', ${flyway:user})
So flyway can substitute ${flyway:user}
and insert user name.
Is there any way to render sql like this or will I have to do it "manually"?
答案1
得分: 2
Flyway的占位符与任何其他“供应商特定”SQL语法没有区别,这种语法不能被jOOQ直接支持,所以纯SQL模板化是答案。
只需使用
field(" ${flyway:user}")
不要使用DSL.inline()
,该方法用于创建“内联值”(例如字符串文字)。
英文:
Flyway's placeholders are no different from any other "vendor specific" SQL syntax, which isn't supported out of the box by jOOQ, so plain SQL templating has the answer.
Just use
field("${flyway:user}")
Don't use DSL.inline()
, which is used for creating "inline values" (e.g. a string literal).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论