UnQLite wrapper 1.0 is avaliable for Rust

Overview

unqlite

A high-level UnQLite database engine wrapper.

travis-badge release-badge downloads docs-badge license-badge

NOTE: Some of the documents is stolen from UnQLite Official Website.

What is UnQLite?

UnQLite is a software library which implements a self-contained, serverless, zero-configuration, transactional NoSQL database engine. UnQLite is a document store database similar to [MongoDB], [Redis], [CouchDB] etc. as well a standard Key/Value store similar to [BerkeleyDB], [LevelDB], etc.

UnQLite is an embedded NoSQL (Key/Value store and Document-store) database engine. Unlike most other NoSQL databases, UnQLite does not have a separate server process. UnQLite reads and writes directly to ordinary disk files. A complete database with multiple collections, is contained in a single disk file. The database file format is cross-platform, you can freely copy a database between 32-bit and 64-bit systems or between big-endian and little-endian architectures.

Port to Rust

This crate is high-level UnQLite database wrapper for Rust. A low-level bindings wrapper is available as a seperated crate: unqlite-sys.

Usage

You can start with UnQLite constructors:

extern crate unqlite;

use unqlite::{UnQLite, Config, KV, Cursor};

fn main() {
    // The database memory is not handled by Rust, and the database is on-disk,
    // so `mut` is not neccessary.
    let unqlite = UnQLite::create_temp();
    // Use any type that can use as `[u8]`
    unqlite.kv_store("key", "a long length value").unwrap();
    unqlite.kv_store("abc", [1,2,3]).unwrap();

    let mut entry = unqlite.first();
    // Iterate records
    loop {
        if entry.is_none() { break; }

        let record = entry.expect("valid entry");
        let (key, value) = record.key_value();
        println!("* Go through {:?} --> {:?}", key, value);

        if value.len() > 10 {
            println!("** Delete key {:?} by value length", key);
            entry = record.delete();
        } else {
            entry = record.next();
        }
    }
    //panic!("for test");
}

Contributors

  • @bemyak
  • @chritchens
  • @wolandr
  • @timlyo
  • @dariusc93
Comments
  • Derive clone for UnQLiteVm

    Derive clone for UnQLiteVm

    I think UnQLiteVm needs a Clone trait for the following scenario:

    I have a Jx9-script that can search in DB and return some result. Multiple clients want to use it at the same time (asynchronously) to get data from DB. They must somehow pass their search parameters to script. The only way I found is to use add_argument method, but it requires to have a mutable reference to UnQLiteVm. So I need to make a Mutex or RfCell and still each client will lock the UnQLiteVm instance.

    The simple solution is to spawn UnQLiteVm on each request, but I'm afraid that UnQLite::complie() will cause unnecessary CPU and IO usage. But with this trait we can copy comiled version of UnQLiteVm for each client -- not much overhead.

    Also I've updated upstream repo to current version, all tests have passed.

    opened by bemyak 4
  • Removed deprecated functions and minor update to unqlite.rs.

    Removed deprecated functions and minor update to unqlite.rs.

    While these changes are minor, they do remove deprecated calls and also updated to use 2018 edition. Submodule was also updated and a examples/temp.rs was added (which was taken from the readme, might add my own example at a later date, although the current example is more than enough).

    opened by dariusc93 3
  • Add an example of creating DB at a path

    Add an example of creating DB at a path

    The example is on creating the DB in a temporary file. Is there any possibility to add an example when creating the db on a file path? There is lot of confusion for a new bie.

    Thanks.

    opened by elielnfinic 1
  • Failed to run custom build command for `unqlite v1.5.0`

    Failed to run custom build command for `unqlite v1.5.0`

    Hi ,

    I copy & paste the Example code provided in readme usage section and then did cargo run .

    Found Following Error error: failed to run custom build command for unqlite v1.5.0

    Screen Shot with RUST_BACKTRACE=1
    unqlite_error

    Complete Error Log With RUST_BACKTRACE=full unqlite_error.txt

    Rust Version - rustc 1.57.0 (f1edd0429 2021-11-29) Cargo Version - cargo 1.57.0 (b2e52d7ca 2021-10-21) Operating System -Windows, version 10.0.19042 X64

    I would greatly appreciate your assistance if I am missing something.

    opened by RahulDas-dev 1
  • Publish 1.4.2 to crates.io

    Publish 1.4.2 to crates.io

    The latest version of unqlite on crates.io is 1.4.1, which requires the concat_ident feature, which won't work on stable Rust. I configured a project to import v1.4.2 directly from the head of this repository and on cursory inspection, it seems work fine and appears ready for release. If there isn't a problem, could you publish 1.4.2? I'd much appreciate having all my dependencies archived in crates.io.

    opened by Flaise 1
  • Implement Send for Error

    Implement Send for Error

    Implement Send for Error so that it could be used in structs and traits requiring any error E to be E: Error + Send + 'static (e.g.: generally Result).

    opened by chritchens 1
  • Can't build on latest (2aeb5930f 2017-08-25) nightly

    Can't build on latest (2aeb5930f 2017-08-25) nightly

    $ rustup run nightly-x86_64-unknown-linux-gnu cargo build
       Compiling unqlite v1.3.0 (file:///home/sergey/projects/unqlite.rs-1.3.0)
    error[E0308]: mismatched types
       --> src/lib.rs:149:49
        |
    149 |             .map(|_| UnQLite { engine: unsafe { Shared::new(db) } })
        |                                                 ^^^^^^^^^^^^^^^ expected struct `std::ptr::Shared`, found enum `std::option::Option`
        |
        = note: expected type `std::ptr::Shared<_>`
                   found type `std::option::Option<std::ptr::Shared<_>>`
    
    error[E0308]: mismatched types
       --> src/kv_cursor.rs:220:34
        |
    220 |                 cursor: unsafe { Unique::new(cursor) },
        |                                  ^^^^^^^^^^^^^^^^^^^ expected struct `std::ptr::Unique`, found enum `std::option::Option`
        |
        = note: expected type `std::ptr::Unique<_>`
                   found type `std::option::Option<std::ptr::Unique<_>>`
    
    error[E0308]: mismatched types
      --> src/document/doc_store.rs:99:30
       |
    99 |             native: unsafe { Shared::new(vm) }, 
       |                              ^^^^^^^^^^^^^^^ expected struct `std::ptr::Shared`, found enum `std::option::Option`
       |
       = note: expected type `std::ptr::Shared<_>`
                  found type `std::option::Option<std::ptr::Shared<_>>`
    
    error: aborting due to 3 previous errors
    
    error: Could not compile `unqlite`.
    
    opened by vessd 1
  • Is the project still maintained?

    Is the project still maintained?

    Hello 👋

    I'm looking for an embedded DB (sql, nosql, graph, but not key/value) to store a moderate amount of data for a Tauri app.

    It looks like the document interface is not yet complete when having a look at the roadmap (#1), and the last commit was two years ago.

    Is it something you think is going to be done at some point, or is this project on life support? :)

    opened by martpie 1
  • Make error codes available

    Make error codes available

    Right now, the only way I see for a program calling the UnQLite wrapper to know the nature of an error is to compare the error string associated with the error with the string literals in UnQLite's error.rs. This seems unsafe.

    The Custom struct that is returned for the error contains UnQLite's numeric error code and the ErrorKind enum variant that the wrapper assigned to it. However, even though the ErrorKind enum is public, the fields of the UnQLite struct are private and there is no way for the calling program to access this.

    Please add methods to access the fields of a Custom struct:

    #[derive(Clone, Debug, PartialEq, Eq)]
    pub struct Custom {
        kind: ErrorKind,
        raw: i32,
    }
    
    opened by mgrand 0
  • Crash when getting key-value pairs during iteration

    Crash when getting key-value pairs during iteration

    OS: windows 8.1 Rust toolchain: nightly-1.29.0-x86_64-pc-windows-gnu Clang: clang version 5.0.0 (tags/RELEASE_500/final) Target: x86_64-w64-windows-gnu Thread model: posix unqlite.rs: 1.4.1

    gdb trace info: ... warning: HEAP[test_db.exe]: warning: Invalid address specified to RtlFreeHeap( 0000000000AC0000, 0000000000024830 ) Program received signal SIGTRAP, Trace/breakpoint trap. 0x00007ff8b7413af2 in ntdll!RtlpNtMakeTemporaryKey () from C:\WINDOWS\SYSTEM32\ntdll.dll (gdb) bt bt #0 0x00007ff8b7413af2 in ntdll!RtlpNtMakeTemporaryKey () from C:\WINDOWS\SYSTEM32\ntdll.dll #1 0x00007ff8b73cd876 in ntdll!memset () from C:\WINDOWS\SYSTEM32\ntdll.dll #2 0x00007ff8b7412984 in ntdll!RtlpNtMakeTemporaryKey () from C:\WINDOWS\SYSTEM32\ntdll.dll #3 0x00007ff8b73ca8d5 in ntdll!memset () from C:\WINDOWS\SYSTEM32\ntdll.dll #4 0x00007ff8b7355a38 in ntdll!RtlFreeHeap () from C:\WINDOWS\SYSTEM32\ntdll.dll #5 0x0000000000419282 in alloc::alloc::dealloc ( ptr=0x24830 "SALDKFJ;098787t5k,.mcv,xmc.ckpo&^%IOU_)K<jlknksafd;alkmds7t6r57k()&^%$#@$%^&<mhlsmv,s.mdf;lasdfya967sdjl;867546KHHGLK;", '\253' <repeats 16 times>, "\356\376\356\376\356\376\000", layout=...) at C:\projects\rust\src\liballoc/alloc.rs:80 #6 0x000000000041906b in <alloc::alloc::Global as core::alloc::Alloc>::dealloc (self=0x23fb60, ptr=..., layout=...) at C:\projects\rust\src\liballoc/alloc.rs:128 #7 0x000000000041ad3a in <alloc::raw_vec::RawVec<T, A>>::dealloc_buffer ( self=0x23fb60) at C:\projects\rust\src\liballoc/raw_vec.rs:720 #8 0x000000000041c813 in <alloc::raw_vec::RawVec<T, A> as core::ops::drop::Drop>::drop (self=0x23fb60) at C:\projects\rust\src\liballoc/raw_vec.rs:729 #9 0x0000000000403ab3 in core::ptr::drop_in_place () at C:\projects\rust\src\libcore/ptr.rs:59 #10 0x0000000000403b02 in core::ptr::drop_in_place () at C:\projects\rust\src\libcore/ptr.rs:59 #11 0x0000000000406a16 in test_db::main () at src\main.rs:38 (gdb)

    #0  0x00007ff8b7413af2 in ntdll!RtlpNtMakeTemporaryKey ()
       from C:\WINDOWS\SYSTEM32\ntdll.dll
    #1  0x00007ff8b73cd876 in ntdll!memset () from C:\WINDOWS\SYSTEM32\ntdll.dll
    #2  0x00007ff8b7412984 in ntdll!RtlpNtMakeTemporaryKey () from C:\WINDOWS\SYSTEM32\ntdll.dll
    #3  0x00007ff8b73ca8d5 in ntdll!memset () from C:\WINDOWS\SYSTEM32\ntdll.dll
    #4  0x00007ff8b7355a38 in ntdll!RtlFreeHeap ()
       from C:\WINDOWS\SYSTEM32\ntdll.dll
    #5  0x0000000000419282 in alloc::alloc::dealloc (
        ptr=0x24830 "SALDKFJ;098787t5k,.mcv,xmc.ckpo&*^%*IOU_)K<jlknksafd;alkmds7t6r57k()*&^%$#@$%^&*<mhlsmv,s.mdf;lasdfya967sdjl;867546KHHGLK;", '\253' <repeats 16 times>, "\356\376\356\376\356\376\000", layout=...)
        at C:\projects\rust\src\liballoc/alloc.rs:80
    #6  0x000000000041906b in <alloc::alloc::Global as core::alloc::Alloc>::dealloc (self=0x23fb60, ptr=..., layout=...)
        at C:\projects\rust\src\liballoc/alloc.rs:128
    #7  0x000000000041ad3a in <alloc::raw_vec::RawVec<T, A>>::dealloc_buffer (self=0x23fb60) at C:\projects\rust\src\liballoc/raw_vec.rs:720
    #8  0x000000000041c813 in <alloc::raw_vec::RawVec<T, A> as core::ops::drop::Drop>::drop (self=0x23fb60) at C:\projects\rust\src\liballoc/raw_vec.rs:729
    #9  0x0000000000403ab3 in core::ptr::drop_in_place ()
        at C:\projects\rust\src\libcore/ptr.rs:59
    #10 0x0000000000403b02 in core::ptr::drop_in_place ()
        at C:\projects\rust\src\libcore/ptr.rs:59
    #11 0x0000000000406a16 in test_db::main () at src\main.rs:38
    
    opened by vmosone 0
  • Roadmap

    Roadmap

    • Database Engine Handle
      • [x] unqlite_open
      • [x] unqlite_config
      • [x] unqlite_close
    • Key/Value Store Interfaces
      • [x] unqlite_kv_store
      • [x] unqlite_kv_append
      • [ ] unqlite_kv_store_fmt
      • [ ] unqlite_kv_append_fmt
      • [x] unqlite_kv_fetch
      • [ ] unqlite_kv_fetch_callback
      • [x] unqlite_kv_delete
      • [x] unqlite_kv_config
    • Document Store (JSON via Jx9) Interfaces
      • [ ] unqlite_compile
      • [ ] unqlite_compile_file
      • [ ] unqlite_vm_config
      • [ ] unqlite_vm_exec
      • [ ] unqlite_vm_reset
      • [ ] unqlite_vm_release
      • [ ] unqlite_vm_extract_variable
      • [ ] unqlite_vm_dump
    • Cursor Iterator Interfaces
      • [x] unqlite_kv_cursor_init
      • [x] unqlite_kv_cursor_release
      • [x] unqlite_kv_cursor_seek
      • [x] unqlite_kv_cursor_first_entry
      • [x] unqlite_kv_cursor_last_entry
      • [x] unqlite_kv_cursor_valid_entry
      • [x] unqlite_kv_cursor_next_entry
      • [x] unqlite_kv_cursor_prev_entry
      • [x] unqlite_kv_cursor_key
      • [x] unqlite_kv_cursor_key_callback
      • [x] unqlite_kv_cursor_data
      • [x] unqlite_kv_cursor_data_callback
      • [x] unqlite_kv_cursor_delete_entry
      • [x] unqlite_kv_cursor_reset
    • Manual Transaction Manager
      • [x] unqlite_begin
      • [x] unqlite_commit
      • [x] unqlite_rollback
    • Utility Interfaces
      • [x] unqlite_util_load_mmaped_file
      • [x] unqlite_util_release_mmaped_file
      • [x] unqlite_util_random_string
      • [x] unqlite_util_random_num
    • In-process Extending Interfaces
      • [ ] unqlite_create_function
      • [ ] unqlite_delete_function
      • [ ] unqlite_create_constant
      • [ ] unqlite_delete_constant
    • To be continued
    opened by zitsen 0
Releases(v1.5.0)
An API Wrapper for https://paste.myst.rs written in rust

PasteMyst.RS pastemyst-rs is an api wrapper for pastemyst written in Rust. ⚠ This package is under development ⚠ Sample usage To get a paste from past

ANF Studios 14 Nov 28, 2021
duckdb-rs is an ergonomic wrapper for using duckdb from Rust.

duckdb-rs duckdb-rs is an ergonomic wrapper for using duckdb from Rust. It attempts to expose an interface similar to rusqlite. Acctually the initial

Wang Fenjin 126 Dec 30, 2022
ODBC wrapper for safe idiomatic Rust

ODBC wrapper for safe idiomatic Rust Library for writing ODBC applications in Rust. If you're looking for raw ODBC FFI bindings check odbc-safe and od

Konstantin V. Salikhov 91 Dec 10, 2022
Rusqlite is an ergonomic wrapper for using SQLite from Rust

Rusqlite Rusqlite is an ergonomic wrapper for using SQLite from Rust. It attempts to expose an interface similar to rust-postgres. use rusqlite::{para

Rusqlite 1.9k Jan 7, 2023
Thin wrapper around [`tokio::process`] to make it streamable

process-stream Wraps tokio::process::Command to future::stream. Install process-stream = "0.2.2" Example usage: From Vec<String> or Vec<&str> use proc

null 4 Jun 25, 2022
Postgres Foreign Data Wrapper for Clerk.com API

Pre-requisites Postgres-15 Rust pgrx Getting Started To run the program locally, clone the repository git clone https://github.com/tembo-io/clerk_fdw.

Tembo 3 Aug 22, 2023
🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, SQLite, and MSSQL.

SQLx ?? The Rust SQL Toolkit Install | Usage | Docs Built with ❤️ by The LaunchBadge team SQLx is an async, pure Rust† SQL crate featuring compile-tim

launchbadge 7.6k Dec 31, 2022
Redis re-implemented in Rust.

rsedis Redis re-implemented in Rust. Why? To learn Rust. Use Cases rsedis does not rely on UNIX-specific features. Windows users can run it as a repla

Sebastian Waisbrot 1.6k Jan 6, 2023
A generic connection pool for Rust

r2d2 A generic connection pool for Rust. Documentation Opening a new database connection every time one is needed is both inefficient and can lead to

Steven Fackler 1.2k Jan 8, 2023
An ArangoDB driver for Rust

Rincon Rincon is an ArangoDB driver for Rust. It enables low level access to ArangoDB in a typesafe and Rust idiomatic manner. The name Rincon is deri

Innoave 35 Mar 21, 2021
Cassandra DB native client written in Rust language. Find 1.x versions on https://github.com/AlexPikalov/cdrs/tree/v.1.x Looking for an async version? - Check WIP https://github.com/AlexPikalov/cdrs-async

CDRS CDRS is looking for maintainers CDRS is Apache Cassandra driver written in pure Rust. ?? Looking for an async version? async-std https://github.c

Alex Pikalov 338 Jan 1, 2023
Cassandra (CQL) driver for Rust, using the DataStax C/C++ driver under the covers.

cassandra-cpp This is a maintained Rust project that exposes the DataStax cpp driver at https://github.com/datastax/cpp-driver/ in a somewhat-sane cra

null 93 Jan 7, 2023
CouchDB client-side library for the Rust programming language

Chill Chill is a client-side CouchDB library for the Rust programming language, available on crates.io. It targets Rust Stable. Chill's three chief de

null 35 Jun 26, 2022
Sofa - CouchDB for Rust

Sofa - CouchDB for Rust Documentation Here: http://docs.rs/sofa Installation [dependencies] sofa = "0.6" Description This crate is an interface to Cou

66 Origin 40 Feb 11, 2022
⚡🦀 🧨 make your rust types fit DynamoDB and visa versa

?? ?? dynomite dynomite makes DynamoDB fit your types (and visa versa) Overview Goals ⚡ make writing dynamodb applications in rust a productive experi

Doug Tangren 197 Dec 15, 2022
A Rust client for the ElasticSearch REST API

rs-es Introduction An ElasticSearch client for Rust via the REST API. Targetting ElasticSearch 2.0 and higher. Other clients For later versions of Ela

Ben Ashford 218 Dec 27, 2022
An Elasticsearch REST API client for Rust

elastic elastic is an efficient, modular API client for Elasticsearch written in Rust. The API is targeting the Elastic Stack 7.x. elastic provides st

null 249 Oct 18, 2022
An etcd client library for Rust.

etcd An etcd client library for Rust. etcd on crates.io Documentation for the latest crates.io release Running the tests Install Docker and Docker Com

Jimmy Cuadra 138 Dec 27, 2022
etcd for rust

etcd for Rust An etcd(API v3) client for Rust, and it provides async/await APIs backed by tokio and tonic. Documentation on the library can be found a

ccc 159 Dec 30, 2022