mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
implement existing certificate selection
This commit is contained in:
parent
10cf4fc6a1
commit
728a9c06d5
9 changed files with 189 additions and 41 deletions
|
|
@ -27,6 +27,27 @@ impl Database {
|
|||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Create new record in database
|
||||
pub fn add(&self, pem: &str, name: Option<&str>) -> Result<i64, Error> {
|
||||
// Begin new transaction
|
||||
let mut writable = self.connection.write().unwrap(); // @TODO
|
||||
let tx = writable.transaction()?;
|
||||
|
||||
// Create new record
|
||||
insert(&tx, *self.profile_identity_id, pem, name)?;
|
||||
|
||||
// Hold insert ID for result
|
||||
let id = last_insert_id(&tx);
|
||||
|
||||
// Done
|
||||
match tx.commit() {
|
||||
Ok(_) => Ok(id),
|
||||
Err(reason) => Err(reason),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all records match current `profile_identity_id`
|
||||
pub fn records(&self) -> Result<Vec<Table>, Error> {
|
||||
let readable = self.connection.read().unwrap(); // @TODO
|
||||
|
|
@ -56,6 +77,22 @@ pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn insert(
|
||||
tx: &Transaction,
|
||||
profile_identity_id: i64,
|
||||
pem: &str,
|
||||
name: Option<&str>,
|
||||
) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
"INSERT INTO `profile_identity_gemini` (
|
||||
`profile_identity_id`,
|
||||
`pem`,
|
||||
`name`
|
||||
) VALUES (?, ?, ?)",
|
||||
(profile_identity_id, pem, name),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn select(tx: &Transaction, profile_identity_id: i64) -> Result<Vec<Table>, Error> {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT `id`,
|
||||
|
|
@ -84,3 +121,7 @@ pub fn select(tx: &Transaction, profile_identity_id: i64) -> Result<Vec<Table>,
|
|||
|
||||
Ok(records)
|
||||
}
|
||||
|
||||
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||
tx.last_insert_rowid()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue