Skip to content

Commit

Permalink
chore: fixing new expression
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonShin committed Aug 26, 2023
1 parent f036d35 commit 2d1d87a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/parser/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,15 @@ pub fn get_sql_from_expr<'a>(
}
Expr::Cond(_) => {}
Expr::New(expr) => {
let args = &expr.args;
let expr = &expr.callee;
return get_sql_from_expr(sqls, var_decl_name, expr, span, import_alias);
if let Some(args) = &args {
for arg in args {
get_sql_from_expr(sqls, var_decl_name, &arg.expr, span, import_alias);
}
}

get_sql_from_expr(sqls, var_decl_name, expr, span, import_alias);
}
Expr::Seq(seq) => {
let exprs = &seq.exprs;
Expand Down
1 change: 0 additions & 1 deletion tests/demo/typescript/expression/conditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ SELECT id FROM items
-- @name: falsy
SELECT id FROM items
`

15 changes: 15 additions & 0 deletions tests/demo/typescript/expression/new.queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


export type NewClassParams = [];


export interface INewClassResult {
id: number;
};


export interface INewClassQuery {
params: NewClassParams;
result: INewClassResult;
};

12 changes: 12 additions & 0 deletions tests/demo/typescript/expression/new.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { sql } from 'sqlx-ts'

class NewClass {
constructor(theQuery: string) {
console.log(theQuery)
}
}

const testInstance = new NewClass(sql`
-- @name: new class
SELECT id FROM items
`)

0 comments on commit 2d1d87a

Please sign in to comment.