GithubHelp home page GithubHelp logo

loomaclin / tarantool_rs Goto Github PK

View Code? Open in Web Editor NEW
14.0 5.0 0.0 203 KB

Sync/Async tarantool database connector. WORK IN PROGRESS. DON'T SHARE THIS REPO

License: GNU General Public License v3.0

Rust 100.00%
tarantool driver connector sync async rust library

tarantool_rs's Introduction

tarantool_rs

Sync/Async tarantool database connector.

Build Status

Coverage Status

Overview

Install

[dependencies]
tarantool = { git = "https://github.com/LooMaclin/tarantool_rs.git" }

Usage

Include extern crate

extern crate tarantool;

Use modules

use tarantool::{Value, Tarantool, IteratorType, Select, Insert, Replace, Delete, UpdateCommon,
                CommonOperation, Call, Eval, UpdateString, UpdateInteger, IntegerOperation, Upsert,
                UpsertOperation};

Create tarantool connection instance

    let mut tarantool_instance = Tarantool::auth("127.0.0.1:3301", "test", "test").unwrap_or_else(|err| {
        panic!("err: {}", err);
    });

    let error_handler = |err| panic!(SyncClient, err);

Retrieve space id

    let space_id = tarantool_instance.fetch_space_id("tester");
    debug!("Tester space id: {}", space_id);

Retrieve index id

    let index_id = tarantool_instance.fetch_index_id(space_id, "primary");
    debug!("Tester primary index id: {}", index_id);

Select

    let select = Select {
        space: 512,
        index: 0,
        limit: 100,
        offset: 0,
        iterator: IteratorType::All,
        keys: &vec![]
    };

    let tuples = tarantool_instance.request(&select).unwrap_or_else(&error_handler);

    debug!("Select result: ");
    for (index, tuple) in tuples.as_array().unwrap().iter().enumerate() {
        let tuple = tuple.as_array().unwrap();
        debug!("{}: {:?}", index, tuple);
    }
    

Insert

    let insert = Insert {
        space: 512,
        keys: &vec![Value::from(9)]
    };

    debug!("Insert result: {:?}", tarantool_instance.request(&insert).unwrap_or_else(&error_handler));

Replace

    let replace = Replace {
        space: 512,
        keys: &vec![Value::from(1), Value::String(String::from("TEST REPLACE"))]
    };

    debug!("Replace result: {:?}", tarantool_instance.request(&replace).unwrap_or_else(&error_handler));

Update integer

    let update_integer = UpdateInteger {
        space: 512,
        index: 0,
        operation_type: IntegerOperation::Addition,
        field_number: 2,
        argument: 1,
        keys: &vec![Value::from(4)]
    };

    debug!("Integer-Update result: {:?}", tarantool_instance.request(&update_integer).unwrap_or_else(&error_handler));

Update string

    let update_string = UpdateString {
        space: 512,
        index: 0,
        field_number: 1,
        position: 3,
        offset: 3,
        argument: "TEST UPDATE STRING".into(),
        keys: &vec![Value::from(2)]
    };

    debug!("String-Update result: {:?}", tarantool_instance.request(&update_string).unwrap_or_else(&error_handler));

Update common

    let update_common = UpdateCommon {
        space: 512,
        index: 0,
        operation_type: CommonOperation::Assign,
        field_number: 3,
        argument: Value::String(String::from("Test Update Common Assign")),
        keys: &vec![Value::from(6)]
    };

    debug!("Common-Update result: {:?}", tarantool_instance.request(&update_common).unwrap_or_else(&error_handler));

Delete

    let delete = Delete {
        space: 512,
        index: 0,
        keys: &vec![Value::from(3)]
    };

    debug!("Delete result: {:?}", tarantool_instance.request(&delete).unwrap_or_else(&error_handler));

Call

    let call = Call {
        function_name: "test",
        keys: &vec![]
    };

    debug!("Call result: {:?}", tarantool_instance.request(&call).unwrap_or_else(&error_handler));

Eval

    let eval = Eval {
        expression: r#"return 5+5"#,
        keys: &vec![]
    };

    debug!("Eval result: {:?}", tarantool_instance.request(&eval).unwrap_or_else(&error_handler));

Upsert

    let upsert = Upsert {
        space: 512,
        keys: &vec![Value::from(5)],
        operation_type: UpsertOperation::Add,
        field_number: 2,
        argument: 2,
    };

    debug!("Upsert result: {:?}", tarantool_instance.request(&upsert).unwrap_or_else(&error_handler));

#Roadmap

  • Without heap-allocation
  • Sync connector
  • Ergonomic API with builders
  • Async connector
  • Full test coverage
  • Full-application examples

tarantool_rs's People

Contributors

loomaclin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  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.