Skip to content

Commit

Permalink
Merge pull request #181 from darnuria/fix/163
Browse files Browse the repository at this point in the history
Fixes the documentation and examples of the append methods
  • Loading branch information
Kerollmops committed Jul 11, 2023
2 parents 2a8ae11 + 4d6fc46 commit 880d621
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
13 changes: 8 additions & 5 deletions heed/src/db/polymorph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ impl PolyDatabase {
/// Append the given key/data pair to the end of the database.
///
/// This option allows fast bulk loading when keys are already known to be in the correct order.
/// Loading unsorted keys will cause a MDB_KEYEXIST error.
/// Loading unsorted keys will cause a `KeyExist`/`MDB_KEYEXIST` error.
///
/// ```
/// # use std::fs;
Expand All @@ -1599,14 +1599,17 @@ impl PolyDatabase {
/// let db = env.create_poly_database(&mut wtxn, Some("append-i32"))?;
///
/// # db.clear(&mut wtxn)?;
/// db.put::<BEI32, Str>(&mut wtxn, &13, "i-am-thirteen")?;
/// db.put::<BEI32, Str>(&mut wtxn, &27, "i-am-twenty-seven")?;
/// db.put::<BEI32, Str>(&mut wtxn, &42, "i-am-forty-two")?;
/// db.put::<BEI32, Str>(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;
/// db.append::<BEI32, Str>(&mut wtxn, &13, "i-am-thirteen")?;
/// db.append::<BEI32, Str>(&mut wtxn, &27, "i-am-twenty-seven")?;
/// db.append::<BEI32, Str>(&mut wtxn, &42, "i-am-forty-two")?;
/// db.append::<BEI32, Str>(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;
///
/// let ret = db.get::<BEI32, Str>(&mut wtxn, &27)?;
/// assert_eq!(ret, Some("i-am-twenty-seven"));
///
/// // Be wary if you insert at the end unsorted you get the KEYEXIST error.
/// assert!(db.append::<BEI32, Str>(&mut wtxn, &1, "Oh No").is_err());
///
/// wtxn.commit()?;
/// # Ok(()) }
/// ```
Expand Down
13 changes: 8 additions & 5 deletions heed/src/db/uniform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ impl<KC, DC> Database<KC, DC> {
/// Append the given key/data pair to the end of the database.
///
/// This option allows fast bulk loading when keys are already known to be in the correct order.
/// Loading unsorted keys will cause a MDB_KEYEXIST error.
/// Loading unsorted keys will cause a `KeyExist`/`MDB_KEYEXIST` error.
///
/// ```
/// # use std::fs;
Expand All @@ -1326,14 +1326,17 @@ impl<KC, DC> Database<KC, DC> {
/// let db: Database<BEI32, Str> = env.create_database(&mut wtxn, Some("iter-i32"))?;
///
/// # db.clear(&mut wtxn)?;
/// db.put(&mut wtxn, &13, "i-am-thirteen")?;
/// db.put(&mut wtxn, &27, "i-am-twenty-seven")?;
/// db.put(&mut wtxn, &42, "i-am-forty-two")?;
/// db.put(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;
/// db.append(&mut wtxn, &13, "i-am-thirteen")?;
/// db.append(&mut wtxn, &27, "i-am-twenty-seven")?;
/// db.append(&mut wtxn, &42, "i-am-forty-two")?;
/// db.append(&mut wtxn, &521, "i-am-five-hundred-and-twenty-one")?;
///
/// let ret = db.get(&mut wtxn, &27)?;
/// assert_eq!(ret, Some("i-am-twenty-seven"));
///
/// // Be wary if you insert at the end unsorted you get the KEYEXIST error.
/// assert!(db.append(&mut wtxn, &1, "Oh No").is_err());
///
/// wtxn.commit()?;
/// # Ok(()) }
/// ```
Expand Down
3 changes: 3 additions & 0 deletions heed/src/mdb/lmdb_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use lmdb_master_sys as ffi;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Error {
/// key/data pair already exists.
///
/// May be also returned by append functions, data are passed
/// doesn't respect the database ordering.
KeyExist,
/// key/data pair not found (EOF).
NotFound,
Expand Down

0 comments on commit 880d621

Please sign in to comment.