-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update data model to handle feature environments + start server refactor
- Loading branch information
1 parent
d2fe4de
commit 5182ce3
Showing
15 changed files
with
238 additions
and
79 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
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
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,43 @@ | ||
pub use super::*; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct Environment { | ||
pub id: String, | ||
pub name: String, | ||
pub project_id: String | ||
} | ||
|
||
impl Environment { | ||
pub async fn new(pool: &SqlitePool, name: impl Into<String>, project_id: &String) -> Result<Environment, sqlx::Error> { | ||
let id = gen::id(); | ||
let name: String = name.into(); | ||
sqlx::query_as!( | ||
Environment, | ||
r#" | ||
INSERT INTO environment | ||
(id, name, project_id) | ||
VALUES | ||
(?, ?, ?) | ||
RETURNING *; | ||
"#, | ||
id, | ||
name, | ||
project_id, | ||
) | ||
.fetch_one(pool) | ||
.await | ||
} | ||
|
||
pub async fn connect_feature(self, pool: &SqlitePool, feature_id: String) -> Result<String, sqlx::Error> { | ||
let id = gen::id(); | ||
sqlx::query!( | ||
"INSERT INTO environment_feature (id, environment_id, feature_id, active) VALUES (?, ?, ?, ?) RETURNING id", | ||
id, | ||
self.id, | ||
feature_id, | ||
false | ||
) | ||
.fetch_one(pool) | ||
.await.map(|rec| rec.id) | ||
} | ||
} |
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,15 @@ | ||
pub use super::*; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct Feature { | ||
pub id: String, | ||
pub project_id: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct EnvironmentFeature { | ||
pub id: String, | ||
pub active: bool, | ||
pub feature_id: String, | ||
pub environment_id: String | ||
} |
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,13 @@ | ||
pub mod environment; | ||
pub use environment::Environment; | ||
|
||
pub mod feature; | ||
pub use feature::Feature; | ||
|
||
pub mod project; | ||
pub use project::Project; | ||
|
||
pub use serde::{Deserialize, Serialize}; | ||
pub use sqlx::SqlitePool; | ||
|
||
pub use crate::gen; |
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,20 @@ | ||
use super::*; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct Project { | ||
pub id: Option<String>, | ||
pub name: String, | ||
pub user_id: String, | ||
} | ||
|
||
impl Project { | ||
pub async fn load_envs(project_id: String, pool: &SqlitePool) -> Result<Vec<Environment>, sqlx::Error> { | ||
sqlx::query_as!( | ||
Environment, | ||
"SELECT * FROM environment WHERE project_id = ?;", | ||
project_id | ||
) | ||
.fetch_all(pool) | ||
.await | ||
} | ||
} |
Oops, something went wrong.