-
Notifications
You must be signed in to change notification settings - Fork 21
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
1 parent
01bc9f5
commit bf47e8f
Showing
10 changed files
with
274 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
DROP TABLE fedimint; | ||
DROP TABLE profile; |
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,57 @@ | ||
use crate::db_models::schema::fedimint; | ||
use diesel::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive( | ||
QueryableByName, Queryable, AsChangeset, Serialize, Deserialize, Debug, Clone, PartialEq, | ||
)] | ||
#[diesel(table_name = fedimint)] | ||
pub struct Fedimint { | ||
pub id: String, | ||
pub value: Vec<u8>, | ||
} | ||
|
||
impl Fedimint { | ||
pub fn get_value(conn: &mut SqliteConnection, id: String) -> anyhow::Result<Option<Vec<u8>>> { | ||
Ok(fedimint::table | ||
.filter(fedimint::id.eq(id)) | ||
.first::<Fedimint>(conn) | ||
.optional()? | ||
.map(|v| v.value)) | ||
} | ||
|
||
pub fn update(&self, conn: &mut SqliteConnection) -> anyhow::Result<()> { | ||
let _ = diesel::update(fedimint::table) | ||
.filter(fedimint::id.eq(self.id.clone())) | ||
.set(fedimint::value.eq(self.value.clone())) | ||
.execute(conn)?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Insertable)] | ||
#[diesel(table_name = fedimint)] | ||
pub struct NewFedimint { | ||
pub id: String, | ||
pub value: Vec<u8>, | ||
} | ||
|
||
impl From<&NewFedimint> for Fedimint { | ||
fn from(new_fedimint: &NewFedimint) -> Self { | ||
Fedimint { | ||
id: new_fedimint.id.clone(), | ||
value: new_fedimint.value.clone(), | ||
} | ||
} | ||
} | ||
|
||
impl NewFedimint { | ||
pub fn insert(&self, conn: &mut SqliteConnection) -> anyhow::Result<Fedimint> { | ||
let _ = diesel::insert_into(fedimint::table) | ||
.values(self) | ||
.execute(conn)?; | ||
|
||
Ok(self.into()) | ||
} | ||
} |
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,4 +1,7 @@ | ||
pub mod profile; | ||
pub use profile::*; | ||
|
||
pub mod fedimint; | ||
pub use fedimint::*; | ||
|
||
pub mod schema; |
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,8 +1,20 @@ | ||
// @generated automatically by Diesel CLI. | ||
|
||
diesel::table! { | ||
fedimint (id) { | ||
id -> Text, | ||
value -> Binary, | ||
} | ||
} | ||
|
||
diesel::table! { | ||
profile (id) { | ||
id -> Text, | ||
seed_words -> Text, | ||
} | ||
} | ||
|
||
diesel::allow_tables_to_appear_in_same_query!( | ||
fedimint, | ||
profile, | ||
); |
Oops, something went wrong.