-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
7 changed files
with
77 additions
and
17 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
CREATE TABLE conf( | ||
id INTEGER PRIMARY KEY NOT NULL, | ||
paywall_add_element_comment_price_sat TEXT NOT NULL, | ||
paywall_boost_element_30d_price_sat TEXT NOT NULL, | ||
paywall_boost_element_90d_price_sat TEXT NOT NULL, | ||
paywall_boost_element_365d_price_sat TEXT NOT NULL | ||
paywall_add_element_comment_price_sat INTEGER NOT NULL, | ||
paywall_boost_element_30d_price_sat INTEGER NOT NULL, | ||
paywall_boost_element_90d_price_sat INTEGER NOT NULL, | ||
paywall_boost_element_365d_price_sat INTEGER NOT NULL | ||
) STRICT; | ||
|
||
INSERT INTO conf (paywall_add_element_comment_price_sat, paywall_boost_element_30d_price_sat, paywall_boost_element_90d_price_sat, paywall_boost_element_365d_price_sat) VALUES (500, 5000, 10000, 30000); |
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 crate::Result; | ||
use deadpool_sqlite::Pool; | ||
use rusqlite::{Connection, Row}; | ||
|
||
pub struct Conf { | ||
pub paywall_add_element_comment_price_sat: i64, | ||
pub paywall_boost_element_30d_price_sat: i64, | ||
pub paywall_boost_element_90d_price_sat: i64, | ||
pub paywall_boost_element_365d_price_sat: i64, | ||
} | ||
|
||
const TABLE_NAME: &str = "conf"; | ||
|
||
const MAPPER_PROJECTION: &str = "paywall_add_element_comment_price_sat, paywall_boost_element_30d_price_sat, paywall_boost_element_90d_price_sat, paywall_boost_element_365d_price_sat"; | ||
|
||
impl Conf { | ||
pub async fn select_async(pool: &Pool) -> Result<Conf> { | ||
pool.get() | ||
.await? | ||
.interact(|conn| Conf::select(conn)) | ||
.await? | ||
} | ||
|
||
pub fn select(conn: &Connection) -> Result<Conf> { | ||
let sql = format!( | ||
r#" | ||
SELECT {MAPPER_PROJECTION} | ||
FROM {TABLE_NAME}; | ||
"# | ||
); | ||
conn.prepare(&sql)? | ||
.query_row({}, mapper()) | ||
.map_err(Into::into) | ||
} | ||
} | ||
|
||
const fn mapper() -> fn(&Row) -> rusqlite::Result<Conf> { | ||
|row: &Row| -> rusqlite::Result<Conf> { | ||
Ok(Conf { | ||
paywall_add_element_comment_price_sat: row.get(0)?, | ||
paywall_boost_element_30d_price_sat: row.get(1)?, | ||
paywall_boost_element_90d_price_sat: row.get(2)?, | ||
paywall_boost_element_365d_price_sat: row.get(3)?, | ||
}) | ||
} | ||
} |
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
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