SQLite3 Bindings for Rust

Related tags

Database rustsqlite
Overview

SQLite3 Bindings for Rust

To compile use rustc src/sqlite3.rs or if you have Cargo installed cargo build.

The interface is currently evolving both along with Rust and as I think of better ways to implement various behaviors. If you have ideas about better behavior for anything in this binding please feel free to open an issue.

Build status: Build Status

Maintainers

These are the brave souls who have kept this project alive in some fashion or another. Note to future maintainers: if you feel you've made significant contributions to the project, do add yourself to the list.

  • @linuxfood originally wrote the bindings, then wandered away - 2011
  • @kud1ing took over maintainership for quite awhile - 2011-2014
  • @lifthrasiir now carries the torch - 2014
Comments
  • Evaluate making a full featured DBI interface for Rust

    Evaluate making a full featured DBI interface for Rust

    So this was just an idea that popped into my head at some point and I figured I should jot it down.

    If nobody else is working on making a DBI interface for Rust (similar to, but perhaps a little more coherent than Perl DBI: http://dbi.perl.org/ ), we might be in a pretty cool spot to think about that.

    @kud1ing do you have any thoughts or interest? :)

    opened by linuxfood 13
  • Fix various mutability problems.

    Fix various mutability problems.

    The fix was planned after #94 but I was a bit late in the party. So, this commit fixes the following:

    • Fixed a mistake that Database was accidentally Sendable.
    • Made Cursor::{reset, clear_bindings, step, step_row, get_blob, get_int, get_i64, get_f64, get_text, bind_param, bind_params} receive &mut self.
    • Made Database::set_busy_timeout receive &mut self. Database::{prepare, exec} has been left as is, since it is perfectly safe to have multiple cursors (see prepared_stmt_bind_static_text_interleaved test for an example). The associated thread safety issue is handled by making Database non-Sendable.

    Closes #98, #99, #100, #101 and #103.

    opened by lifthrasiir 7
  • Revisit the bundled sqlite library

    Revisit the bundled sqlite library

    I was just looking over things since #26 was raised, and thinking that the bundled sqlite should probably either be removed or updated, since it was last updated a year ago, and I know there have been quite a few updates since then.

    opened by linuxfood 6
  • Ensure that a cursor outlives its database

    Ensure that a cursor outlives its database

    Cursors now borrow a pointer to the database handle. This changes the prepare() api.

    If you turn on debug logging before applying this commit, you can see the database's Drop running before the cursor's.

    I'm no rust expert, so this may not be the best way.

    opened by PeterReid 4
  • Database::prepare() and Database::exec() mutate but do not take &mut self

    Database::prepare() and Database::exec() mutate but do not take &mut self

    This is a threadsafety problem.

    In Rust, safe code provides several guarantees: that aliased data cannot be mutated, that mutation is only possible through unique paths, that data races cannot happen, that invalid memory cannot be accessed, that references cannot outlive their referents, etc.

    If you are going to directly wrap C functions that do not provide these guarantees, you need to mark your functions unsafe. Otherwise you are violating the contract of the language and putting your users at risk.

    opened by apoelstra 3
  • Naming in anticipation of sqlite4

    Naming in anticipation of sqlite4

    Sqlite4 is coming and will probably overtake sqlite3 at some point in the future. It would be good to future-proof these bindings in anticipation of that. Two things I can see are:

    • get_num could be renamed get_f64. Sqlite4 is going to have sqlite4_num, a decimal instead of binary floating point representation, ( http://sqlite.org/src4/doc/trunk/www/decimal.wiki ) so this naming would be confusing to a future users who are more familiar with sqlite4.
    • This is a more annoying change, but: the crate could be named and linked as sqlite3 instead of sqlite. Otherwise, some future version of rustpkg may end up with an often-used "sqlite4" package and a rarely used "sqlite" that shadows it in the autocomplete.

    I'm perfectly willing to do these changes, but I thought it would be good to see what other people thing before doing something with so much API change.

    opened by PeterReid 2
  • Segfault with bind_param

    Segfault with bind_param

    Hi! First of all, cool project ;-)

    I tried it out (am still new to Rust) and arrived at a segfault. Thought you'd like to know about it if you don't already.

    I'm running the master version of both rustsqlite and Rust.

    It may just be a transitioning thing (I know Rust is changing and breaking all the time), but it's a bit difficult for me to tell the difference.

    Anyway, here's the code: https://gist.github.com/brinchj/7363049

    I tried running the code through valgrind, but it doesn't seem to give me anything useful. Except perhaps that it seems to be telling me that the segfault is in finalize: ==31159== by 0x713477E: sqlite3_finalize (in /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6) ==31159== by 0x5D936C9: cursor::Drop$Cursor::drop::h96b05de1db21bd53ioao::v0.1

    If I comment out the bind_param line, the program runs fine. And it only seems to happen with Text. Integer doesn't segfault.

    opened by brinchj 2
  • Remove sqlite.rs

    Remove sqlite.rs

    It seems @erickt somewhat duplicated sqlite.rs into sqlite.rc in https://github.com/linuxfood/rustsqlite/commit/eb89e85580a54fd390c355642c571cd1d6701789#sqlite.rc

    sqlite.rc appears to be more up-to-date.

    Should sqlite.rs be removed?

    opened by kud1ing 2
  • get sqlite working on 0.4

    get sqlite working on 0.4

    There were a couple other last minute changes that broke rustsqlite. This fixes them, and also switches over to using send_maps instead of hashmaps, as that gets rid of the "no-implicit-copies" warnings.

    To do is some library modernization, such as converting over to structs, and getting it to work well with serialization. That'll come in a little bit.

    opened by erickt 2
  • Travis build error: rustup.sh

    Travis build error: rustup.sh

    https://travis-ci.org/linuxfood/rustsqlite

    rustup.sh seems to await an interactive input which times out:

    You may uninstall later by running /usr/local/lib/rustlib/uninstall.sh,
    or by running this script again with the --uninstall flag.
    
    Continue? (y/N) 
    
    No output has been received in the last 10 minutes, this potentially indicates a stalled build or something wrong with the build itself.
    

    Maybe pass the --uninstall flag?

    opened by kud1ing 1
  • Copy is opt-in, Sync is automatically not implemented for raw pointers, and libc lives on crates.io

    Copy is opt-in, Sync is automatically not implemented for raw pointers, and libc lives on crates.io

    See marker.rs for some discussion of the current state of marker traits. The upshot is that Copy is opt-in, so we don't need to explicitly opt out with a _nocopy field, and Database automatically does not implement Sync because it has a *mut dbh field.

    After this change, this project is compatible with the beta release of rustc. :)

    opened by dwrensha 1
  • Easy way to get stuff out of a RowMap

    Easy way to get stuff out of a RowMap

    A RowMap is defined as a HashMap<String, BindArg>. I am relatively new to Rust, and maybe that is why, taking values out of a RowMap is annoying:

    let text = match row_map.get("somekey") {
        Some(BindArg::Text(ref val)) => val.clone(),
        Some(_) => panic!("Wrong type"),
        None => panic!("No such column")
    };
    

    Am I missing something? Is there a better, less verbose way of doing this? If not, I propose this:

    pub trait TypedGet {
        fn get_text(&self, key: &str) -> Option<String>;
        fn get_float64(&self, key: &str) -> Option<f64>;
        fn get_integer(&self, key: &str) -> Option<isize>;
        fn get_integer64(&self, key: &str) -> Option<i64>;
        fn get_blog(&self, key: &str) -> Option<Vec<u8>>;
    }
    
    impl TypedGet for RowMap {
        fn get_text(&self, key: &str) -> Option<String> {
            match self.get(key) {
                Some(thing) => match *thing {
                    BindArg::Text(ref val) => Some(val.clone()),
                    BindArg::Null => None,
                    _ => panic!("No text found"), // Or maybe change the return type to Result<Option<String>, String> and Err here?
                },
                None => None,
            }
        }
        // And so on for other trait fns...
    }
    

    This will allow people to import the TypedGet trait and then use these methods instead of writing their own similar utility methods.

    Another solution (maybe better) could be to implement these methods on the enum BindArg itself.

    impl BindArg {
        pub fn get_text(&self) -> Result<Option<String>, String> {
            match *self {
                BindArg::Text(ref val) => Ok(Some(val.clone())),
                BindArg::Null => Ok(None),
                _ => Err("No text found".to_string()),
            }
        }
       // ...
    }
    

    But I'm not sure if there is already a better way around this. Thanks.

    opened by yati-sagade 0
  • No way to get error string for sqlite3::open() failure

    No way to get error string for sqlite3::open() failure

    rustsqlite doesn't expose a way to query the database for the error message for the failure of creating the database since the binding closes the db handle, so Database::get_errmsg cannot be called. Also sqlite3_errstr is apparently not exposed.

    opened by ben0x539 0
  • Database::get_errmsg() is not threadsafe

    Database::get_errmsg() is not threadsafe

    The function sqlite3_errmsg returns the error message from "the most recent call". If this is going to be exposed then every single function calling a sqlite3_* function needs to take a mutable self, otherwise this function will be racy.

    Probably the better thing is to not expose this message and instead bundle its result into any Errs that are returned from SqliteResult-returning function, since it is not very Rustic to have error reporting be separated from error occurance like this.

    opened by apoelstra 1
  • Decoder / Encoder API for query results and binding

    Decoder / Encoder API for query results and binding

    The idea is the client declares a strict with deriving Encodeable; then query results come back as an iterator over that type.

    Likewise, bind variables for a statement can be set from a a Decodeable struct or perhaps even a tuple.

    I hope to work up a PR.

    opened by dckc 0
  • The rlib shares a same base name with SQLite

    The rlib shares a same base name with SQLite

    As per rust-lang/rfcs#109, rustsqlite now produces libsqlite3.rlib which shares a same base name with SQLite (libsqlite3.a) and causes a name conflict when linked by other crates. It can be resolved either by giving -C extra-filename=_rust (or similar) to rustc, or by renaming the library. It may also be made a non-issue when Cargo may resolve this as well.

    opened by lifthrasiir 0
  • examples

    examples

    Hi, Any chance of some up-to-date examples, or can you point me to some up-to-date examples? The main thing currently that I need to do is a SELECT with NEXT or similar and extracting column values. I've seen highlow, but I believe that's not up-to-date.

    opened by brianoh 3
Owner
null
Example sqlite3 Dynamic Loadable Extension in Rust - vfs and vtab modules - port of vfsstat.c

Example sqlite3 Dynamic Loadable Extension in Rust - vfs and vtab modules The vfs and vtab This is a port of the official ext/misc/vfsstat.c sqlite3 e

Manos Pitsidianakis 28 Oct 10, 2022
sqlite3 Rewritten in RiiR Rust 🦀🦀🦀

sqlite3 Rewritten in RiiR Rust ?? ?? ?? Finally, one of the best written software paired with one of the best writable programming language‽ Fearless

Manos Pitsidianakis 142 Jan 3, 2023
Rust bindings for LMDB

lmdb-rs Rust bindings for LMDB Documentation (master branch) Building LMDB is bundled as submodule so update submodules first: git submodule update --

Valerii Hiora 104 Dec 8, 2022
Ergonomic bindings to SQLite for 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 5, 2023
leveldb LevelDB LevelDB skade/leveldb — LevelDB bindings

Rust leveldb bindings Almost-complete bindings for leveldb for Rust. Documentation Rust version policy leveldb is built and tested on stable releases

Florian Gilcher 161 Nov 20, 2022
"KakaoTalk" internal api bindings

talk-api-client "KakaoTalk" internal api bindings Examples Auth See examples/auth.rs To run example, clone this repository and run command cargo run -

storycraft 5 Sep 7, 2022
🧰 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