JasonShin / sqlx-ts

node.js compile-time SQL validations & type generations
https://jasonshin.github.io/sqlx-ts/
MIT License
151 stars 6 forks source link

Failed toe find the column from the table schema of "\"user\"" #134

Open simplenotezy opened 6 days ago

simplenotezy commented 6 days ago

I am getting the following error:

Failed toe find the column from the table schema of "\"user\""

With the following query:

    const getUserQuery = await this.client.query({
      text: sql`SELECT * FROM "user" WHERE id = $1`,
      values: [id],
    });

Full stack trace:

[INFO] Scanning "./src" for SQLs with extension Ts
thread 'main' panicked at src/ts_generator/sql_parser/expressions/translate_expr.rs:133:36:
Failed toe find the column from the table schema of "\"user\""
stack backtrace:
   0:        0x104a75b64 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1f3776e0b5c7517d
   1:        0x104a94ef0 - core::fmt::write::heedef092c8c0962e
   2:        0x104a72850 - std::io::Write::write_fmt::h7178e8e2ea928914
   3:        0x104a759bc - std::sys_common::backtrace::print::h417292deb95532ed
   4:        0x104a76b18 - std::panicking::default_hook::{{closure}}::h0cb68f1228c4613a
   5:        0x104a7680c - std::panicking::default_hook::h24535936bc1f51de
   6:        0x104a773d0 - std::panicking::rust_panic_with_hook::h5db4d2345b297bed
   7:        0x104a76e00 - std::panicking::begin_panic_handler::{{closure}}::h3fd558f09a0d5492
   8:        0x104a75fec - std::sys_common::backtrace::__rust_end_short_backtrace::hfc76eebe1ce501b2
   9:        0x104a76b70 - _rust_begin_unwind
  10:        0x104ab81d0 - core::panicking::panic_fmt::hc2b459a5bd3dce66
  11:        0x1045c87d8 - sqlx_ts::ts_generator::sql_parser::expressions::translate_expr::get_sql_query_param::{{closure}}::h1896019f709491df
  12:        0x1045cc70c - sqlx_ts::ts_generator::sql_parser::expressions::translate_expr::translate_expr::{{closure}}::h8167647399229f64
  13:        0x1046b9f24 - sqlx_ts::ts_generator::sql_parser::translate_query::translate_query::{{closure}}::hbb13567b6f258221
  14:        0x1046bb2bc - sqlx_ts::ts_generator::sql_parser::translate_stmt::translate_stmt::{{closure}}::hb018146488cc502c
  15:        0x1046b5e3c - sqlx_ts::ts_generator::generator::generate_ts_interface::{{closure}}::h0437b2601b8838b8
  16:        0x1046c0554 - sqlx_ts::main::{{closure}}::hdfdc8c390af37a65
  17:        0x1046ad694 - tokio::runtime::park::CachedParkThread::block_on::hfff00a85b0473a50
  18:        0x104688028 - tokio::runtime::context::runtime::enter_runtime::h7ca324ddb8c44e99
  19:        0x104619b0c - tokio::runtime::runtime::Runtime::block_on::h04bf0b47b449c7d4
  20:        0x10464f9ec - sqlx_ts::main::he63bae760152502e
  21:        0x1046996c4 - std::sys_common::backtrace::__rust_begin_short_backtrace::heca7c122cd8ebc36
  22:        0x1046034ac - std::rt::lang_start::{{closure}}::h889d2a596bb18acf
  23:        0x104a6d484 - std::rt::lang_start_internal::hecc68fef83c8f44d
  24:        0x10464faf4 - _main
simplenotezy commented 6 days ago

Casting to uuid fixes the issue:

+SELECT * FROM "user" WHERE id::uuid = $1
-SELECT * FROM "user" WHERE id = $1
JasonShin commented 6 days ago

hello, thanks for this.

I am seeing the problem when the table name is provided with ". This is a valid syntax in SQL, but when the parser retrieves the table name, it is using a key \"user\", but it should be user.

Could you try removing the double quotes " for the time being?

The fix will be tracked here https://github.com/JasonShin/sqlx-ts/pull/135