Skip to content

Commit

Permalink
fix translate column name assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonShin committed Aug 4, 2024
1 parent aba41d8 commit 1bfcb74
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/ts_generator/sql_parser/expressions/translate_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ pub fn translate_column_name_assignment(assignment: &Assignment) -> Option<Strin
let right = assignment.id.get(1);

if left.is_some() && right.is_some() {
return right.map(|x| x.to_string());
return right.map(|ident| DisplayIndent(ident).to_string());
} else if left.is_some() && right.is_none() {
return left.map(|x| x.to_string());
return left.map(|ident| DisplayIndent(ident).to_string());
}
None
}
Expand Down
2 changes: 1 addition & 1 deletion src/ts_generator/sql_parser/quoted_strings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sqlparser::ast::{Ident, ObjectName, TableAlias};
use sqlparser::ast::{Assignment, Expr, Ident, ObjectName, TableAlias};
use std::fmt;
use std::fmt::{write, Formatter};

Expand Down
13 changes: 13 additions & 0 deletions tests/demo/update/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { sql } from 'sqlx-ts'

const updateQuery = sql`
UPDATE items
SET food_type = $1, time_takes_to_cook = $2
WHERE id = $3
`

const quotedUpdateQuery = sql`
UPDATE "items"
SET "food_type" = "$1", "time_takes_to_cook" = "$2"
WHERE "id" = $3
`

0 comments on commit 1bfcb74

Please sign in to comment.