Skip to content

Commit 2a7561a

Browse files
authored
[#18] Properly pass ON CONFLICT column names through 'columnNameMapper' (#19)
1 parent aabf64d commit 2a7561a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

scalasql/query/src/OnConflict.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ object OnConflict {
2323
protected def expr = WithSqlExpr.get(query)
2424
private[scalasql] def renderSql(ctx: Context) = {
2525
val str = Renderable.renderSql(query)(ctx)
26-
str + sql" ON CONFLICT (${SqlStr.join(columns.map(c => SqlStr.raw(c.name)), SqlStr.commaSep)}) DO NOTHING"
26+
val columnsStr = SqlStr.join(
27+
columns.map(c => SqlStr.raw(ctx.config.columnNameMapper(c.name))),
28+
SqlStr.commaSep
29+
)
30+
str + sql" ON CONFLICT ($columnsStr) DO NOTHING"
2731
}
2832

2933
protected override def queryIsExecuteUpdate = true
@@ -43,9 +47,14 @@ object OnConflict {
4347
private[scalasql] def renderSql(ctx: Context) = {
4448
implicit val implicitCtx = Context.compute(ctx, Nil, Some(table))
4549
val str = Renderable.renderSql(query)
46-
val columnsStr = SqlStr.join(columns.map(c => SqlStr.raw(c.name)), SqlStr.commaSep)
50+
val columnsStr = SqlStr.join(
51+
columns.map(c => SqlStr.raw(ctx.config.columnNameMapper(c.name))),
52+
SqlStr.commaSep
53+
)
4754
val updatesStr = SqlStr.join(
48-
updates.map { case assign => SqlStr.raw(assign.column.name) + sql" = ${assign.value}" },
55+
updates.map { case assign =>
56+
SqlStr.raw(ctx.config.columnNameMapper(assign.column.name)) + sql" = ${assign.value}"
57+
},
4958
SqlStr.commaSep
5059
)
5160
str + sql" ON CONFLICT (${columnsStr}) DO UPDATE SET $updatesStr"

0 commit comments

Comments
 (0)