Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ohsayan committed Dec 6, 2023
1 parent 2786b6e commit b1018d6
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 277 deletions.
2 changes: 0 additions & 2 deletions examples/Cargo.toml

This file was deleted.

31 changes: 0 additions & 31 deletions examples/README.md

This file was deleted.

11 changes: 0 additions & 11 deletions examples/actions/Cargo.toml

This file was deleted.

18 changes: 0 additions & 18 deletions examples/actions/src/main.rs

This file was deleted.

13 changes: 0 additions & 13 deletions examples/aio/Cargo.toml

This file was deleted.

22 changes: 0 additions & 22 deletions examples/aio/src/main.rs

This file was deleted.

10 changes: 0 additions & 10 deletions examples/basic/Cargo.toml

This file was deleted.

19 changes: 0 additions & 19 deletions examples/basic/src/main.rs

This file was deleted.

9 changes: 0 additions & 9 deletions examples/custom-queries/Cargo.toml

This file was deleted.

39 changes: 0 additions & 39 deletions examples/custom-queries/src/main.rs

This file was deleted.

11 changes: 0 additions & 11 deletions examples/custom-types/Cargo.toml

This file was deleted.

62 changes: 0 additions & 62 deletions examples/custom-types/src/main.rs

This file was deleted.

75 changes: 75 additions & 0 deletions examples/custom_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use skytable::{
query,
query::SQParam,
response::{FromResponse, Response},
ClientResult, Config,
};

#[derive(Debug, PartialEq, Clone)]
struct User {
username: String,
password: String,
followers: u64,
email: Option<String>,
}

impl User {
fn new(username: String, password: String, followers: u64, email: Option<String>) -> Self {
Self {
username,
password,
followers,
email,
}
}
}

impl SQParam for User {
fn append_param(&self, q: &mut Vec<u8>) -> usize {
self.username.append_param(q)
+ self.password.append_param(q)
+ self.followers.append_param(q)
+ self.email.append_param(q)
}
}

impl FromResponse for User {
fn from_response(resp: Response) -> ClientResult<Self> {
let (username, password, followers, email) = FromResponse::from_response(resp)?;
Ok(Self::new(username, password, followers, email))
}
}

fn main() {
let mut db = Config::new_default("username", "password")
.connect()
.unwrap();

// set up schema
// create space
db.query_parse::<()>(&query!("create space myspace"))
.unwrap();
// create model
db.query_parse::<()>(&query!(
"create model myspace.mymodel(username: string, password: string, followers: uint64, null email: string"
))
.unwrap();

// insert data
let our_user = User::new("myuser".into(), "pass123".into(), 0, None);
db.query_parse::<()>(&query!(
"insert into myspace.mymodel(?, ?, ?, ?)",
our_user.clone()
))
.unwrap();

// select data
let ret_user: User = db
.query_parse(&query!(
"select * from myspace.mymodel WHERE username = ?",
&our_user.username
))
.unwrap();

assert_eq!(our_user, ret_user);
}
9 changes: 0 additions & 9 deletions examples/ddl/Cargo.toml

This file was deleted.

21 changes: 0 additions & 21 deletions examples/ddl/src/main.rs

This file was deleted.

Loading

0 comments on commit b1018d6

Please sign in to comment.