Unify database structs
This commit is contained in:
parent
3d8867d218
commit
b6adc918c6
@ -28,7 +28,7 @@ impl Storage {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn flakes(&self) -> Result<Vec<FlakeUri>> {
|
pub async fn flakes(&self) -> Result<Vec<FlakeRow>> {
|
||||||
sqlx::query_as("
|
sqlx::query_as("
|
||||||
SELECT
|
SELECT
|
||||||
flake_uri
|
flake_uri
|
||||||
@ -40,11 +40,15 @@ impl Storage {
|
|||||||
.context("Failed to fetch data from database")
|
.context("Failed to fetch data from database")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn revisions_from_flake(&self, uri: &str) -> Result<Vec<RevisionListModel>> {
|
pub async fn revisions_from_flake(&self, uri: &str) -> Result<Vec<RevisionRow>> {
|
||||||
sqlx::query_as("
|
sqlx::query_as("
|
||||||
SELECT
|
SELECT
|
||||||
revision_uri,
|
revision_uri,
|
||||||
last_modified
|
flake_uri,
|
||||||
|
nix_store_path,
|
||||||
|
nar_hash,
|
||||||
|
last_modified,
|
||||||
|
tracker_last_scanned
|
||||||
FROM revisions
|
FROM revisions
|
||||||
WHERE flake_uri = ?
|
WHERE flake_uri = ?
|
||||||
ORDER BY last_modified DESC
|
ORDER BY last_modified DESC
|
||||||
@ -55,7 +59,7 @@ impl Storage {
|
|||||||
.context("Failed to fetch data from database")
|
.context("Failed to fetch data from database")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn inputs_for_revision(&self, revision_uri: &str) -> Result<Vec<InputModel>> {
|
pub async fn inputs_for_revision(&self, revision_uri: &str) -> Result<Vec<InputRow>> {
|
||||||
sqlx::query_as("
|
sqlx::query_as("
|
||||||
SELECT
|
SELECT
|
||||||
revision_uri,
|
revision_uri,
|
||||||
@ -74,7 +78,7 @@ impl Storage {
|
|||||||
.context("Failed to fetch data from database")
|
.context("Failed to fetch data from database")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn input_of_for_revision(&self, revision_uri: &str) -> Result<Vec<InputModel>> {
|
pub async fn input_of_for_revision(&self, revision_uri: &str) -> Result<Vec<InputRow>> {
|
||||||
sqlx::query_as("
|
sqlx::query_as("
|
||||||
SELECT
|
SELECT
|
||||||
revision_uri,
|
revision_uri,
|
||||||
@ -93,14 +97,17 @@ impl Storage {
|
|||||||
.context("Failed to fetch data from database")
|
.context("Failed to fetch data from database")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn current_inputs_for_flake(&self, flake_uri: &str) -> Result<Vec<InputForFlakeRow>> {
|
pub async fn current_inputs_for_flake(&self, flake_uri: &str) -> Result<Vec<InputRow>> {
|
||||||
sqlx::query_as("
|
sqlx::query_as("
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
revisions.revision_uri,
|
revisions.revision_uri,
|
||||||
MAX(revisions.last_modified) AS last_modified,
|
|
||||||
inputs.input_name,
|
inputs.input_name,
|
||||||
inputs.locked_flake_uri
|
inputs.locked_revision_uri,
|
||||||
|
inputs.locked_flake_uri,
|
||||||
|
inputs.locked_nar_hash,
|
||||||
|
inputs.last_modified,
|
||||||
|
MAX(revisions.last_modified)
|
||||||
FROM
|
FROM
|
||||||
revisions
|
revisions
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
@ -120,57 +127,30 @@ impl Storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromRow)]
|
#[derive(FromRow)]
|
||||||
pub struct FlakeRevisionRow {
|
pub struct RevisionRow {
|
||||||
pub revision_uri: String,
|
pub revision_uri: String,
|
||||||
pub flake_uri: Option<String>,
|
pub flake_uri: Option<String>,
|
||||||
pub nix_store_path: Option<String>,
|
pub nix_store_path: Option<String>,
|
||||||
pub nar_hash: Option<String>,
|
pub nar_hash: Option<String>,
|
||||||
pub last_modified: Option<i64>,
|
pub last_modified: Option<i64>,
|
||||||
|
pub tracker_last_scanned: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromRow)]
|
impl RevisionRow {
|
||||||
pub struct InputForFlakeRow {
|
pub fn revision_link(&self) -> String {
|
||||||
pub revision_uri: String,
|
format!("/r/{}", urlencode(&self.revision_uri))
|
||||||
pub last_modified: Option<i64>,
|
}
|
||||||
pub input_name: String,
|
|
||||||
pub locked_flake_uri: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl InputForFlakeRow {
|
pub fn flake_link(&self) -> String {
|
||||||
pub fn locked_flake_link(&self ) -> String {
|
match &self.flake_uri {
|
||||||
match &self.locked_flake_uri {
|
Some(flake_uri) => format!("/f/{}", urlencode(&flake_uri)),
|
||||||
Some(locked_flake_uri) => format!("/f/{}", urlencode(&locked_flake_uri)),
|
|
||||||
None => String::from("#"),
|
None => String::from("#"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(FromRow)]
|
#[derive(FromRow)]
|
||||||
pub struct RevisionListModel {
|
pub struct InputRow {
|
||||||
pub revision_uri: String,
|
|
||||||
pub last_modified: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RevisionListModel {
|
|
||||||
pub fn revision_link(&self ) -> String {
|
|
||||||
format!("/r/{}", urlencode(&self.revision_uri))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(FromRow)]
|
|
||||||
pub struct FlakeUri {
|
|
||||||
pub flake_uri: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FlakeUri {
|
|
||||||
pub fn flake_link(&self ) -> String {
|
|
||||||
format!("/f/{}", urlencode(&self.flake_uri))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(FromRow)]
|
|
||||||
pub struct InputModel {
|
|
||||||
pub revision_uri: String,
|
pub revision_uri: String,
|
||||||
pub input_name: String,
|
pub input_name: String,
|
||||||
pub locked_revision_uri: Option<String>,
|
pub locked_revision_uri: Option<String>,
|
||||||
@ -179,7 +159,7 @@ pub struct InputModel {
|
|||||||
pub last_modified: Option<i64>,
|
pub last_modified: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputModel {
|
impl InputRow {
|
||||||
pub fn revision_link(&self) -> String {
|
pub fn revision_link(&self) -> String {
|
||||||
format!("/r/{}", urlencode(&self.revision_uri))
|
format!("/r/{}", urlencode(&self.revision_uri))
|
||||||
}
|
}
|
||||||
@ -198,3 +178,15 @@ impl InputModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(FromRow)]
|
||||||
|
pub struct FlakeRow {
|
||||||
|
pub flake_uri: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FlakeRow {
|
||||||
|
pub fn flake_link(&self ) -> String {
|
||||||
|
format!("/f/{}", urlencode(&self.flake_uri))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -3,10 +3,9 @@ use askama::{
|
|||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
storage::{
|
storage::{
|
||||||
FlakeUri,
|
FlakeRow,
|
||||||
InputModel,
|
InputRow,
|
||||||
InputForFlakeRow,
|
RevisionRow,
|
||||||
RevisionListModel,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -18,21 +17,21 @@ pub struct IndexTemplate {
|
|||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "flakes.html")]
|
#[template(path = "flakes.html")]
|
||||||
pub struct FlakesTemplate {
|
pub struct FlakesTemplate {
|
||||||
pub flakes: Vec<FlakeUri>,
|
pub flakes: Vec<FlakeRow>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "flake.html")]
|
#[template(path = "flake.html")]
|
||||||
pub struct FlakeTemplate {
|
pub struct FlakeTemplate {
|
||||||
pub uri: String,
|
pub uri: String,
|
||||||
pub revisions: Vec<RevisionListModel>,
|
pub revisions: Vec<RevisionRow>,
|
||||||
pub current_inputs: Vec<InputForFlakeRow>,
|
pub current_inputs: Vec<InputRow>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "revision.html")]
|
#[template(path = "revision.html")]
|
||||||
pub struct RevisionTemplate {
|
pub struct RevisionTemplate {
|
||||||
pub revision_uri: String,
|
pub revision_uri: String,
|
||||||
pub inputs: Vec<InputModel>,
|
pub inputs: Vec<InputRow>,
|
||||||
pub input_of: Vec<InputModel>,
|
pub input_of: Vec<InputRow>,
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{% for revision in revisions %}
|
{% for revision in revisions %}
|
||||||
<li><a href="{{ revision.revision_link() }}">{{ revision.revision_uri }}</a> ({{ revision.last_modified }})</li>
|
<li><a href="{{ revision.revision_link() }}">{{ revision.revision_uri }}</a> {% match revision.last_modified %}{% when Some with (last_modified) %}({{ last_modified }}){% when None %}{% endmatch %}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user