GithubHelp home page GithubHelp logo

measproem / alopecosa Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dedefer/alopecosa

0.0 0.0 0.0 55 KB

Tarantool connector for rust based on tokio

License: MIT License

Lua 0.66% Rust 99.34%

alopecosa's Introduction

MIT licensed Version Code Coverage Downloads

Added support: UUID, DateTime, Decimal

I have forked for personal use not yet fully unit test but may benefit someone

Alopecosa

Alopecosa is a convenient async pure-rust Tarantool 1.6+ connector built on tokio (version 1).

By the way, alopecosa is the kind of tarantula that inhabits in Japan.

Documentation link

Crates.io link

Example

use std::{
  error::Error,
  time::Duration,
  sync::Arc,
};
use alopecosa::{
  Connection, Connector, IntoTuple,
  Call, Eval, Select, Iterator
};
use tokio::time::timeout;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
  let addr = "127.0.0.1:3301".parse()?;
  let conn: Arc<Connection> = Connector::new(addr)
    .connect().await?;

  let eval_resp: (u32, u32) = conn.eval(Eval {
    expr: "return 1, 2".into(),
    args: ().into_tuple(),
  }).await?;

  let select_resp: Vec<(u32, u32, u32)> = conn.select(Select {
    space_id: 512, index_id: 0,
    limit: 100, offset: 0,
    iterator: Iterator::Ge,
    keys: ( 1u64, ).into_tuple(),
  }).await?;

  let (resp_with_timeout,): (i32,) = timeout(
    Duration::from_secs(1),
    conn.call(Call {
      function: "echo".into(),
      args: ( 123, ).into_tuple(),
    })
  ).await??;

  Ok(())
}

Auth

let addr = "127.0.0.1:3301".parse()?;
let conn: Arc<Connection> = Connector::new(addr)
  .with_auth("user".into(), "password".into())
  .connect().await?;

Connection tuning

let addr = "127.0.0.1:3301".parse()?;
let conn: Arc<Connection> = Connector::new(addr)
  .with_connect_timeout(Duration::from_secs(10))
  .with_reconnect_interval(Duration::from_secs(1))
  .with_send_request_timeout(Duration::from_secs(10))
  .connect().await?;

alopecosa's People

Contributors

dedefer avatar measproem avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.