core
: Filter meta queries on document
This commit is contained in:
parent
d0aa551ef4
commit
94203cdc7b
1 changed files with 9 additions and 3 deletions
|
@ -45,14 +45,16 @@ pub struct MetaProperty {
|
||||||
|
|
||||||
|
|
||||||
impl MetaAlias {
|
impl MetaAlias {
|
||||||
pub async fn query_matching(conn: &mut AsyncPgConnection, subject: &str) -> QueryResult<Vec<MetaAlias>> {
|
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<MetaAlias>> {
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use schema::meta_aliases::dsl::*;
|
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);
|
let subject_matches_pattern = subject.into_sql::<diesel::sql_types::Text>().ilike(pattern);
|
||||||
|
|
||||||
meta_aliases
|
meta_aliases
|
||||||
|
.filter(document_is_equal)
|
||||||
.filter(subject_matches_pattern)
|
.filter(subject_matches_pattern)
|
||||||
.select(Self::as_select())
|
.select(Self::as_select())
|
||||||
.load(conn)
|
.load(conn)
|
||||||
|
@ -61,14 +63,16 @@ impl MetaAlias {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MetaLink {
|
impl MetaLink {
|
||||||
pub async fn query_matching(conn: &mut AsyncPgConnection, subject: &str) -> QueryResult<Vec<MetaLink>> {
|
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<MetaLink>> {
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use schema::meta_links::dsl::*;
|
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);
|
let subject_matches_pattern = subject.into_sql::<diesel::sql_types::Text>().ilike(pattern);
|
||||||
|
|
||||||
meta_links
|
meta_links
|
||||||
|
.filter(document_is_equal)
|
||||||
.filter(subject_matches_pattern)
|
.filter(subject_matches_pattern)
|
||||||
.select(Self::as_select())
|
.select(Self::as_select())
|
||||||
.load(conn)
|
.load(conn)
|
||||||
|
@ -86,14 +90,16 @@ impl MetaLink {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MetaProperty {
|
impl MetaProperty {
|
||||||
pub async fn query_matching(conn: &mut AsyncPgConnection, subject: &str) -> QueryResult<Vec<MetaProperty>> {
|
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<MetaProperty>> {
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use schema::meta_properties::dsl::*;
|
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);
|
let subject_matches_pattern = subject.into_sql::<diesel::sql_types::Text>().ilike(pattern);
|
||||||
|
|
||||||
meta_properties
|
meta_properties
|
||||||
|
.filter(document_is_equal)
|
||||||
.filter(subject_matches_pattern)
|
.filter(subject_matches_pattern)
|
||||||
.select(Self::as_select())
|
.select(Self::as_select())
|
||||||
.load(conn)
|
.load(conn)
|
||||||
|
|
Loading…
Reference in a new issue