feat(mssql): setup the initial boilerplate for MSSQL

Co-authored-by: Daniel Akhterov <akhterovd@gmail.com>
This commit is contained in:
Ryan Leckey 2020-06-02 00:22:25 -07:00
parent 8c42d7fcc0
commit 05eb07e7d4
12 changed files with 361 additions and 0 deletions

View File

@ -19,6 +19,7 @@ default = [ "runtime-async-std" ]
postgres = [ "md-5", "sha2", "base64", "sha-1", "rand", "hmac", "futures-channel/sink", "futures-util/sink" ] postgres = [ "md-5", "sha2", "base64", "sha-1", "rand", "hmac", "futures-channel/sink", "futures-util/sink" ]
mysql = [ "sha-1", "sha2", "generic-array", "num-bigint", "base64", "digest", "rand" ] mysql = [ "sha-1", "sha2", "generic-array", "num-bigint", "base64", "digest", "rand" ]
sqlite = [ "libsqlite3-sys" ] sqlite = [ "libsqlite3-sys" ]
mssql = [ ]
# types # types
all-types = [ "chrono", "time", "bigdecimal", "ipnetwork", "json", "uuid" ] all-types = [ "chrono", "time", "bigdecimal", "ipnetwork", "json", "uuid" ]

View File

@ -0,0 +1,21 @@
use crate::arguments::Arguments;
use crate::encode::Encode;
use crate::mssql::database::MsSql;
#[derive(Default)]
pub struct MsSqlArguments {}
impl<'q> Arguments<'q> for MsSqlArguments {
type Database = MsSql;
fn reserve(&mut self, additional: usize, size: usize) {
unimplemented!()
}
fn add<T>(&mut self, value: T)
where
T: 'q + Encode<'q, Self::Database>,
{
unimplemented!()
}
}

View File

@ -0,0 +1,45 @@
use either::Either;
use futures_core::future::BoxFuture;
use futures_core::stream::BoxStream;
use crate::describe::Describe;
use crate::error::Error;
use crate::executor::{Execute, Executor};
use crate::mssql::{MsSql, MsSqlConnection, MsSqlRow};
impl<'c> Executor<'c> for &'c mut MsSqlConnection {
type Database = MsSql;
fn fetch_many<'e, 'q: 'e, E: 'q>(
self,
query: E,
) -> BoxStream<'e, Result<Either<u64, MsSqlRow>, Error>>
where
'c: 'e,
E: Execute<'q, Self::Database>,
{
unimplemented!()
}
fn fetch_optional<'e, 'q: 'e, E: 'q>(
self,
query: E,
) -> BoxFuture<'e, Result<Option<MsSqlRow>, Error>>
where
'c: 'e,
E: Execute<'q, Self::Database>,
{
unimplemented!()
}
fn describe<'e, 'q: 'e, E: 'q>(
self,
query: E,
) -> BoxFuture<'e, Result<Describe<Self::Database>, Error>>
where
'c: 'e,
E: Execute<'q, Self::Database>,
{
unimplemented!()
}
}

View File

@ -0,0 +1,49 @@
use std::fmt::{self, Debug, Formatter};
use futures_core::future::BoxFuture;
use crate::connection::{Connect, Connection};
use crate::error::{BoxDynError, Error};
use crate::mssql::{MsSql, MsSqlConnectOptions};
mod executor;
pub struct MsSqlConnection {}
impl Debug for MsSqlConnection {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("MsSqlConnection").finish()
}
}
impl Connection for MsSqlConnection {
type Database = MsSql;
fn close(self) -> BoxFuture<'static, Result<(), Error>> {
unimplemented!()
}
fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>> {
unimplemented!()
}
fn flush(&mut self) -> BoxFuture<'_, Result<(), Error>> {
unimplemented!()
}
fn get_ref(&self) -> &MsSqlConnection {
unimplemented!()
}
fn get_mut(&mut self) -> &mut MsSqlConnection {
unimplemented!()
}
}
impl Connect for MsSqlConnection {
type Options = MsSqlConnectOptions;
fn connect_with(options: &Self::Options) -> BoxFuture<'_, Result<Self, Error>> {
unimplemented!()
}
}

View File

@ -0,0 +1,35 @@
use crate::database::{Database, HasArguments, HasValueRef};
use crate::mssql::{
MsSqlArguments, MsSqlConnection, MsSqlRow, MsSqlTransactionManager, MsSqlTypeInfo, MsSqlValue,
MsSqlValueRef,
};
/// MSSQL database driver.
#[derive(Debug)]
pub struct MsSql;
impl Database for MsSql {
type Connection = MsSqlConnection;
type TransactionManager = MsSqlTransactionManager;
type Row = MsSqlRow;
type TypeInfo = MsSqlTypeInfo;
type Value = MsSqlValue;
}
impl<'r> HasValueRef<'r> for MsSql {
type Database = MsSql;
type ValueRef = MsSqlValueRef<'r>;
}
impl HasArguments<'_> for MsSql {
type Database = MsSql;
type Arguments = MsSqlArguments;
type ArgumentBuffer = Vec<u8>;
}

View File

@ -0,0 +1,42 @@
use crate::error::DatabaseError;
use std::error::Error;
use std::fmt::{self, Debug, Display, Formatter};
/// An error returned from the MSSQL database.
pub struct MsSqlDatabaseError {}
impl Debug for MsSqlDatabaseError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
unimplemented!()
}
}
impl Display for MsSqlDatabaseError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
unimplemented!()
}
}
impl Error for MsSqlDatabaseError {}
impl DatabaseError for MsSqlDatabaseError {
#[inline]
fn message(&self) -> &str {
unimplemented!()
}
#[doc(hidden)]
fn as_error(&self) -> &(dyn Error + Send + Sync + 'static) {
self
}
#[doc(hidden)]
fn as_error_mut(&mut self) -> &mut (dyn Error + Send + Sync + 'static) {
self
}
#[doc(hidden)]
fn into_error(self: Box<Self>) -> Box<dyn Error + Send + Sync + 'static> {
self
}
}

View File

@ -0,0 +1,29 @@
//! Microsoft SQL (MSSQL) database driver.
mod arguments;
mod connection;
mod database;
mod error;
mod options;
mod row;
mod transaction;
mod type_info;
mod value;
pub use arguments::MsSqlArguments;
pub use connection::MsSqlConnection;
pub use database::MsSql;
pub use error::MsSqlDatabaseError;
pub use options::MsSqlConnectOptions;
pub use row::MsSqlRow;
pub use transaction::MsSqlTransactionManager;
pub use type_info::MsSqlTypeInfo;
pub use value::{MsSqlValue, MsSqlValueRef};
/// An alias for [`Pool`][crate::pool::Pool], specialized for MySQL.
pub type MsSqlPool = crate::pool::Pool<MsSql>;
// NOTE: required due to the lack of lazy normalization
impl_into_arguments_for_arguments!(MsSqlArguments);
impl_executor_for_pool_connection!(MsSql, MsSqlConnection, MsSqlRow);
impl_executor_for_transaction!(MsSql, MsSqlRow);

View File

@ -0,0 +1,14 @@
use std::str::FromStr;
use crate::error::BoxDynError;
#[derive(Debug, Clone)]
pub struct MsSqlConnectOptions {}
impl FromStr for MsSqlConnectOptions {
type Err = BoxDynError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
unimplemented!()
}
}

View File

@ -0,0 +1,23 @@
use crate::error::Error;
use crate::mssql::{MsSql, MsSqlValueRef};
use crate::row::{ColumnIndex, Row};
pub struct MsSqlRow {}
impl crate::row::private_row::Sealed for MsSqlRow {}
impl Row for MsSqlRow {
type Database = MsSql;
#[inline]
fn len(&self) -> usize {
unimplemented!()
}
fn try_get_raw<I>(&self, index: I) -> Result<MsSqlValueRef<'_>, Error>
where
I: ColumnIndex<Self>,
{
unimplemented!()
}
}

View File

@ -0,0 +1,32 @@
use futures_core::future::BoxFuture;
use crate::error::Error;
use crate::executor::Executor;
use crate::mssql::{MsSql, MsSqlConnection};
use crate::transaction::{
begin_ansi_transaction_sql, commit_ansi_transaction_sql, rollback_ansi_transaction_sql,
TransactionManager,
};
/// Implementation of [`TransactionManager`] for MSSQL.
pub struct MsSqlTransactionManager;
impl TransactionManager for MsSqlTransactionManager {
type Database = MsSql;
fn begin(conn: &mut MsSqlConnection, depth: usize) -> BoxFuture<'_, Result<(), Error>> {
unimplemented!()
}
fn commit(conn: &mut MsSqlConnection, depth: usize) -> BoxFuture<'_, Result<(), Error>> {
unimplemented!()
}
fn rollback(conn: &mut MsSqlConnection, depth: usize) -> BoxFuture<'_, Result<(), Error>> {
unimplemented!()
}
fn start_rollback(conn: &mut MsSqlConnection, depth: usize) {
unimplemented!()
}
}

View File

@ -0,0 +1,22 @@
use std::fmt::{self, Display, Formatter};
use crate::type_info::TypeInfo;
#[derive(Debug, Clone)]
pub struct MsSqlTypeInfo {}
impl TypeInfo for MsSqlTypeInfo {}
impl Display for MsSqlTypeInfo {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
unimplemented!()
}
}
impl PartialEq<MsSqlTypeInfo> for MsSqlTypeInfo {
fn eq(&self, other: &MsSqlTypeInfo) -> bool {
unimplemented!()
}
}
impl Eq for MsSqlTypeInfo {}

View File

@ -0,0 +1,48 @@
use std::borrow::Cow;
use std::marker::PhantomData;
use crate::database::HasValueRef;
use crate::mssql::{MsSql, MsSqlTypeInfo};
use crate::value::{Value, ValueRef};
/// Implementation of [`ValueRef`] for MSSQL.
#[derive(Clone)]
pub struct MsSqlValueRef<'r> {
phantom: PhantomData<&'r ()>,
}
impl ValueRef<'_> for MsSqlValueRef<'_> {
type Database = MsSql;
fn to_owned(&self) -> MsSqlValue {
unimplemented!()
}
fn type_info(&self) -> Option<Cow<'_, MsSqlTypeInfo>> {
unimplemented!()
}
fn is_null(&self) -> bool {
unimplemented!()
}
}
/// Implementation of [`Value`] for MSSQL.
#[derive(Clone)]
pub struct MsSqlValue {}
impl Value for MsSqlValue {
type Database = MsSql;
fn as_ref(&self) -> <Self::Database as HasValueRef<'_>>::ValueRef {
unimplemented!()
}
fn type_info(&self) -> Option<Cow<'_, MsSqlTypeInfo>> {
unimplemented!()
}
fn is_null(&self) -> bool {
unimplemented!()
}
}