Skip to content

Commit 759269d

Browse files
committed
bindings/rust: test methods on rusqlite::Transaction
1 parent fc91f67 commit 759269d

3 files changed

Lines changed: 38 additions & 27 deletions

File tree

bindings/rust/src/lib.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ pub struct RefSeq {
170170
}
171171

172172
/// Methods for GenomicSQLite [rusqlite::Connection]s; see [Programming Guide](https://mlin.github.io/GenomicSQLite/guide/#tuning-options)
173+
/// for each method's semantics. The methods can also be invoked on an open
174+
/// [rusqlite::Transaction], via its implicit `Deref<Target=Connection>`.
173175
pub trait ConnectionMethods {
174176
/// Get Genomics Extension version
175177
fn genomicsqlite_version(&self) -> String;
@@ -415,7 +417,7 @@ mod tests {
415417
);
416418
let mut config = json::object::Object::new();
417419
config.insert("threads", json::JsonValue::from(3));
418-
let conn = super::open(
420+
let mut conn = super::open(
419421
dbfn,
420422
OpenFlags::SQLITE_OPEN_CREATE | OpenFlags::SQLITE_OPEN_READ_WRITE,
421423
&config,
@@ -428,18 +430,25 @@ mod tests {
428430
.unwrap();
429431
assert_eq!(ans, 3);
430432

431-
// load table & create GRI
432-
conn.execute_batch(
433-
"CREATE TABLE feature(rid INTEGER, beg INTEGER, end INTEGER);
434-
INSERT INTO feature VALUES(3, 12, 34);
435-
INSERT INTO feature VALUES(3, 0, 23);
436-
INSERT INTO feature VALUES(3, 34, 56)",
437-
)
438-
.unwrap();
439-
let gri_sql = conn
440-
.create_genomic_range_index_sql("feature", "rid", "beg", "end")
433+
// begin transaction
434+
{
435+
let txn = conn.transaction().unwrap();
436+
437+
// load table & create GRI
438+
txn.execute_batch(
439+
"CREATE TABLE feature(rid INTEGER, beg INTEGER, end INTEGER);
440+
INSERT INTO feature VALUES(3, 12, 34);
441+
INSERT INTO feature VALUES(3, 0, 23);
442+
INSERT INTO feature VALUES(3, 34, 56)",
443+
)
441444
.unwrap();
442-
conn.execute_batch(&gri_sql).unwrap();
445+
let gri_sql = txn
446+
.create_genomic_range_index_sql("feature", "rid", "beg", "end")
447+
.unwrap();
448+
txn.execute_batch(&gri_sql).unwrap();
449+
450+
txn.commit().unwrap();
451+
}
443452

444453
// GRI query
445454
ans = conn

docs/guide.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,35 @@ The Genomics Extension integrates with your programming language's existing SQLi
2828
use rusqlite::{Connection, OpenFlags, params, NO_PARAMS};
2929
```
3030

31+
The `genomicsqlite::ConnectionMethods` trait makes available GenomicSQLite-specific methods for
32+
`rusqlite::Connection` (and `rusqlite::Transaction`). See [rustdoc](https://docs.rs/genomicsqlite)
33+
for some extra details.
34+
3135
=== "C++"
3236
``` c++
33-
// link program to sqlite3 and genomicsqlite libraries; optionally, SQLiteCpp:
34-
// https://github.com/SRombauts/SQLiteCpp
3537
#include <sqlite3.h>
3638
#include "SQLiteCpp/SQLiteCpp.h" // optional
3739
#include "genomicsqlite.h"
38-
39-
// General note: most GenomicSQLite C++ routines are liable to throw.
4040
```
4141

42+
Link the program to `sqlite3` and `genomicsqlite` libraries; optionally,
43+
[SQLiteCpp](https://github.com/SRombauts/SQLiteCpp).
44+
45+
General note: GenomicSQLite C++ routines are liable to throw exceptions.
46+
4247
=== "C"
4348
``` c
44-
/* link program to sqlite3 and genomicsqlite libraries */
4549
#include <sqlite3.h>
4650
#include "genomicsqlite.h"
47-
48-
/* General note: all GenomicSQLite C routines returning a char* string use
49-
* the following convention:
50-
* If the operation suceeds then it's a nonempty, null-terminated string.
51-
* Otherwise it points to a null byte followed immediately by a nonempty,
52-
* null-terminated error message.
53-
* IN EITHER CASE, the caller should free the string with sqlite3_free().
54-
* Null is returned only if malloc failed.
55-
*/
5651
```
5752

53+
Link the program to `sqlite3` and `genomicsqlite` libraries.
54+
55+
All GenomicSQLite C routines returning a `char*` string use the following convention. If the
56+
operation succeeds, then it's a nonempty, null-terminated string. Otherwise, it points to a
57+
null byte followed immediately by a nonempty, null-terminated error message. *In either case,*
58+
the caller must free the string with `sqlite3_free()`. NULL is returned only if out of memory.
59+
5860
## Opening a compressed database
5961

6062
**↪ GenomicSQLite Open:** create or open a compressed database, returning a connection object with various settings pre-tuned for large datasets.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ It's usually easiest to obtain the extension as a pre-compiled shared library (L
7575
version = "^0"
7676
```
7777

78-
The crate will build a bundled shared library file appropriate for your platform into your compilation unit. To disable this, add `default-features = false` and at runtime, set environment variable `LIBGENOMICSQLITE` to a filename or place the library file somewhere it'll be found by `dlopen("libgenomicsqlite")`.
78+
Building with the crate will include a platform-appropriate shared library file within your compilation unit, to be extracted & loaded at runtime. To disable this, add `default-features = false` and at runtime, set environment variable `LIBGENOMICSQLITE` to a filename or place the library file somewhere it'll be found by `dlopen("libgenomicsqlite")`.
7979

8080
=== "C/C++"
8181
Download zip of shared library and `genomicsqlite.h` from [GitHub Releases](https://github.com/mlin/GenomicSQLite/releases). Build your program with them, and also ensure the dynamic linker will find the shared library at runtime, by either: (1) installing it in a system or user lib directory & refreshing cache, (2) setting `LD_LIBRARY_PATH` environment variable, (3) building with `-rpath`.

0 commit comments

Comments
 (0)