Ensure parameters can be used in RELATE statements without spaces
Closes #1447
This commit is contained in:
parent
a3d0f46994
commit
a9de682370
4 changed files with 50 additions and 3 deletions
|
@ -181,6 +181,12 @@ pub fn param(i: &str) -> IResult<&str, Idiom> {
|
|||
Ok((i, Idiom::from(v)))
|
||||
}
|
||||
|
||||
/// Used in a RELATE statement
|
||||
pub fn plain(i: &str) -> IResult<&str, Idiom> {
|
||||
let (i, p) = first(i)?;
|
||||
Ok((i, Idiom::from(vec![p])))
|
||||
}
|
||||
|
||||
pub fn idiom(i: &str) -> IResult<&str, Idiom> {
|
||||
alt((
|
||||
|i| {
|
||||
|
|
|
@ -86,9 +86,9 @@ pub fn param(i: &str) -> IResult<&str, Param> {
|
|||
Ok((i, Param::from(v)))
|
||||
}
|
||||
|
||||
pub fn basic(i: &str) -> IResult<&str, Param> {
|
||||
pub fn plain(i: &str) -> IResult<&str, Param> {
|
||||
let (i, _) = char('$')(i)?;
|
||||
let (i, v) = idiom::basic(i)?;
|
||||
let (i, v) = idiom::plain(i)?;
|
||||
Ok((i, Param::from(v)))
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::sql::comment::shouldbespace;
|
|||
use crate::sql::data::{data, Data};
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::output::{output, Output};
|
||||
use crate::sql::param::basic as param;
|
||||
use crate::sql::param::plain as param;
|
||||
use crate::sql::subquery::subquery;
|
||||
use crate::sql::table::{table, Table};
|
||||
use crate::sql::thing::thing;
|
||||
|
|
41
lib/tests/relate.rs
Normal file
41
lib/tests/relate.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
mod parse;
|
||||
use parse::Parse;
|
||||
use surrealdb::sql::Value;
|
||||
use surrealdb::Datastore;
|
||||
use surrealdb::Error;
|
||||
use surrealdb::Session;
|
||||
|
||||
#[tokio::test]
|
||||
async fn relate_with_parameters() -> Result<(), Error> {
|
||||
let sql = "
|
||||
LET $tobie = person:tobie;
|
||||
LET $jaime = person:jaime;
|
||||
RELATE $tobie->knows->$jaime SET id = knows:test;
|
||||
";
|
||||
let dbs = Datastore::new("memory").await?;
|
||||
let ses = Session::for_kv().with_ns("test").with_db("test");
|
||||
let res = &mut dbs.execute(&sql, &ses, None, false).await?;
|
||||
assert_eq!(res.len(), 3);
|
||||
//
|
||||
let tmp = res.remove(0).result?;
|
||||
let val = Value::None;
|
||||
assert_eq!(tmp, val);
|
||||
//
|
||||
let tmp = res.remove(0).result?;
|
||||
let val = Value::None;
|
||||
assert_eq!(tmp, val);
|
||||
//
|
||||
let tmp = res.remove(0).result?;
|
||||
let val = Value::parse(
|
||||
"[
|
||||
{
|
||||
id: knows:test,
|
||||
in: person:tobie,
|
||||
out: person:jaime,
|
||||
}
|
||||
]",
|
||||
);
|
||||
assert_eq!(tmp, val);
|
||||
//
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in a new issue