database: Add insert functions to all Insert structs

This commit is contained in:
Steffo 2024-12-07 03:22:22 +01:00
parent 79e604eb96
commit d11934952f
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0

View file

@ -28,6 +28,7 @@
use diesel::deserialize::FromSql;
use diesel::{AsExpression, Associations, FromSqlRow, Identifiable, Insertable, IntoSql, PgTextExpressionMethods, QueryResult, Queryable, QueryableByName, Selectable, SelectableHelper, ExpressionMethods, BelongingToDsl};
use diesel::dsl::insert_into;
use diesel::pg::{Pg, PgConnection};
use diesel::serialize::{Output, ToSql};
use diesel_async::AsyncPgConnection;
@ -416,6 +417,29 @@ impl MetaSubject {
}
}
impl MetaSubjectInsert {
/// Syncronously insert the record into the table, returning the full inserted record.
pub fn insert(self, conn: &mut PgConnection) -> QueryResult<MetaSubject> {
use diesel::RunQueryDsl;
use schema::meta_subjects::dsl::*;
insert_into(meta_subjects)
.values(self)
.get_result(conn)
}
/// Asyncronously insert the record into the table, returning the full inserted record.
pub async fn ainsert(self, conn: &mut AsyncPgConnection) -> QueryResult<MetaSubject> {
use diesel_async::RunQueryDsl;
use schema::meta_subjects::dsl::*;
insert_into(meta_subjects)
.values(self)
.get_result(conn)
.await
}
}
impl MetaAlias {
/// Synchronously query the records matching the given document and resource.
pub fn query_matching(conn: &mut PgConnection, doc: &str, subject: &str) -> QueryResult<Vec<Self>> {
@ -451,6 +475,29 @@ impl MetaAlias {
}
}
impl MetaAliasInsert {
/// Syncronously insert the record into the table, returning the full inserted record.
pub fn insert(self, conn: &mut PgConnection) -> QueryResult<MetaAlias> {
use diesel::RunQueryDsl;
use schema::meta_aliases::dsl::*;
insert_into(meta_aliases)
.values(self)
.get_result(conn)
}
/// Asyncronously insert the record into the table, returning the full inserted record.
pub async fn ainsert(self, conn: &mut AsyncPgConnection) -> QueryResult<MetaAlias> {
use diesel_async::RunQueryDsl;
use schema::meta_aliases::dsl::*;
insert_into(meta_aliases)
.values(self)
.get_result(conn)
.await
}
}
impl MetaLink {
/// Synchronously query the records matching the given document and resource.
pub async fn query_matching(conn: &mut PgConnection, doc: &str, subject: &str) -> QueryResult<Vec<Self>> {
@ -486,6 +533,29 @@ impl MetaLink {
}
}
impl MetaLinkInsert {
/// Syncronously insert the record into the table, returning the full inserted record.
pub fn insert(self, conn: &mut PgConnection) -> QueryResult<MetaLink> {
use diesel::RunQueryDsl;
use schema::meta_links::dsl::*;
insert_into(meta_links)
.values(self)
.get_result(conn)
}
/// Asyncronously insert the record into the table, returning the full inserted record.
pub async fn ainsert(self, conn: &mut AsyncPgConnection) -> QueryResult<MetaLink> {
use diesel_async::RunQueryDsl;
use schema::meta_links::dsl::*;
insert_into(meta_links)
.values(self)
.get_result(conn)
.await
}
}
impl MetaLinkProperty {
/// Synchronously query the records belonging to the given [`MetaLink`]s.
pub fn query_by_link(conn: &mut PgConnection, links: &[MetaLink]) -> QueryResult<Vec<Self>> {
@ -505,6 +575,29 @@ impl MetaLinkProperty {
}
}
impl MetaLinkPropertyInsert {
/// Syncronously insert the record into the table, returning the full inserted record.
pub fn insert(self, conn: &mut PgConnection) -> QueryResult<MetaLinkProperty> {
use diesel::RunQueryDsl;
use schema::meta_link_properties::dsl::*;
insert_into(meta_link_properties)
.values(self)
.get_result(conn)
}
/// Asyncronously insert the record into the table, returning the full inserted record.
pub async fn ainsert(self, conn: &mut AsyncPgConnection) -> QueryResult<MetaLinkProperty> {
use diesel_async::RunQueryDsl;
use schema::meta_link_properties::dsl::*;
insert_into(meta_link_properties)
.values(self)
.get_result(conn)
.await
}
}
impl MetaLinkTitle {
/// Synchronously query the records belonging to the given [`MetaLink`]s.
pub fn query_by_link(conn: &mut PgConnection, links: &[MetaLink]) -> QueryResult<Vec<Self>> {
@ -524,6 +617,29 @@ impl MetaLinkTitle {
}
}
impl MetaLinkTitleInsert {
/// Syncronously insert the record into the table, returning the full inserted record.
pub fn insert(self, conn: &mut PgConnection) -> QueryResult<MetaLinkTitle> {
use diesel::RunQueryDsl;
use schema::meta_link_titles::dsl::*;
insert_into(meta_link_titles)
.values(self)
.get_result(conn)
}
/// Asyncronously insert the record into the table, returning the full inserted record.
pub async fn ainsert(self, conn: &mut AsyncPgConnection) -> QueryResult<MetaLinkTitle> {
use diesel_async::RunQueryDsl;
use schema::meta_link_titles::dsl::*;
insert_into(meta_link_titles)
.values(self)
.get_result(conn)
.await
}
}
impl MetaProperty {
/// Synchronously query the records matching the given document and resource.
pub fn query_matching(conn: &mut PgConnection, doc: &str, subject: &str) -> QueryResult<Vec<Self>> {
@ -558,3 +674,26 @@ impl MetaProperty {
.await
}
}
impl MetaPropertyInsert {
/// Syncronously insert the record into the table, returning the full inserted record.
pub fn insert(self, conn: &mut PgConnection) -> QueryResult<MetaProperty> {
use diesel::RunQueryDsl;
use schema::meta_properties::dsl::*;
insert_into(meta_properties)
.values(self)
.get_result(conn)
}
/// Asyncronously insert the record into the table, returning the full inserted record.
pub async fn ainsert(self, conn: &mut AsyncPgConnection) -> QueryResult<MetaProperty> {
use diesel_async::RunQueryDsl;
use schema::meta_properties::dsl::*;
insert_into(meta_properties)
.values(self)
.get_result(conn)
.await
}
}