Comments (4)
Could you please explain the idea a little bit, or give an example? I have no idea what the proposed trait is used for.
from arangors.
Yes, sorry, I have written this with my phone.
Here is an example:
trait DbClient {
async fn aql_query<R>(&self, aql: AqlQuery<'_>) -> Result<Vec<R>, ClientError>
where R: DeserializeOwned + Send;
}
impl<T> DbClient for Database<T>
where T: ClientExt + Send {
async fn aql_query<R>(&self, aql: AqlQuery<'_>) -> Result<Vec<R>, ClientError>
where R: DeserializeOwned + Send {
self.aql_query(aql).await
}
}
impl<T> DbClient for Transaction<T>
where T: ClientExt + Send {
async fn aql_query<R>(&self, aql: AqlQuery<'_>) -> Result<Vec<R>, ClientError>
where R: DeserializeOwned + Send {
self.aql_query(aql).await
}
}
impl<T> UserDAO for T
where T: DbClient + Send + Sync{
async fn add_user(&self, user: User) -> Result<User, DAOError> {
let json = serde_json::value::to_value(&user).unwrap();
let aql = AqlQuery::builder()
.query(r#"
INSERT @user INTO @@collection
LET result = NEW
RETURN {_id:result._id, _key:result._key, _rev:result._rev}
"#)
.bind_var("user", json)
.bind_var("@collection", USERS_COLLECTION)
.build();
let resp: Vec<DocumentHeader> = db.aql_query(aql).await?;
if let Some(header) = resp.into_iter().next() {
user.document_header = Some(header);
return Ok(user);
}
Err("Response was empty".into())
}
}
As you can see, I can now use my add_user function on Database struct and Transaction struct.
Maybe there is an other way to do it but I did not find any better way.
from arangors.
?
from arangors.
Related Issues (20)
- arangors::Connexion problem
- rust web development HOT 1
- User Management HOT 2
- reqwest + rustls HOT 6
- Release: new version with transactions, analyzers and views? HOT 2
- Example dependency using the blocking feature in README.md is wrong. HOT 1
- Transaction support improvements
- Error Improvements HOT 1
- Improve error message when credentials for connection are wrong HOT 5
- Make fields on `InsertOption`, `UpdateOption`, etc public HOT 3
- reqwest 0.11 breaks tokio dependencies HOT 4
- Is this project unmaintained? HOT 3
- Make Document and Header derive Clone HOT 2
- Unit test failing on AqlQueryBuilder HOT 5
- rustls features don't work
- arangors 0.5.0 phantom compile errors HOT 11
- Are bind parameters passed on to HTTP API? HOT 3
- save and update views HOT 1
- support pipeline analyzer HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arangors.