Crates.io | merkle-tree-bulletin-board-backend-mysql |
lib.rs | merkle-tree-bulletin-board-backend-mysql |
version | 0.3.0 |
source | src |
created_at | 2021-11-23 03:29:00.155285 |
updated_at | 2023-03-10 11:55:36.220403 |
description | A mysql backend for merkle-tree-bulletin-board. |
homepage | https://github.com/RightToAskOrg/bulletin-board |
repository | https://github.com/RightToAskOrg/bulletin-board |
max_upload_size | |
id | 486021 |
size | 76,866 |
This is a mysql/mariadb based backend for the merkle-tree-bulletin-board crate.
It is partly present as a demonstration of how a sql based backend could be, but it is also usable in its own right.
A provided binary test_mysql is available; this is only for demo purposes and has no function in a production system.
I am not a SQL tuning expert; this is not as careful code as the merkle-tree-bulletin-board crate, however every operation is O(mysql single indexed operation)*O(data size) and data size is generally O(log bulletin board size). That is, no operation should take long.
Define some function to get a mysql connection to the data base such as
fn get_bulletin_board_connection() -> Conn {
let opts = Opts::from_url(&CONFIG.database.bulletinboard).expect("Could not parse bulletin_board_url url");
Conn::new(opts).expect("Could not connect to bulletin board database")
}
Then initialise the database with something such as
/// Delete all data and recreate the schema.
pub fn initialize_bulletin_board_database() -> anyhow::Result<()> {
let mut conn = get_bulletin_board_connection();
conn.query_drop("drop table if exists PUBLISHED_ROOTS")?;
conn.query_drop("drop table if exists PUBLISHED_ROOT_REFERENCES")?;
conn.query_drop("drop table if exists BRANCH")?;
conn.query_drop("drop table if exists LEAF")?;
let schema = merkle_tree_bulletin_board_backend_mysql::SCHEMA;
conn.query_drop(schema)?;
Ok(())
}
Then create a backend by something like
let conn = get_bulletin_board_connection();
let backend = merkle_tree_bulletin_board_backend_mysql::BackendMysql{ connection: std::sync::Mutex::new(Box::new(conn)) };
Copyright 2021 Thinking Cybersecurity Pty. Ltd.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
0.2: Change of mysql version in dependencies. Old version had a transitive dependency funty 1.2 that was yanked.
0.3: Change to match 0.3 bulletin board - better error handling (API change for errors).