Skip to content

Commit

Permalink
doc: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
fMeow committed Jun 6, 2024
1 parent af85fe5 commit 94f1902
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 62 deletions.
117 changes: 58 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,16 @@ HTTP headers.
Hierarchy of arangors:
> connection -> databases -> collections -> documents/edges
## Features

By now, the available features of arangors are:

- make connection to ArangoDB
- get list of databases and collections
- fetch database and collection info
- create and delete database or collections
- full featured AQL query
- support both `async` and sync

## Abilities & TODO
## Features & TODO

- [X] make connection to ArangoDB
- [X] get list of databases and collections
- [X] fetch database and collection info
- [X] create and delete database or collections
- [X] full featured AQL query
- [X] Synchronous connection based on `reqwest` and full featured AQL query.
- [X] Fill the unimplemented API in `Connection`, `Database`, `Collection` and
`Document`.
- [X] Implement both sync and async client.
- [X] Fill the unimplemented API in `Connection`, `Database`, `Collection` and `Document`.
- [X] support both `async` and sync client
- [X] Offers a way to use custom HTTP client ecosystem.
- [X] Index Management (since 0.4.3)
- [X] Graph Management (since 0.4.5)
Expand All @@ -61,6 +54,7 @@ You can switch to different HTTP ecosystem with a feature gate, or implement
the Client yourself (see examples).

Currently out-of-box supported ecosystem are:

- `reqwest_async`
- `reqwest_blocking`
- `surf_async`
Expand Down Expand Up @@ -91,6 +85,7 @@ with a feature gate. Arangors adopts async first policy.
### Connection

There is three way to establish connections:

- jwt
- basic auth
- no authentication
Expand All @@ -106,22 +101,26 @@ use arangors::Connection;

// (Recommended) Handy functions
let conn = Connection::establish_jwt("http://localhost:8529", "username", "password")
.await
.unwrap();
.await
.unwrap();
let conn = Connection::establish_basic_auth("http://localhost:8529", "username", "password")
.await
.unwrap();
.await
.unwrap();
```

- Without authentication, only use in evaluation setting
- Without authentication

**Only use in evaluation setting**.

``` rust, ignore
## use arangors::Connection;
use arangors::Connection;
let conn = Connection::establish_without_auth("http://localhost:8529").await.unwrap();
```rust
```

## Database && Collection

To get info or operate on database or collections:

```rust
use arangors::Connection;

Expand All @@ -131,7 +130,8 @@ let collection = db.collection("test_collection").await.unwrap();

### AQL Query

All [AQL](https://www.arangodb.com/docs/stable/aql/index.html) query related functions are associated with database, as AQL query
All [AQL](https://www.arangodb.com/docs/stable/aql/index.html) query related functions are associated with database, as
AQL query
is performed at database level.

There are several way to execute AQL query, and can be categorized into two
Expand Down Expand Up @@ -165,14 +165,14 @@ struct User {

// Typed
let resp: Vec<User> = db
.aql_str("FOR u IN test_collection RETURN u")
.await
.unwrap();
.aql_str("FOR u IN test_collection RETURN u")
.await
.unwrap();
// Not typed: Arbitrary JSON objects
let resp: Vec<serde_json::Value> = db
.aql_str("FOR u IN test_collection RETURN u")
.await
.unwrap();
.aql_str("FOR u IN test_collection RETURN u")
.await
.unwrap();
```

#### Batch query
Expand All @@ -184,13 +184,12 @@ next batch and update cursor with the cursor.

```rust


let aql = AqlQuery::builder()
.query("FOR u IN @@collection LIMIT 3 RETURN u")
.bind_var("@collection", "test_collection")
.batch_size(1)
.count(true)
.build();
.query("FOR u IN @@collection LIMIT 3 RETURN u")
.bind_var("@collection", "test_collection")
.batch_size(1)
.count(true)
.build();

// fetch the first cursor
let mut cursor = db.aql_query_batch(aql).await.unwrap();
Expand All @@ -199,15 +198,15 @@ println!("count: {:?}", cursor.count);
println!("cached: {}", cursor.cached);
let mut results: Vec<serde_json::Value> = Vec::new();
loop {
if cursor.more {
let id = cursor.id.unwrap().clone();
// save data
results.extend(cursor.result.into_iter());
// update cursor
cursor = db.aql_next_batch(id.as_str()).await.unwrap();
} else {
break;
}
if cursor.more {
let id = cursor.id.unwrap().clone();
// save data
results.extend(cursor.result.into_iter());
// update cursor
cursor = db.aql_next_batch(id.as_str()).await.unwrap();
} else {
break;
}
}
println!("{:?}", results);
```
Expand Down Expand Up @@ -235,9 +234,9 @@ struct User {
}

let result: Vec<User> = db
.aql_str(r#"FOR i in test_collection FILTER i.username=="test2" return i"#)
.await
.unwrap();
.aql_str(r#"FOR i in test_collection FILTER i.username=="test2" return i"#)
.await
.unwrap();
```

##### `aql_bind_vars`
Expand All @@ -256,14 +255,14 @@ struct User {

let mut vars = HashMap::new();
let user = User {
username: "test".to_string(),
password: "test_pwd".to_string(),
username: "test".to_string(),
password: "test_pwd".to_string(),
};
vars.insert("user", serde_json::value::to_value(&user).unwrap());
let result: Vec<Document<User>> = db
.aql_bind_vars(r#"FOR i in test_collection FILTER i==@user return i"#, vars)
.await
.unwrap();
vars.insert("user", serde_json::value::to_value( & user).unwrap());
let result: Vec<Document<User> > = db
.aql_bind_vars(r#"FOR i in test_collection FILTER i==@user return i"#, vars)
.await
.unwrap();
```

##### `aql_query`
Expand All @@ -280,11 +279,11 @@ use serde_json::value::Value;


let aql = AqlQuery::builder()
.query("FOR u IN @@collection LIMIT 3 RETURN u")
.bind_var("@collection", "test_collection")
.batch_size(1)
.count(true)
.build();
.query("FOR u IN @@collection LIMIT 3 RETURN u")
.bind_var("@collection", "test_collection")
.batch_size(1)
.count(true)
.build();

let resp: Vec<Value> = db.aql_query(aql).await.unwrap();
println!("{:?}", resp);
Expand Down
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,19 @@
//! # }
//! ```
//!
//! - Without authentication, only use in evaluation setting
//! - Without authentication
//!
//! **Only use in evaluation setting**.
//!
//! ``` rust, ignore
//! # use arangors::Connection;
//! use arangors::Connection;
//! let conn = Connection::establish_without_auth("http://localhost:8529").await.unwrap();
//! ```
//!
//! ## Database && Collection
//!
//! To get info or operate on database or collections:
//!
//! ```rust
//! use arangors::Connection;
//!
Expand Down Expand Up @@ -206,7 +210,6 @@
//! # .await
//! # .unwrap();
//! # let db = conn.db("test_db").await.unwrap();
//!
//! let aql = AqlQuery::builder()
//! .query("FOR u IN @@collection LIMIT 3 RETURN u")
//! .bind_var("@collection", "test_collection")
Expand Down

0 comments on commit 94f1902

Please sign in to comment.