picoslon

Crates.iopicoslon
lib.rspicoslon
version0.1.0
sourcesrc
created_at2024-01-18 11:06:06.067593
updated_at2024-01-18 11:06:06.067593
descriptionA postgresql driver for picodata apps.
homepage
repositoryhttps://git.picodata.io/picodata/modules/picoslon
max_upload_size
id1104095
size20,348
(picodata-account)

documentation

README

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
Commit count: 0

cargo fmt