core
: Add queryable meta
structs
This commit is contained in:
parent
18b3619785
commit
c235467b06
1 changed files with 61 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
use diesel::{Associations, Identifiable, Insertable, Queryable, QueryableByName, Selectable};
|
use diesel::{Associations, Identifiable, Insertable, QueryResult, Queryable, QueryableByName, Selectable};
|
||||||
|
use diesel_async::AsyncPgConnection;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::schema;
|
use super::schema;
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ pub struct MetaLink {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub pattern: String,
|
pub pattern: String,
|
||||||
pub rel: String,
|
pub rel: String,
|
||||||
pub type_: Option<String>,
|
pub r#type: Option<String>,
|
||||||
pub href: Option<String>,
|
pub href: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,3 +39,61 @@ pub struct MetaProperty {
|
||||||
pub pattern: String,
|
pub pattern: String,
|
||||||
pub value: Option<String>,
|
pub value: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl MetaAlias {
|
||||||
|
pub async fn query_matching(conn: &mut AsyncPgConnection, subject: &str) -> QueryResult<Vec<MetaAlias>> {
|
||||||
|
use diesel::prelude::*;
|
||||||
|
use diesel_async::RunQueryDsl;
|
||||||
|
use schema::meta_aliases::dsl::*;
|
||||||
|
|
||||||
|
let subject_matches_pattern = subject.into_sql::<diesel::sql_types::Text>().ilike(pattern);
|
||||||
|
|
||||||
|
meta_aliases
|
||||||
|
.filter(subject_matches_pattern)
|
||||||
|
.select(Self::as_select())
|
||||||
|
.load(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MetaLink {
|
||||||
|
pub async fn query_matching(conn: &mut AsyncPgConnection, subject: &str) -> QueryResult<Vec<MetaLink>> {
|
||||||
|
use diesel::prelude::*;
|
||||||
|
use diesel_async::RunQueryDsl;
|
||||||
|
use schema::meta_links::dsl::*;
|
||||||
|
|
||||||
|
let subject_matches_pattern = subject.into_sql::<diesel::sql_types::Text>().ilike(pattern);
|
||||||
|
|
||||||
|
meta_links
|
||||||
|
.filter(subject_matches_pattern)
|
||||||
|
.select(Self::as_select())
|
||||||
|
.load(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn query_properties(&self, conn: &mut AsyncPgConnection) -> QueryResult<Vec<MetaLinkProperty>> {
|
||||||
|
use diesel::prelude::*;
|
||||||
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
|
MetaLinkProperty::belonging_to(self)
|
||||||
|
.load(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MetaProperty {
|
||||||
|
pub async fn query_matching(conn: &mut AsyncPgConnection, subject: &str) -> QueryResult<Vec<MetaProperty>> {
|
||||||
|
use diesel::prelude::*;
|
||||||
|
use diesel_async::RunQueryDsl;
|
||||||
|
use schema::meta_properties::dsl::*;
|
||||||
|
|
||||||
|
let subject_matches_pattern = subject.into_sql::<diesel::sql_types::Text>().ilike(pattern);
|
||||||
|
|
||||||
|
meta_properties
|
||||||
|
.filter(subject_matches_pattern)
|
||||||
|
.select(Self::as_select())
|
||||||
|
.load(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue