165 lines
4.5 KiB
Rust
165 lines
4.5 KiB
Rust
use diesel::{Associations, Identifiable, Insertable, QueryResult, Queryable, QueryableByName, Selectable, pg::Pg};
|
|
use diesel_async::AsyncPgConnection;
|
|
use uuid::Uuid;
|
|
use super::schema;
|
|
|
|
|
|
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)]
|
|
#[diesel(table_name = schema::meta_subjects)]
|
|
#[diesel(check_for_backend(Pg))]
|
|
pub struct MetaSubject {
|
|
pub id: Uuid,
|
|
pub document: String,
|
|
pub pattern: String,
|
|
pub redirect: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)]
|
|
#[diesel(table_name = schema::meta_aliases)]
|
|
#[diesel(check_for_backend(Pg))]
|
|
pub struct MetaAlias {
|
|
pub id: Uuid,
|
|
pub document: String,
|
|
pub pattern: String,
|
|
pub alias: String,
|
|
}
|
|
|
|
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)]
|
|
#[diesel(table_name = schema::meta_links)]
|
|
#[diesel(check_for_backend(Pg))]
|
|
pub struct MetaLink {
|
|
pub id: Uuid,
|
|
pub document: String,
|
|
pub pattern: String,
|
|
pub rel: String,
|
|
pub type_: Option<String>,
|
|
pub href: Option<String>,
|
|
pub template: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable, Associations)]
|
|
#[diesel(belongs_to(MetaLink))]
|
|
#[diesel(table_name = schema::meta_link_properties)]
|
|
#[diesel(check_for_backend(Pg))]
|
|
pub struct MetaLinkProperty {
|
|
pub id: Uuid,
|
|
pub meta_link_id: Uuid,
|
|
pub rel: String,
|
|
pub value: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable, Associations)]
|
|
#[diesel(belongs_to(MetaLink))]
|
|
#[diesel(table_name = schema::meta_link_titles)]
|
|
#[diesel(check_for_backend(Pg))]
|
|
pub struct MetaLinkTitle {
|
|
pub id: Uuid,
|
|
pub meta_link_id: Uuid,
|
|
pub language: String,
|
|
pub value: String,
|
|
}
|
|
|
|
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)]
|
|
#[diesel(table_name = schema::meta_properties)]
|
|
#[diesel(check_for_backend(Pg))]
|
|
pub struct MetaProperty {
|
|
pub id: Uuid,
|
|
pub document: String,
|
|
pub pattern: String,
|
|
pub rel: String,
|
|
pub value: Option<String>,
|
|
}
|
|
|
|
impl MetaSubject {
|
|
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<Self>> {
|
|
use diesel::prelude::*;
|
|
use diesel_async::RunQueryDsl;
|
|
use schema::meta_subjects::dsl::*;
|
|
|
|
let document_is_equal = document.eq(doc);
|
|
let subject_matches_pattern = subject.into_sql::<diesel::sql_types::Text>().ilike(pattern);
|
|
|
|
meta_subjects
|
|
.filter(document_is_equal)
|
|
.filter(subject_matches_pattern)
|
|
.select(Self::as_select())
|
|
.load(conn)
|
|
.await
|
|
}
|
|
}
|
|
|
|
impl MetaAlias {
|
|
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<Self>> {
|
|
use diesel::prelude::*;
|
|
use diesel_async::RunQueryDsl;
|
|
use schema::meta_aliases::dsl::*;
|
|
|
|
let document_is_equal = document.eq(doc);
|
|
let subject_matches_pattern = subject.into_sql::<diesel::sql_types::Text>().ilike(pattern);
|
|
|
|
meta_aliases
|
|
.filter(document_is_equal)
|
|
.filter(subject_matches_pattern)
|
|
.select(Self::as_select())
|
|
.load(conn)
|
|
.await
|
|
}
|
|
}
|
|
|
|
impl MetaLink {
|
|
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<Self>> {
|
|
use diesel::prelude::*;
|
|
use diesel_async::RunQueryDsl;
|
|
use schema::meta_links::dsl::*;
|
|
|
|
let document_is_equal = document.eq(doc);
|
|
let subject_matches_pattern = subject.into_sql::<diesel::sql_types::Text>().ilike(pattern);
|
|
|
|
meta_links
|
|
.filter(document_is_equal)
|
|
.filter(subject_matches_pattern)
|
|
.select(Self::as_select())
|
|
.load(conn)
|
|
.await
|
|
}
|
|
}
|
|
|
|
impl MetaLinkProperty {
|
|
pub async fn query_by_link(conn: &mut AsyncPgConnection, links: &[MetaLink]) -> QueryResult<Vec<Self>> {
|
|
use diesel::prelude::*;
|
|
use diesel_async::RunQueryDsl;
|
|
|
|
Self::belonging_to(links)
|
|
.load(conn)
|
|
.await
|
|
}
|
|
}
|
|
|
|
impl MetaLinkTitle {
|
|
pub async fn query_by_link(conn: &mut AsyncPgConnection, links: &[MetaLink]) -> QueryResult<Vec<Self>> {
|
|
use diesel::prelude::*;
|
|
use diesel_async::RunQueryDsl;
|
|
|
|
Self::belonging_to(links)
|
|
.load(conn)
|
|
.await
|
|
}
|
|
}
|
|
|
|
impl MetaProperty {
|
|
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<Self>> {
|
|
use diesel::prelude::*;
|
|
use diesel_async::RunQueryDsl;
|
|
use schema::meta_properties::dsl::*;
|
|
|
|
let document_is_equal = document.eq(doc);
|
|
let subject_matches_pattern = subject.into_sql::<diesel::sql_types::Text>().ilike(pattern);
|
|
|
|
meta_properties
|
|
.filter(document_is_equal)
|
|
.filter(subject_matches_pattern)
|
|
.select(Self::as_select())
|
|
.load(conn)
|
|
.await
|
|
}
|
|
}
|