While using the Rust SDK for Surrealdb, where i don't know what i do different compared to the official documentation. Selecting all records from a table works fine, however selecting a specified record doesn't give me a result.
Working Example selecting all records in the table
here self.db is a Surreal<Client>:
pub async fn get_all_sensors(&self) -> Result<Vec<Sensor>, SDBError>{
let response_data: Result<Vec<Sensor>, surrealdb::Error> = self.db.select("sensor").await;
match response_data {
Ok(response_data) => Ok(response_data),
Err(_) => Err(SDBError)
}
}
which will give me the following result:
[
{
"uuid": "foo"
}
]
however trying to select only the "foo" entry like the following:
pub async fn get_sensor(&self, sensor: Sensor) -> Option<Sensor>{
let response: Result<Option<Sensor>, surrealdb::Error> = self.db.select(("sensor", "foo")).await;
match response {
Ok(output) => output,
Err(_) => None,
}
in Surrealist i can see that the entry also has the right "id".
{
"id": "sensor:foo",
"uuid": "foo"
}
Implementation is very similar to the Documentation: Surrealdb Rust SDK
Only difference is that i don't use the await? but awaitthen matching the Result manually.
Also tried out the version (for testing) with self.db.select("sensor", "foo").range((Bound::Included(""), Bound::Exluded("foo")).await.unwrap() as they have done it in their tests Surrealdb Github Test on Line 131.
One difference that I can see is that they use a Lazy<Surreal<Client>> but I don't see that as the problem.
I tried to reproduce your example as closely as possible but I can't get the same result. I first created the record using
and then ran the following code
This prints
In my case both the
surrealdbcrate and server are onv1.0.0. Which versions are you using for both?self.db.select("sensor", "foo")shouldn't compile. That method only takes one argument..range((Bound::Included(""), Bound::Exluded("foo"))tells the database to return all records whoseidstarts from""up to but not including"foo", sorted byid. This can be written simply as.range("".."foo"). As you may expect, this method only works with queries that return multiple results. If you try to use it with something that fetches a specific record likedb.select(("sensor", "foo"))you will get an error.