|
1 | 1 | MonetDB bindings for Rust |
2 | 2 | ========================= |
| 3 | + |
| 4 | +Rust client for the [MonetDB](https://www.monetdb.org/) analytics database. |
| 5 | + |
| 6 | +Note: this crate is in its early stages. The basics seem to work but a lot has |
| 7 | +not been implemented yet and the API may change in incompatible ways at any |
| 8 | +time. |
| 9 | + |
| 10 | +Examples |
| 11 | +-------- |
| 12 | + |
| 13 | +```rust |
| 14 | +use std::error::Error; |
| 15 | +use monetdb::Connection; |
| 16 | + |
| 17 | +fn main() -> Result<(), Box<dyn Error>> { |
| 18 | + let url = "monetdb:///demo?user=monetdb&password=monetdb"; |
| 19 | + let conn = Connection::connect_url(url)?; |
| 20 | + let mut cursor = conn.cursor(); |
| 21 | + |
| 22 | + cursor.execute("SELECT hostname, clientpid, client, remark FROM sys.sessions")?; |
| 23 | + while cursor.next_row()? { |
| 24 | + // getters return Option< >, None means NULL |
| 25 | + let hostname: Option<&str> = cursor.get_str(0)?; |
| 26 | + let clientpid: Option<u32> = cursor.get_u32(1)?; |
| 27 | + let client: Option<&str> = cursor.get_str(2)?; |
| 28 | + let remark: Option<&str> = cursor.get_str(3)?; // usually NULL |
| 29 | + println!("host={hostname:?} clientpid={clientpid:?} client={client:?} remark={remark:?}",); |
| 30 | + } |
| 31 | + Ok(()) |
| 32 | +} |
| 33 | + |
| 34 | +// Example output: |
| 35 | +// host=Some("totoro") clientpid=Some(1895691) client=Some("libmapi 11.51.4") remark=None |
| 36 | +// host=Some("totoro") clientpid=Some(1914127) client=Some("monetdb-rust 0.1.1") remark=None |
| 37 | +``` |
| 38 | + |
| 39 | +You can also use a [`Parameters`] object to fine tune the connection parameters: |
| 40 | + |
| 41 | +```rust |
| 42 | +# use std::error::Error; |
| 43 | +use monetdb::{Parameters, Connection}; |
| 44 | +# fn main() -> Result<(), Box<dyn Error>> { |
| 45 | +let parms = Parameters::basic("demo", "monetdb", "monetdb")? // database / user / password |
| 46 | + .with_autocommit(false)?; |
| 47 | +let conn = Connection::new(parms)?; |
| 48 | +# Ok(()) |
| 49 | +# } |
| 50 | +``` |
| 51 | + |
| 52 | +Current status |
| 53 | +-------------- |
| 54 | + |
| 55 | +* Support for MonetDB Jun2020 (11.37.7) and higher. Older versions are highly |
| 56 | + likely to work but haven't been tested. If you need this, just ask. |
| 57 | + |
| 58 | +* Rust 1.81 and higher. (TODO: check this) |
| 59 | + |
| 60 | +* The full `monetdb://` connection URL syntax is supported, though not all features have been implemented. |
| 61 | + |
| 62 | +* Most data types can be retrieved in string form using `get_str()`. |
| 63 | + Exception: blobs |
| 64 | + |
| 65 | +* The primitive types bool, i8/u8, i16/u16, i32/u32, i64/u64, i128/u128, |
| 66 | + isize/usize, f32/f64 have typed getters, for example `get_i8()`. |
| 67 | + |
| 68 | +* A single call to `Cursor::execute()` can return multiple result sets. |
| 69 | + |
| 70 | +* extremely basic and untested TLS (`monetdbs://`) support can optionally be |
| 71 | + compiled in. |
| 72 | + |
| 73 | +Not implemented yet but planned: |
| 74 | + |
| 75 | +* parametrized queries |
| 76 | + |
| 77 | +* start transaction / commit / rollback |
| 78 | + |
| 79 | +* typed getters for decimal and temporal types |
| 80 | + |
| 81 | +* BLOB support |
| 82 | + |
| 83 | +* Full TLS support |
| 84 | + |
| 85 | +* file transfers |
| 86 | + |
| 87 | +* Binary result set |
| 88 | + |
| 89 | +* Adaptive paging window sizes |
| 90 | + |
| 91 | +* scanning /tmp for Unix Domain sockets |
| 92 | + |
| 93 | +* Non-SQL, for example language=mal for MonetDB's tracing / profiling API |
| 94 | + |
| 95 | +* PREPARE STATEMENT |
| 96 | + |
| 97 | +* Async, seems to be needed for [sqlx] |
| 98 | + |
| 99 | +* Integration with database frameworks such as [sqlx] and [Diesel]. |
| 100 | + There does not seem to be a JDBC equivalent for Rust. |
| 101 | + |
| 102 | +[sqlx]: https://crates.io/crates/sqlx |
| 103 | + |
| 104 | +[Diesel]: https://crates.io/crates/diesel |
| 105 | + |
| 106 | +Optional features |
| 107 | +----------------- |
| 108 | + |
| 109 | +The `monetdb` crate currently defines one optional feature: |
| 110 | + |
| 111 | +* **rustls** Enable a first stab at supporting TLS connections using |
| 112 | + [rustls](https://crates.io/crates/rustls/). The TLS-related configuration |
| 113 | + parameters such as `cert=` and `clientkey=` aren't supported yet and there is |
| 114 | + no testing, but a basic `monetdbs://` URL seems to work. |
| 115 | + To try it, pass it on the command line like this: |
| 116 | + ```plain |
| 117 | + cargo run --features=rustls --example testconnect -- monetdbs://my.tls.host/demo |
| 118 | + ``` |
| 119 | + or enable it in your application's Cargo.toml like this: |
| 120 | + ```plain |
| 121 | + [dependencies] |
| 122 | + monetdb = { version="0.1.1", features=["rustls"]} |
| 123 | + ``` |
0 commit comments