Some type experimentation
This commit is contained in:
parent
0d648952cd
commit
80f85b6579
@ -21,7 +21,13 @@ features=["chrono","serde_json","url"]
|
||||
optional=true
|
||||
package="rusqlite"
|
||||
|
||||
[dependencies.my]
|
||||
version="15.1.0"
|
||||
optional=true
|
||||
package="mysql"
|
||||
|
||||
[features]
|
||||
default=['postgres']
|
||||
postgres=['pg']
|
||||
sqlite=['slite']
|
||||
mysql=['my']
|
||||
|
@ -3,16 +3,20 @@
|
||||
//! Drivers represent a connection to a specific type of database engine
|
||||
use std::fmt;
|
||||
|
||||
#[cfg(feature="pg")]
|
||||
#[cfg(feature="postgres")]
|
||||
mod postgres;
|
||||
|
||||
#[cfg(feature="sqlite")]
|
||||
mod sqlite;
|
||||
|
||||
#[cfg(feature="mysql")]
|
||||
mod mysql;
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Connection;
|
||||
|
||||
/// Result for a db query
|
||||
#[derive(Debug)]
|
||||
struct QueryResult;
|
||||
|
||||
|
14
src/drivers/mysql.rs
Normal file
14
src/drivers/mysql.rs
Normal file
@ -0,0 +1,14 @@
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MySQL;
|
||||
|
||||
impl DatabaseDriver for MySQL {
|
||||
fn quote_identifier(&self, identifier: &str) -> String {
|
||||
String::from(identifier)
|
||||
}
|
||||
|
||||
fn query(&self, _query: &str) -> Result<(), ()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
22
src/main.rs
Normal file
22
src/main.rs
Normal file
@ -0,0 +1,22 @@
|
||||
//! This main file is just for temparary testing
|
||||
use stringqb::query_builder::QueryBuilder;
|
||||
use stringqb::types::{SQLType, Type};
|
||||
|
||||
fn main() {
|
||||
let qb = QueryBuilder::new()
|
||||
.set("foo", Box::new("bar"))
|
||||
.set("bar", Box::new(12))
|
||||
.set("baz", Box::new(false))
|
||||
.set("fizz", Box::new(12.38))
|
||||
.set("buzz", Box::new((1, 2.0, true, 'q')));
|
||||
|
||||
|
||||
|
||||
// This just makes me sad
|
||||
let qb = qb.r#where("foo", Box::new(2));
|
||||
|
||||
println!("QueryBuilder object: {:#?}", &qb);
|
||||
|
||||
println!("SQLType mapping: {:#?}", SQLType::SmallInt(32));
|
||||
println!("Type: {:#?}", Type(Box::new(1234567890)));
|
||||
}
|
@ -217,7 +217,10 @@ impl QueryBuilder {
|
||||
|
||||
/// Specify a condition for the `where` clause of the query
|
||||
pub fn r#where(mut self, key: &str, value: Box<dyn Any>) -> Self {
|
||||
unimplemented!();
|
||||
// @TODO actually implement setting the keys for the where
|
||||
self.state.where_values.push(value);
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
/// Specify a condition for the `where` clause of the query, prefixed with `or`
|
||||
|
27
src/types.rs
27
src/types.rs
@ -1 +1,28 @@
|
||||
//! Shared Types for different Database drivers
|
||||
use std::any::Any;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Type(pub Box<dyn Any>);
|
||||
|
||||
/// Enum struct for mapping between database and Rust types
|
||||
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
|
||||
pub enum SQLType<T> {
|
||||
Boolean(T),
|
||||
SmallInt(T),
|
||||
BigInt(T),
|
||||
Text(T),
|
||||
None,
|
||||
}
|
||||
|
||||
impl<T> SQLType<T> {
|
||||
pub fn is_some(&self) -> bool {
|
||||
match *self {
|
||||
SQLType::None => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_none(&self) -> bool {
|
||||
!self.is_some()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user