Skip to content

Commit

Permalink
feat: get db struct from a collection
Browse files Browse the repository at this point in the history
  • Loading branch information
fMeow committed Jul 26, 2020
1 parent 0dd3ecc commit 20d2505
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/collection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ impl<'a, C: ClientExt> Collection<C> {
Arc::clone(&self.session)
}

/// Get the db od current collection
pub fn db(&self) -> Database<C> {
// Base url should be like `http://server:port/_db/mydb/_api/collection/{collection-name}`
let mut paths = self.base_url.path_segments().unwrap();
// must be `_db`
paths.next();
// must be db name
let name = paths.next().unwrap();
Database::new(name, &self.url().join("/").unwrap(), self.session())
}

/// Drop a collection
///
/// # Note
Expand Down

0 comments on commit 20d2505

Please sign in to comment.