How to use variable in REMOVE statement #2905
-
Hi all, Am trying to play around few query statements in a rust project embedding surrealdb . While using REMOVE statement with table name as variable, I am encountering below error:
Following is the function:
However, when I am not trying to use any variable by hard coding the table name, the query works fine:
Am I missing something here? Thanks in advance. Pardon any silly error 🙇 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @plus1xp-everyday ! Unfortunately, our parser doesn't currently allow using variable bindings in some statements like we can use So that function can be written as async fn remove(db: &Surreal<Db>, table: &str) -> Result<()> {
let sql = format!("REMOVE TABLE {table}");
db.query(sql).await?.check()?;
Ok(())
} Another interesting option for Rust users only is to bypass the parser completely and pass in the remove statement directly:
This should be much faster because it bypasses the parser completely in both the client and the server. This option should be safer too if Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hey @plus1xp-everyday !
Unfortunately, our parser doesn't currently allow using variable bindings in some statements like
DEFINE
andREMOVE
, as in this case. We need to put that directly in the query itself. So instead oflet sql = "REMOVE TABLE $table";
we can use
let sql = format!("REMOVE TABLE {table}");
So that function can be written as
Another interesting option for Rust users only is to bypass the parser completely and pass in the remove statement directly: