Remove diesel integration

This commit is contained in:
Jonas Platte 2020-05-30 19:10:21 +02:00
parent 96ca638474
commit 5861457f3b
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
10 changed files with 5 additions and 79 deletions

View File

@ -1,5 +1,10 @@
# [unreleased]
Breaking changes
* Removed diesel integration. If you were using it, please comment on the corresponding issue:
https://github.com/ruma/ruma-identifiers/issues/22
# 0.16.1
Bug fixes:

View File

@ -20,7 +20,6 @@ rustdoc-args = ["--cfg", "docsrs"]
default = ["serde"]
[dependencies]
diesel = { version = "1.4.4", optional = true }
either = { version = "1.5.3", optional = true }
rand = { version = "0.7.3", optional = true }
serde = { version = "1.0.106", optional = true }

View File

@ -1,42 +0,0 @@
//! Implements traits from Diesel, allowing identifiers to be used as database fields.
use std::{convert::TryFrom, error::Error as StdError, io::Write};
use diesel::{
backend::Backend,
deserialize::{FromSql, Result as DeserializeResult},
serialize::{Output, Result as SerializeResult, ToSql},
sql_types::Text,
};
macro_rules! diesel_impl {
($name:ident) => {
impl<DB> ToSql<Text, DB> for $crate::$name
where
DB: Backend,
{
fn to_sql<W: Write>(&self, out: &mut Output<'_, W, DB>) -> SerializeResult {
ToSql::<Text, DB>::to_sql(self.as_ref(), out)
}
}
impl<DB> FromSql<Text, DB> for $crate::$name
where
String: FromSql<Text, DB>,
DB: Backend,
{
fn from_sql(value: Option<&<DB as Backend>::RawValue>) -> DeserializeResult<Self> {
let string = <String as FromSql<Text, DB>>::from_sql(value)?;
Self::try_from(string.as_str())
.map_err(|error| Box::new(error) as Box<dyn StdError + Send + Sync>)
}
}
};
}
diesel_impl!(EventId);
diesel_impl!(RoomAliasId);
diesel_impl!(RoomId);
diesel_impl!(RoomIdOrAliasId);
diesel_impl!(RoomVersionId);
diesel_impl!(UserId);

View File

@ -2,9 +2,6 @@
use std::{borrow::Cow, convert::TryFrom, num::NonZeroU8};
#[cfg(feature = "diesel")]
use diesel::sql_types::Text;
use crate::{error::Error, parse_id, validate_id};
/// A Matrix event ID.
@ -41,8 +38,6 @@ use crate::{error::Error, parse_id, validate_id};
/// );
/// ```
#[derive(Clone, Debug)]
#[cfg_attr(feature = "diesel", derive(FromSqlRow, QueryId, AsExpression, SqlType))]
#[cfg_attr(feature = "diesel", sql_type = "Text")]
pub struct EventId {
full_id: Box<str>,
colon_idx: Option<NonZeroU8>,

View File

@ -11,10 +11,6 @@
#![allow(clippy::use_self)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(feature = "diesel")]
#[cfg_attr(feature = "diesel", macro_use)]
extern crate diesel;
use std::num::NonZeroU8;
#[cfg(feature = "serde")]
@ -31,9 +27,6 @@ pub use crate::{
mod macros;
pub mod device_id;
#[cfg(feature = "diesel")]
#[cfg_attr(docsrs, doc(cfg(feature = "diesel")))]
mod diesel_integration;
mod error;
mod event_id;
mod room_alias_id;

View File

@ -2,9 +2,6 @@
use std::{borrow::Cow, convert::TryFrom, num::NonZeroU8};
#[cfg(feature = "diesel")]
use diesel::sql_types::Text;
use crate::{error::Error, parse_id};
/// A Matrix room alias ID.
@ -21,8 +18,6 @@ use crate::{error::Error, parse_id};
/// );
/// ```
#[derive(Clone, Debug)]
#[cfg_attr(feature = "diesel", derive(FromSqlRow, QueryId, AsExpression, SqlType))]
#[cfg_attr(feature = "diesel", sql_type = "Text")]
pub struct RoomAliasId {
pub(crate) full_id: Box<str>,
pub(crate) colon_idx: NonZeroU8,

View File

@ -2,9 +2,6 @@
use std::{borrow::Cow, convert::TryFrom, num::NonZeroU8};
#[cfg(feature = "diesel")]
use diesel::sql_types::Text;
use crate::{error::Error, parse_id};
/// A Matrix room ID.
@ -21,8 +18,6 @@ use crate::{error::Error, parse_id};
/// );
/// ```
#[derive(Clone, Debug)]
#[cfg_attr(feature = "diesel", derive(FromSqlRow, QueryId, AsExpression, SqlType))]
#[cfg_attr(feature = "diesel", sql_type = "Text")]
pub struct RoomId {
pub(crate) full_id: Box<str>,
pub(crate) colon_idx: NonZeroU8,

View File

@ -2,9 +2,6 @@
use std::{borrow::Cow, convert::TryFrom, hint::unreachable_unchecked, num::NonZeroU8};
#[cfg(feature = "diesel")]
use diesel::sql_types::Text;
use crate::{error::Error, parse_id, RoomAliasId, RoomId};
/// A Matrix room ID or a Matrix room alias ID.
@ -27,8 +24,6 @@ use crate::{error::Error, parse_id, RoomAliasId, RoomId};
/// );
/// ```
#[derive(Clone, Debug)]
#[cfg_attr(feature = "diesel", derive(FromSqlRow, QueryId, AsExpression, SqlType))]
#[cfg_attr(feature = "diesel", sql_type = "Text")]
pub struct RoomIdOrAliasId {
full_id: Box<str>,
colon_idx: NonZeroU8,

View File

@ -6,8 +6,6 @@ use std::{
fmt::{self, Display, Formatter},
};
#[cfg(feature = "diesel")]
use diesel::sql_types::Text;
#[cfg(feature = "serde")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
@ -27,8 +25,6 @@ const MAX_CODE_POINTS: usize = 32;
/// assert_eq!(RoomVersionId::try_from("1").unwrap().as_ref(), "1");
/// ```
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "diesel", derive(FromSqlRow, QueryId, AsExpression, SqlType))]
#[cfg_attr(feature = "diesel", sql_type = "Text")]
pub struct RoomVersionId(InnerRoomVersionId);
/// Possibile values for room version, distinguishing between official Matrix versions and custom

View File

@ -2,9 +2,6 @@
use std::{borrow::Cow, convert::TryFrom, num::NonZeroU8};
#[cfg(feature = "diesel")]
use diesel::sql_types::Text;
use crate::{error::Error, is_valid_server_name, parse_id};
/// A Matrix user ID.
@ -21,8 +18,6 @@ use crate::{error::Error, is_valid_server_name, parse_id};
/// );
/// ```
#[derive(Clone, Debug)]
#[cfg_attr(feature = "diesel", derive(FromSqlRow, QueryId, AsExpression, SqlType))]
#[cfg_attr(feature = "diesel", sql_type = "Text")]
pub struct UserId {
full_id: Box<str>,
colon_idx: NonZeroU8,