1 unstable release

0.1.0 Jan 18, 2024

#2308 in Database interfaces

BSD-2-Clause

21KB
302 lines

Picoslon

A postgresql driver for picodata apps. Non blocking, fiber friendly, driven by CBUS. Build over rust-postgres driver.

This client has a similar API as postgres crate (see docs for more).

Usage example

Create a client using client builder:

    use radegast::ClientBuilder;
    use tarantool::cbus;
    use tarantool::fiber::Fiber;

    pub const CBUS_ENDPOINT: &str = "tests_endpoint";

    // initialize cbus first
    pub fn init_cbus() {
        let mut fiber = Fiber::new("cbus_endpoint_f", &mut |_: Box<()>| {
            let cbus_endpoint = cbus::Endpoint::new(CBUS_ENDPOINT).unwrap();
            cbus_endpoint.cbus_loop();
            0
        });
        fiber.start(());
    }

    fn main() {
        init_cbus();
        let client = picoslon::ClientBuilder::new()
            .build("host=localhost user=user password=password dbname=db", picoslon::postegress::NoTls, CBUS_ENDPOINT)
            .unwrap();
    }

If you want, you can manually define a tokio runtime (instead of default) for interaction with underline tokio-postgres library. Now you have the opportunity to query some data:

    let count = client.query_one("SELECT count(*) FROM some_table", &[]).unwrap();
    println!("count is {}", count.get::<_, i64>(0));

To familiarize with request APIs see the postgres docs.

Tests

We use tarantool-test. Run tests:

    docker-compose up -d
    cargo build
    tarantool-test -p ./target/debug/libtests.so

Dependencies

~12–22MB
~333K SLoC