fix: remove single
check for rpc insert (#4812)
This commit is contained in:
parent
127b443f30
commit
5e990d569b
2 changed files with 34 additions and 14 deletions
|
@ -299,8 +299,6 @@ pub trait RpcContext {
|
||||||
let Ok((what, data)) = params.needs_two() else {
|
let Ok((what, data)) = params.needs_two() else {
|
||||||
return Err(RpcError::InvalidParams);
|
return Err(RpcError::InvalidParams);
|
||||||
};
|
};
|
||||||
// Return a single result?
|
|
||||||
let one = what.is_thing_single();
|
|
||||||
// Specify the SQL query string
|
// Specify the SQL query string
|
||||||
|
|
||||||
let mut res = match what {
|
let mut res = match what {
|
||||||
|
@ -323,11 +321,7 @@ pub trait RpcContext {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Extract the first query result
|
let res = res.remove(0).result?;
|
||||||
let res = match one {
|
|
||||||
true => res.remove(0).result?.first(),
|
|
||||||
false => res.remove(0).result?,
|
|
||||||
};
|
|
||||||
// Return the result to the client
|
// Return the result to the client
|
||||||
Ok(res.into())
|
Ok(res.into())
|
||||||
}
|
}
|
||||||
|
@ -337,8 +331,6 @@ pub trait RpcContext {
|
||||||
return Err(RpcError::InvalidParams);
|
return Err(RpcError::InvalidParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
let one = what.is_thing_single();
|
|
||||||
|
|
||||||
let mut res = match what {
|
let mut res = match what {
|
||||||
Value::None | Value::Null => {
|
Value::None | Value::Null => {
|
||||||
let sql = "INSERT RELATION $data RETURN AFTER";
|
let sql = "INSERT RELATION $data RETURN AFTER";
|
||||||
|
@ -360,10 +352,7 @@ pub trait RpcContext {
|
||||||
_ => return Err(RpcError::InvalidParams),
|
_ => return Err(RpcError::InvalidParams),
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = match one {
|
let res = res.remove(0).result?;
|
||||||
true => res.remove(0).result?.first(),
|
|
||||||
false => res.remove(0).result?,
|
|
||||||
};
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -348,13 +348,44 @@ async fn insert() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
assert_eq!(res.len(), 1, "result: {res:?}");
|
||||||
assert_eq!(res[0]["name"], "foo", "result: {res:?}");
|
assert_eq!(res[0]["name"], "foo", "result: {res:?}");
|
||||||
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
||||||
|
// Send INSERT command trying to create multiple records
|
||||||
|
let res = socket
|
||||||
|
.send_request(
|
||||||
|
"insert",
|
||||||
|
json!([
|
||||||
|
"tester",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "foo",
|
||||||
|
"value": "bar",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "foo",
|
||||||
|
"value": "bar",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
assert!(res.is_object(), "result: {res:?}");
|
||||||
|
assert!(res["result"].is_array(), "result: {res:?}");
|
||||||
|
let res = res["result"].as_array().unwrap();
|
||||||
|
assert_eq!(res.len(), 2, "result: {res:?}");
|
||||||
|
assert_eq!(res[0]["name"], "foo", "result: {res:?}");
|
||||||
|
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
||||||
|
assert_eq!(res[1]["name"], "foo", "result: {res:?}");
|
||||||
|
assert_eq!(res[1]["value"], "bar", "result: {res:?}");
|
||||||
// Verify the data was inserted and can be queried
|
// Verify the data was inserted and can be queried
|
||||||
let res = socket.send_message_query("SELECT * FROM tester").await?;
|
let res = socket.send_message_query("SELECT * FROM tester").await?;
|
||||||
assert!(res[0]["result"].is_array(), "result: {res:?}");
|
assert!(res[0]["result"].is_array(), "result: {res:?}");
|
||||||
let res = res[0]["result"].as_array().unwrap();
|
let res = res[0]["result"].as_array().unwrap();
|
||||||
assert_eq!(res.len(), 1, "result: {res:?}");
|
assert_eq!(res.len(), 3, "result: {res:?}");
|
||||||
assert_eq!(res[0]["name"], "foo", "result: {res:?}");
|
assert_eq!(res[0]["name"], "foo", "result: {res:?}");
|
||||||
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
assert_eq!(res[0]["value"], "bar", "result: {res:?}");
|
||||||
|
assert_eq!(res[1]["name"], "foo", "result: {res:?}");
|
||||||
|
assert_eq!(res[1]["value"], "bar", "result: {res:?}");
|
||||||
|
assert_eq!(res[2]["name"], "foo", "result: {res:?}");
|
||||||
|
assert_eq!(res[2]["value"], "bar", "result: {res:?}");
|
||||||
// Test passed
|
// Test passed
|
||||||
server.finish().unwrap();
|
server.finish().unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue