Skip to content

Commit

Permalink
docs: Add 0.8.9 examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ohsayan committed Jun 26, 2024
1 parent e0fa04f commit 75b7824
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ skytable = "0.8"
You're ready to go!

```rust
use skytable::{Query, Response, Config, query};
use skytable::{
Query, Response, Config, query,
response::Rows,
};

#[derive(Query, Response)]
#[derive(Clone, PartialEq, Debug)] // we just do these for the assert (they are not needed)
Expand All @@ -49,6 +52,10 @@ db.query_parse::<()>(&q).unwrap();
// select data
let user: User = db.query_parse(&query!("select * from myspace.mymodel where username = ?", &our_user.userid)).unwrap();
assert_eq!(user, our_user);

// select multiple rows
let users: Rows<User> = db.query_parse(&query!("select all * from myspace.mymodel limit ?", 1000u64)).unwrap();
assert_eq!(rows[0].userid, "user");
```

> **Read [docs here to learn BlueQL](https://docs.skytable.io/)**
Expand Down
15 changes: 15 additions & 0 deletions src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,21 @@ impl FromRow for Row {

#[derive(Debug, PartialEq)]
/// A collection of rows
///
/// ## Example
/// ```no_run
/// use skytable::{response::Rows, Config, Response, query};
///
/// #[derive(Response)]
/// struct User {
/// username: String,
/// password: String,
/// }
///
/// let mut db = Config::new_default("user", "pass").connect().unwrap();
/// let users: Rows<User> = db.query_parse(&query!("select all * from myapp.users limit ?", 1000u64)).unwrap();
/// assert_eq!(users[0].username, "sayan");
/// ```
pub struct Rows<T: FromRow = Row>(Vec<T>);

impl<T: FromRow> Rows<T> {
Expand Down

0 comments on commit 75b7824

Please sign in to comment.