|
| 1 | +//! # Skytable client [](https://crates.io/crates/skytable) [](https://github.com/skytable/client-rust/actions/workflows/test.yml) [](https://docs.rs/skytable) [](https://github.com/skytable/client-rust/releases) |
| 2 | +//! |
| 3 | +//! ## Introduction |
| 4 | +//! |
| 5 | +//! This library is the official client for the free and open-source NoSQL database |
| 6 | +//! [Skytable](https://github.com/skytable/skytable). First, go ahead and install Skytable by |
| 7 | +//! following the instructions [here](https://docs.skytable.io/getting-started). This library supports |
| 8 | +//! all Skytable versions that work with the [Skyhash 1.1 Protocol](https://docs.skytable.io/protocol/skyhash). |
| 9 | +//! This version of the library was tested with the latest Skytable release |
| 10 | +//! (release [0.7.2](https://github.com/skytable/skytable/releases/v0.7.2)). |
| 11 | +//! |
| 12 | +//! ## Features |
| 13 | +//! |
| 14 | +//! - Sync API |
| 15 | +//! - Async API |
| 16 | +//! - TLS in both sync/async APIs |
| 17 | +//! - Connection pooling for sync/async |
| 18 | +//! - Use both sync/async APIs at the same time |
| 19 | +//! - Always up-to-date |
| 20 | +//! |
| 21 | +//! ## Using this library |
| 22 | +//! |
| 23 | +//! This library only ships with the bare minimum that is required for interacting with Skytable. Once you have |
| 24 | +//! Skytable installed and running, you're ready to follow this guide! |
| 25 | +//! |
| 26 | +//! We'll start by creating a new binary application and then running actions. Create a new binary application |
| 27 | +//! by running: |
| 28 | +//! |
| 29 | +//! ```shell |
| 30 | +//! cargo new skyapp |
| 31 | +//! ``` |
| 32 | +//! |
| 33 | +//! **Tip**: You can see a full list of the available actions [here](https://docs.skytable.io/actions-overview). |
| 34 | +//! |
| 35 | +//! First add this to your `Cargo.toml` file: |
| 36 | +//! |
| 37 | +//! ```toml |
| 38 | +//! skytable = "0.6.3" |
| 39 | +//! ``` |
| 40 | +//! |
| 41 | +//! Now open up your `src/main.rs` file and establish a connection to the server while also adding some |
| 42 | +//! imports: |
| 43 | +//! |
| 44 | +//! ```norun |
| 45 | +//! use skytable::{Connection, Query, Element}; |
| 46 | +//! fn main() -> std::io::Result<()> { |
| 47 | +//! let mut con = Connection::new("127.0.0.1", 2003)?; |
| 48 | +//! Ok(()) |
| 49 | +//! } |
| 50 | +//! ``` |
| 51 | +//! |
| 52 | +//! Now let's run a `Query`! Change the previous code block to: |
| 53 | +//! |
| 54 | +//! ```norun |
| 55 | +//! use skytable::{error, Connection, Query, Element}; |
| 56 | +//! fn main() -> Result<(), error::Error> { |
| 57 | +//! let mut con = Connection::new("127.0.0.1", 2003)?; |
| 58 | +//! let query = Query::from("heya"); |
| 59 | +//! let res = con.run_simple_query(&query)?; |
| 60 | +//! assert_eq!(res, Element::String("HEY".to_owned())); |
| 61 | +//! Ok(()) |
| 62 | +//! } |
| 63 | +//! ``` |
| 64 | +//! |
| 65 | +//! ## Running actions |
| 66 | +//! |
| 67 | +//! As noted [below](#binary-data), the default table is a key/value table with a binary key |
| 68 | +//! type and a binary value type. Let's go ahead and run some actions (we're assuming you're |
| 69 | +//! using the sync API; for async, simply change the import to `use skytable::actions::AsyncActions`). |
| 70 | +//! |
| 71 | +//! ### `SET`ting a key |
| 72 | +//! |
| 73 | +//! ```norun |
| 74 | +//! use skytable::actions::Actions; |
| 75 | +//! use skytable::sync::Connection; |
| 76 | +//! |
| 77 | +//! let mut con = Connection::new("127.0.0.1", 2003).unwrap(); |
| 78 | +//! con.set("hello", "world").unwrap(); |
| 79 | +//! ``` |
| 80 | +//! |
| 81 | +//! This will set the value of the key `hello` to `world` in the `default:default` entity. |
| 82 | +//! |
| 83 | +//! ### `GET`ting a key |
| 84 | +//! |
| 85 | +//! ```norun |
| 86 | +//! use skytable::actions::Actions; |
| 87 | +//! use skytable::sync::Connection; |
| 88 | +//! |
| 89 | +//! let mut con = Connection::new("127.0.0.1", 2003).unwrap(); |
| 90 | +//! let x: String = con.get("hello").unwrap(); |
| 91 | +//! assert_eq!(x, "world"); |
| 92 | +//! ``` |
| 93 | +//! |
| 94 | +//! Way to go — you're all set! Now go ahead and run more advanced queries! |
| 95 | +//! |
| 96 | +//! ## Binary data |
| 97 | +//! |
| 98 | +//! The `default:default` keyspace has the following declaration: |
| 99 | +//! |
| 100 | +//! ```text |
| 101 | +//! Keymap { data:(binstr,binstr), volatile:false } |
| 102 | +//! ``` |
| 103 | +//! |
| 104 | +//! This means that the default keyspace is ready to store binary data. Let's say |
| 105 | +//! you wanted to `SET` the value of a key called `bindata` to some binary data stored |
| 106 | +//! in a `Vec<u8>`. You can achieve this with the `RawString` type: |
| 107 | +//! |
| 108 | +//! ```norun |
| 109 | +//! use skytable::actions::Actions; |
| 110 | +//! use skytable::sync::Connection; |
| 111 | +//! use skytable::types::RawString; |
| 112 | +//! |
| 113 | +//! let mut con = Connection::new("127.0.0.1", 2003).unwrap(); |
| 114 | +//! let mybinarydata = RawString::from(vec![1, 2, 3, 4]); |
| 115 | +//! assert!(con.set("bindata", mybinarydata).unwrap()); |
| 116 | +//! ``` |
| 117 | +//! |
| 118 | +//! ## Going advanced |
| 119 | +//! |
| 120 | +//! Now that you know how you can run basic queries, check out the [`actions`] module documentation for learning |
| 121 | +//! to use actions and the [`types`] module documentation for implementing your own Skyhash serializable |
| 122 | +//! types. Need to meddle with DDL queries like creating and dropping tables? Check out the [`ddl`] module. |
| 123 | +//! You can also find some [examples here](https://github.com/skytable/client-rust/tree/v0.7.0-alpha.1/examples) |
| 124 | +//! |
| 125 | +//! ## Connection pooling |
| 126 | +//! |
| 127 | +//! This library supports using sync/async connection pools. See the [`pool`] module-level documentation for examples |
| 128 | +//! and information. |
| 129 | +//! |
| 130 | +//! ## Async API |
| 131 | +//! |
| 132 | +//! If you need to use an `async` API, just change your import to: |
| 133 | +//! |
| 134 | +//! ```toml |
| 135 | +//! skytable = { version = "0.6.3", features=["aio"], default-features = false } |
| 136 | +//! ``` |
| 137 | +//! |
| 138 | +//! You can now establish a connection by using `skytable::AsyncConnection::new()`, adding `.await`s wherever |
| 139 | +//! necessary. Do note that you'll the [Tokio runtime](https://tokio.rs). |
| 140 | +//! |
| 141 | +//! ## Using both `sync` and `async` APIs |
| 142 | +//! |
| 143 | +//! With this client driver, it is possible to use both sync and `async` APIs **at the same time**. To do |
| 144 | +//! this, simply change your import to: |
| 145 | +//! |
| 146 | +//! ```toml |
| 147 | +//! skytable = { version="0.6.3", features=["sync", "aio"] } |
| 148 | +//! ``` |
| 149 | +//! |
| 150 | +//! ## TLS |
| 151 | +//! |
| 152 | +//! If you need to use TLS features, this crate will let you do so with OpenSSL. |
| 153 | +//! |
| 154 | +//! ### Using TLS with sync interfaces |
| 155 | +//! |
| 156 | +//! ```toml |
| 157 | +//! skytable = { version="0.6.3", features=["sync","ssl"] } |
| 158 | +//! ``` |
| 159 | +//! |
| 160 | +//! You can now use the async `sync::TlsConnection` object. |
| 161 | +//! |
| 162 | +//! ### Using TLS with async interfaces |
| 163 | +//! |
| 164 | +//! ```toml |
| 165 | +//! skytable = { version="0.6.3", features=["aio","aio-ssl"], default-features=false } |
| 166 | +//! ``` |
| 167 | +//! |
| 168 | +//! You can now use the async `aio::TlsConnection` object. |
| 169 | +//! |
| 170 | +//! ### _Packed TLS_ setup |
| 171 | +//! |
| 172 | +//! If you want to pack OpenSSL with your crate, then for sync add `sslv` instead of `ssl` or |
| 173 | +//! add `aio-sslv` instead of `aio-ssl` for async. Adding this will statically link OpenSSL |
| 174 | +//! to your crate. Do note that you'll need a C compiler, GNU Make and Perl to compile OpenSSL |
| 175 | +//! and statically link against it. |
| 176 | +//! |
| 177 | +//! ## MSRV |
| 178 | +//! |
| 179 | +//! The MSRV for this crate is Rust 1.39. Need const generics? Add the `const-gen` feature to your |
| 180 | +//! dependency! |
| 181 | +//! |
| 182 | +//! ## Contributing |
| 183 | +//! |
| 184 | +//! Open-source, and contributions ... — they're always welcome! For ideas and suggestions, |
| 185 | +//! [create an issue on GitHub](https://github.com/skytable/client-rust/issues/new) and for patches, |
| 186 | +//! fork and open those pull requests [here](https://github.com/skytable/client-rust)! |
| 187 | +//! |
| 188 | +//! ## License |
| 189 | +//! |
| 190 | +//! This client library is distributed under the permissive |
| 191 | +//! [Apache-2.0 License](https://github.com/skytable/client-rust/blob/next/LICENSE). Now go build great apps! |
| 192 | +//! |
| 193 | +
|
1 | 194 | /* |
2 | 195 | * Created on Wed May 05 2021 |
3 | 196 | * |
|
15 | 208 | * |
16 | 209 | */ |
17 | 210 |
|
18 | | -#![doc = include_str!("../README.md")] |
19 | 211 | #![cfg_attr(docsrs, feature(doc_cfg))] |
20 | 212 | // macro mods |
21 | 213 | #[macro_use] |
|
0 commit comments