Config

Struct Config 

Source
pub struct Config { /* private fields */ }
Expand description

Configuration for a Skytable connection

Implementations§

Source§

impl Config

Source

pub fn new_default(username: &str, password: &str) -> Self

Create a new Config using the default connection settings and using the provided username and password

Examples found in repository?
examples/multi_row.rs (line 12)
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 (line 64)
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 44)
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 20)
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 11)
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 new(host: &str, port: u16, username: &str, password: &str) -> Self

Create a new Config using the given settings.

PROTOCOL VERSION: Defaults to [ProtocolVersion::V2_0]

Source

pub fn host(&self) -> &str

Returns the host setting for this this configuration

Source

pub fn port(&self) -> u16

Returns the port setting for this this configuration

Source

pub fn username(&self) -> &str

Returns the username setting for this this configuration

Source

pub fn password(&self) -> &str

Returns the password set using this configuration

Source§

impl Config

Source

pub async fn connect_async(&self) -> ClientResult<ConnectionAsync>

Establish an async connection to the database using the current configuration

Source

pub async fn connect_tls_async( &self, cert: &str, ) -> ClientResult<ConnectionTlsAsync>

Establish an async TLS connection to the database using the current configuration. Pass the certificate in PEM format.

Source§

impl Config

Source

pub fn connect(&self) -> ClientResult<Connection>

Establish a connection to the database using the current configuration

Examples found in repository?
examples/multi_row.rs (line 12)
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 (line 65)
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 45)
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 21)
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 12)
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 connect_tls(&self, cert: &str) -> ClientResult<ConnectionTls>

Establish a TLS connection to the database using the current configuration. Pass the certificate in PEM format.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

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

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

impl PartialEq for Config

Source§

fn eq(&self, other: &Config) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.