2024-11-15 02:16:06 +00:00
|
|
|
use diesel::{Associations, Identifiable, Insertable, QueryResult, Queryable, QueryableByName, Selectable};
|
|
|
|
use diesel_async::AsyncPgConnection;
|
2024-11-15 01:16:16 +00:00
|
|
|
use uuid::Uuid;
|
|
|
|
use super::schema;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)]
|
|
|
|
#[diesel(table_name = schema::meta_aliases)]
|
|
|
|
pub struct MetaAlias {
|
|
|
|
pub id: Uuid,
|
2024-11-15 04:21:05 +00:00
|
|
|
pub document: String,
|
2024-11-15 01:16:16 +00:00
|
|
|
pub pattern: String,
|
|
|
|
pub alias: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)]
|
|
|
|
#[diesel(table_name = schema::meta_links)]
|
|
|
|
pub struct MetaLink {
|
|
|
|
pub id: Uuid,
|
2024-11-15 04:21:05 +00:00
|
|
|
pub document: String,
|
2024-11-15 01:16:16 +00:00
|
|
|
pub pattern: String,
|
|
|
|
pub rel: String,
|
2024-11-15 19:44:06 +00:00
|
|
|
pub type_: Option<String>,
|
2024-11-15 01:16:16 +00:00
|
|
|
pub href: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable, Associations)]
|
|
|
|
#[diesel(belongs_to(MetaLink))]
|
|
|
|
#[diesel(table_name = schema::meta_link_properties)]
|
|
|
|
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)]
|
|
|
|
#[diesel(table_name = schema::meta_properties)]
|
|
|
|
pub struct MetaProperty {
|
|
|
|
pub id: Uuid,
|
2024-11-15 04:21:05 +00:00
|
|
|
pub document: String,
|
2024-11-15 01:16:16 +00:00
|
|
|
pub pattern: String,
|
2024-11-15 05:30:42 +00:00
|
|
|
pub rel: String,
|
2024-11-15 01:16:16 +00:00
|
|
|
pub value: Option<String>,
|
|
|
|
}
|
2024-11-15 02:16:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
impl MetaAlias {
|
2024-11-15 04:23:06 +00:00
|
|
|
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<MetaAlias>> {
|
2024-11-15 02:16:06 +00:00
|
|
|
use diesel::prelude::*;
|
|
|
|
use diesel_async::RunQueryDsl;
|
|
|
|
use schema::meta_aliases::dsl::*;
|
|
|
|
|
2024-11-15 04:23:06 +00:00
|
|
|
let document_is_equal = document.eq(doc);
|
2024-11-15 02:16:06 +00:00
|
|
|
let subject_matches_pattern = subject.into_sql::<diesel::sql_types::Text>().ilike(pattern);
|
|
|
|
|
|
|
|
meta_aliases
|
2024-11-15 04:23:06 +00:00
|
|
|
.filter(document_is_equal)
|
2024-11-15 02:16:06 +00:00
|
|
|
.filter(subject_matches_pattern)
|
|
|
|
.select(Self::as_select())
|
|
|
|
.load(conn)
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MetaLink {
|
2024-11-15 04:23:06 +00:00
|
|
|
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<MetaLink>> {
|
2024-11-15 02:16:06 +00:00
|
|
|
use diesel::prelude::*;
|
|
|
|
use diesel_async::RunQueryDsl;
|
|
|
|
use schema::meta_links::dsl::*;
|
|
|
|
|
2024-11-15 04:23:06 +00:00
|
|
|
let document_is_equal = document.eq(doc);
|
2024-11-15 02:16:06 +00:00
|
|
|
let subject_matches_pattern = subject.into_sql::<diesel::sql_types::Text>().ilike(pattern);
|
|
|
|
|
|
|
|
meta_links
|
2024-11-15 04:23:06 +00:00
|
|
|
.filter(document_is_equal)
|
2024-11-15 02:16:06 +00:00
|
|
|
.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 {
|
2024-11-15 04:23:06 +00:00
|
|
|
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<MetaProperty>> {
|
2024-11-15 02:16:06 +00:00
|
|
|
use diesel::prelude::*;
|
|
|
|
use diesel_async::RunQueryDsl;
|
|
|
|
use schema::meta_properties::dsl::*;
|
|
|
|
|
2024-11-15 04:23:06 +00:00
|
|
|
let document_is_equal = document.eq(doc);
|
2024-11-15 02:16:06 +00:00
|
|
|
let subject_matches_pattern = subject.into_sql::<diesel::sql_types::Text>().ilike(pattern);
|
|
|
|
|
|
|
|
meta_properties
|
2024-11-15 04:23:06 +00:00
|
|
|
.filter(document_is_equal)
|
2024-11-15 02:16:06 +00:00
|
|
|
.filter(subject_matches_pattern)
|
|
|
|
.select(Self::as_select())
|
|
|
|
.load(conn)
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
}
|