core
: Add meta_subjects
to handle redirects
This commit is contained in:
parent
d80888c9db
commit
dfee4e510e
4 changed files with 49 additions and 2 deletions
|
@ -3,3 +3,4 @@ DROP TABLE IF EXISTS meta_link_properties CASCADE;
|
|||
DROP TABLE IF EXISTS meta_link_titles CASCADE;
|
||||
DROP TABLE IF EXISTS meta_links CASCADE;
|
||||
DROP TABLE IF EXISTS meta_aliases CASCADE;
|
||||
DROP TABLE IF EXISTS meta_subjects CASCADE;
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
CREATE TABLE IF NOT EXISTS meta_subjects (
|
||||
id UUID DEFAULT gen_random_uuid(),
|
||||
document BPCHAR NOT NULL,
|
||||
pattern BPCHAR NOT NULL,
|
||||
redirect BPCHAR NOT NULL,
|
||||
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS meta_aliases (
|
||||
id UUID DEFAULT gen_random_uuid(),
|
||||
document BPCHAR NOT NULL,
|
||||
|
|
|
@ -4,6 +4,15 @@ use uuid::Uuid;
|
|||
use super::schema;
|
||||
|
||||
|
||||
#[derive(Debug, Queryable, QueryableByName, Identifiable, Selectable, Insertable)]
|
||||
#[diesel(table_name = schema::meta_subjects)]
|
||||
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)]
|
||||
pub struct MetaAlias {
|
||||
|
@ -55,6 +64,24 @@ pub struct MetaProperty {
|
|||
pub value: Option<String>,
|
||||
}
|
||||
|
||||
impl MetaSubject {
|
||||
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<MetaSubject>> {
|
||||
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<MetaAlias>> {
|
||||
use diesel::prelude::*;
|
||||
|
|
|
@ -50,6 +50,15 @@ diesel::table! {
|
|||
}
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
meta_subjects (id) {
|
||||
id -> Uuid,
|
||||
document -> Bpchar,
|
||||
pattern -> Bpchar,
|
||||
redirect -> Bpchar,
|
||||
}
|
||||
}
|
||||
|
||||
diesel::joinable!(meta_link_properties -> meta_links (meta_link_id));
|
||||
diesel::joinable!(meta_link_titles -> meta_links (meta_link_id));
|
||||
|
||||
|
@ -59,4 +68,5 @@ diesel::allow_tables_to_appear_in_same_query!(
|
|||
meta_link_titles,
|
||||
meta_links,
|
||||
meta_properties,
|
||||
meta_subjects,
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue