Skip to main content

Connection

Struct Connection 

Source
pub struct Connection(/* private fields */);
Expand description

A skyhash/TCP connection

Specification

  • Protocol version: Skyhash/2.0
  • Query mode: QTDEX-1A/BQL-S1
  • Authentication plugin: pwd

Methods from Deref<Target = TcpConnection<TcpStream>>§

Source

pub fn execute_pipeline( &mut self, pipeline: &Pipeline, ) -> ClientResult<Vec<Response>>

Execute a pipeline. The server returns the queries in the order they were sent (unless otherwise set).

Source

pub fn query(&mut self, q: &Query) -> ClientResult<Response>

Run a query and return a raw Response

Source

pub fn query_parse<T: FromResponse>(&mut self, q: &Query) -> ClientResult<T>

Run and parse a query into the indicated type. The type must implement FromResponse

Examples found in repository?
examples/multi_row.rs (lines 14-17)
11fn main() {
12    let mut db = Config::new_default("user", "password").connect().unwrap();
13    let users: Rows<User> = db
14        .query_parse(&query!(
15            "select all username, password, followers, email from myspace.mymodel limit ?",
16            1000u64
17        ))
18        .unwrap();
19    // assume the first row has username set to 'sayan'
20    assert_eq!(users[0].username, "sayan");
21}
More examples
Hide additional examples
examples/dynamic_lists_advanced.rs (lines 68-71)
63fn main() {
64    let mut db = Config::new_default("root", "password12345678")
65        .connect()
66        .unwrap();
67    let data_from_api = get_data_from_api();
68    db.query_parse::<()>(&skytable::query!(
69        "insert into myapp.mydb { username: ?, password: ?, data: ? }",
70        &data_from_api
71    ))
72    .unwrap();
73    let fetched_user: User = db
74        .query_parse(&skytable::query!(
75            "select * from myapp.mydb where username = ?",
76            "sayan"
77        ))
78        .unwrap();
79    assert_eq!(data_from_api, fetched_user);
80}
examples/custom_types.rs (line 50)
43fn main() {
44    let mut db = Config::new_default("username", "password")
45        .connect()
46        .unwrap();
47
48    // set up schema
49    // create space
50    db.query_parse::<()>(&query!("create space myspace"))
51        .unwrap();
52    // create model
53    db.query_parse::<()>(&query!(
54        "create model myspace.mymodel(username: string, password: string, followers: uint64, null email: string)"
55    ))
56    .unwrap();
57
58    // insert data
59    let our_user = User::new("myuser".into(), "pass123".into(), 0, None);
60    db.query_parse::<()>(&query!(
61        "insert into myspace.mymodel(?, ?, ?, ?)",
62        our_user.clone()
63    ))
64    .unwrap();
65
66    // select data
67    let ret_user: User = db
68        .query_parse(&query!(
69            "select * from myspace.mymodel WHERE username = ?",
70            &our_user.username
71        ))
72        .unwrap();
73
74    assert_eq!(our_user, ret_user);
75}
examples/dynamic_lists_simple.rs (line 30)
19fn main() {
20    let mut db = Config::new_default("root", "password12345678")
21        .connect()
22        .unwrap();
23    let data_from_api = get_list_data_from_api();
24    let q = skytable::query!(
25        "insert into myapp.mydb { username: ?, password: ?, data: ? }",
26        "sayan",
27        "ulw06afuMCAg+1gh2lh1Y9xTIr/dUv2vqGLeZ39cVrE=",
28        QList::new(&data_from_api)
29    );
30    db.query_parse::<()>(&q).unwrap(); // expect this data to be inserted correctly
31                                       // now fetch this data
32    let (username, password, data): (String, String, RList<String>) = db
33        .query_parse(&skytable::query!(
34            "select * from myapp.mydb where username = ?",
35            "sayan"
36        ))
37        .unwrap();
38    assert_eq!(username, "sayan");
39    assert_eq!(password, "ulw06afuMCAg+1gh2lh1Y9xTIr/dUv2vqGLeZ39cVrE=");
40    assert_eq!(data.into_values(), data_from_api);
41}
examples/simple.rs (line 17)
10fn main() {
11    let mut db = Config::new_default("username", "password")
12        .connect()
13        .unwrap();
14
15    // set up schema
16    // create space
17    db.query_parse::<()>(&query!("create space myspace"))
18        .unwrap();
19    // create model
20    db.query_parse::<()>(&query!(
21        "create model myspace.mymodel(username: string, password: string, followers: uint64)"
22    ))
23    .unwrap();
24
25    // manipulate data
26
27    let (form_username, form_pass) = dummy_web_fetch_username_password();
28    // insert some data
29    db.query_parse::<()>(&query!(
30        "insert into myspace.mymodel(?, ?, ?)",
31        &form_username,
32        form_pass,
33        100_000_000u64
34    ))
35    .unwrap();
36
37    // get it back
38    let (password, followers): (String, u64) = db
39        .query_parse(&query!(
40            "select password, followers FROM myspace.mymodel WHERE username = ?",
41            &form_username
42        ))
43        .unwrap();
44    assert_eq!(password, "rick123", "password changed!");
45    // send to our client
46    dummy_respond_to_request(followers);
47
48    // update followers to account for huge numbers who were angry after being rickrolled
49    db.query_parse::<()>(&query!(
50        "update myspace.mymodel SET followers -= ? WHERE username = ?",
51        50_000_000u64,
52        &form_username
53    ))
54    .unwrap();
55
56    // alright, everyone is tired from being rickrolled so we'll have to ban rick's account
57    db.query_parse::<()>(&query!(
58        "delete from myspace.mymodel where username = ?",
59        &form_username
60    ))
61    .unwrap();
62}
Source

pub fn reset_buffer(&mut self)

Call this if the internally allocated buffer is growing too large and impacting your performance. However, normally you will not need to call this

Trait Implementations§

Source§

impl Debug for Connection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Connection

Source§

type Target = TcpConnection<TcpStream>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Connection

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.