-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use rusqlite::Connection; | ||
|
||
#[derive(Debug)] | ||
pub struct BlockGroupLineage { | ||
pub id: i32, | ||
pub source_id: i32, | ||
pub target_id: i32, | ||
} | ||
|
||
impl BlockGroupLineage { | ||
pub fn create(conn: &Connection, source_id: i32, target_id: i32) -> BlockGroupLineage { | ||
let query = | ||
"INSERT INTO block_group_lineage (source_id, target_id) VALUES (?1, ?2) RETURNING (id)"; | ||
let mut stmt = conn.prepare(query).unwrap(); | ||
match stmt.query_row((source_id, target_id), |row| { | ||
Ok(BlockGroupLineage { | ||
id: row.get(0)?, | ||
source_id, | ||
target_id, | ||
}) | ||
}) { | ||
Ok(res) => res, | ||
Err(rusqlite::Error::SqliteFailure(err, details)) => { | ||
if err.code == rusqlite::ErrorCode::ConstraintViolation { | ||
println!("{err:?} {details:?}"); | ||
BlockGroupLineage { | ||
id: conn | ||
.query_row( | ||
"select id from block_group_lineage where source_id = ?1 and target_id = ?2", | ||
(source_id, target_id), | ||
|row| row.get(0), | ||
) | ||
.unwrap(), | ||
source_id, | ||
target_id, | ||
} | ||
} else { | ||
panic!("something bad happened querying the database") | ||
} | ||
} | ||
Err(_) => { | ||
panic!("something bad happened querying the database") | ||
} | ||
} | ||
} | ||
} |