Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jnsougata/deta.rs
Rust bindings for the Deta Base and Drive HTTP API
https://github.com/jnsougata/deta.rs
deta rust
Last synced: 17 days ago
JSON representation
Rust bindings for the Deta Base and Drive HTTP API
- Host: GitHub
- URL: https://github.com/jnsougata/deta.rs
- Owner: jnsougata
- License: mit
- Created: 2022-12-16T23:29:41.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-15T11:38:25.000Z (5 months ago)
- Last Synced: 2024-10-12T20:06:24.338Z (about 1 month ago)
- Topics: deta, rust
- Language: Rust
- Homepage: https://crates.io/crates/detalib
- Size: 55.7 KB
- Stars: 10
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# deta.rs
Rust bindings for the Deta **Base** and **Drive** [HTTP API](https://deta.space/docs/en/build/reference/http-api#content)## Installation
```shell
cargo add detalib
```## Quickstart
```rust
use detalib::{ Deta, Operation, Operator };
use serde::{ Deserialize, Serialize };
use serde_json::{ Number, Value };#[derive(Serialize, Deserialize)]
struct User {
key: String,
name: String,
age: u8,
}fn main() {
let deta = Deta::new("project_key");
let base = deta.base("base_name");
let drive = deta.drive("drive_name");
let user = User {
key: "user_1".to_string(),
name: "John".to_string(),
age: 20,
};///////////////////////////////////
// BASE Methods //
//////////////////////////////////
// Insert a record
_ = base.insert(&user).unwrap();// Put multiple records
let users = vec![
User {
key: "user_1".to_string(),
name: "John".to_string(),
age: 20,
},
User {
key: "user_2".to_string(),
name: "Jane".to_string(),
age: 21,
},
];
_ = base.put(&users).unwrap();
// Get a single record
let user = base.get("user_1").unwrap();
println!("{:?}", user);
// Get in deserialized format
let user_d = base.get_as::("user_1").unwrap();
println!("{:?}", user_d);// Delete a record
_ = base.delete("user_1").unwrap();// Update a record
_ = base.update("user_1")
.set("name", Value::String("Johnny".to_string()))
.increment("age", Value::Number(Number::from(1)))
.commit()
.unwrap();// Query records
let resp = base.query()
.limit(1)
.sort(true)
.equals("name", Value::String("Johnny".to_string()))
.greater_than("age", Value::Number(Number::from(20)))
.less_than("age", Value::Number(Number::from(23)))
.run()
.unwrap();
println!("{:?}", resp);// Query all records
let resp = base.query().run_until_end().unwrap();
println!("{:?}", resp);
/////////////////////////////////
// Drive Methods //
////////////////////////////////
// Put a file
_ = drive.put("hello.txt", "Hello World".as_bytes(), Some("text/plain")).unwrap();// Delete a file
_ = drive.delete(vec!["hello.txt"]).unwrap();// Get a file
let resp = drive.get("hello.txt").unwrap();
// read the response body as bytes and do something with it// List files up to 10, default is 1000
let value = drive.list(None, 10, None).unwrap();
println!("{:?}", value);// List all files
let value = drive.list_all(None).unwrap();
println!("{:?}", value);
}```
## Base
Methods
- [x] `put` (batch max 25)
- [X] `get` (single)
- [X] `insert` (single)
- [X] `delete` (single)
- [X] `update` (with upsert)
- [X] `query` (paginated)
## Drive
Methods
- [X] `put` (single)
- [X] `get` (single)
- [X] `delete` (single)
- [X] `list` (paginated)
- [X] `walk` (multiple)