sea-orm-ffi 0.1.3

Compatibility layer for Sea-ORM when crossing a Rust-to-Rust FFI boundary
Documentation
use crate::string::StringPtr;
use sea_orm::{ConnAcquireErr, DbErr};

#[repr(C)]
pub(crate) enum FfiDbErr {
	ConnAquireTimeout,
	ConnAquireConnClosed,
	UnpackInsertId,
	UpdateGetPrimaryKey,
	RecordNotFound(StringPtr),
	AttrNotSet(StringPtr),
	Custom(StringPtr),
	Type(StringPtr),
	Json(StringPtr),
	Migration(StringPtr),
	RecordNotInserted,
	RecordNotUpdated
}

impl From<DbErr> for FfiDbErr {
	fn from(err: DbErr) -> Self {
		match err {
			DbErr::ConnectionAcquire(ConnAcquireErr::Timeout) => Self::ConnAquireTimeout,
			DbErr::ConnectionAcquire(ConnAcquireErr::ConnectionClosed) => {
				Self::ConnAquireConnClosed
			},
			DbErr::UnpackInsertId => Self::UnpackInsertId,
			DbErr::UpdateGetPrimaryKey => Self::UpdateGetPrimaryKey,
			DbErr::RecordNotFound(s) => Self::RecordNotFound(s.into()),
			DbErr::AttrNotSet(s) => Self::AttrNotSet(s.into()),
			DbErr::Custom(s) => Self::Custom(s.into()),
			DbErr::Type(s) => Self::Type(s.into()),
			DbErr::Json(s) => Self::Json(s.into()),
			DbErr::Migration(s) => Self::Migration(s.into()),
			DbErr::RecordNotInserted => Self::RecordNotInserted,
			DbErr::RecordNotUpdated => Self::RecordNotUpdated,

			err => Self::Custom(err.to_string().into())
		}
	}
}

impl From<FfiDbErr> for DbErr {
	fn from(err: FfiDbErr) -> Self {
		match err {
			FfiDbErr::ConnAquireTimeout => {
				Self::ConnectionAcquire(ConnAcquireErr::Timeout)
			},
			FfiDbErr::ConnAquireConnClosed => {
				Self::ConnectionAcquire(ConnAcquireErr::ConnectionClosed)
			},
			FfiDbErr::UnpackInsertId => Self::UnpackInsertId,
			FfiDbErr::UpdateGetPrimaryKey => Self::UpdateGetPrimaryKey,
			FfiDbErr::RecordNotFound(s) => Self::RecordNotFound(s.into()),
			FfiDbErr::AttrNotSet(s) => Self::AttrNotSet(s.into()),
			FfiDbErr::Custom(s) => Self::Custom(s.into()),
			FfiDbErr::Type(s) => Self::Type(s.into()),
			FfiDbErr::Json(s) => Self::Json(s.into()),
			FfiDbErr::Migration(s) => Self::Migration(s.into()),
			FfiDbErr::RecordNotInserted => Self::RecordNotInserted,
			FfiDbErr::RecordNotUpdated => Self::RecordNotUpdated
		}
	}
}