zcash_client_sqlite::query::get_address()
This commit is contained in:
28
zcash_client_sqlite/src/query.rs
Normal file
28
zcash_client_sqlite/src/query.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
//! Functions for querying information in the data database.
|
||||
|
||||
use rusqlite::Connection;
|
||||
use std::path::Path;
|
||||
|
||||
use crate::error::Error;
|
||||
|
||||
/// Returns the address for the account.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use zcash_client_sqlite::query::get_address;
|
||||
///
|
||||
/// let addr = get_address("/path/to/data.db", 0);
|
||||
/// ```
|
||||
pub fn get_address<P: AsRef<Path>>(db_data: P, account: u32) -> Result<String, Error> {
|
||||
let data = Connection::open(db_data)?;
|
||||
|
||||
let addr = data.query_row(
|
||||
"SELECT address FROM accounts
|
||||
WHERE account = ?",
|
||||
&[account],
|
||||
|row| row.get(0),
|
||||
)?;
|
||||
|
||||
Ok(addr)
|
||||
}
|
||||
Reference in New Issue
Block a user