Trait rustorm::database::Database [] [src]

pub trait Database {
    fn version(&self) -> String;
    fn begin(&self);
    fn commit(&self);
    fn rollback(&self);
    fn is_transacted(&self) -> bool;
    fn is_closed(&self) -> bool;
    fn is_connected(&self) -> bool;
    fn close(&self);
    fn is_valid(&self) -> bool;
    fn reset(&self);
    fn update(&self, query: &Query) -> Dao;
    fn delete(&self, query: &Query) -> Result<usize, String>;
    fn execute_sql_with_return(&self, sql: &str, params: &Vec<Value>) -> Result<Vec<Dao>, DbError>;
    fn execute_sql(&self, sql: &str, param: &Vec<Value>) -> Result<usize, DbError>;
    fn sql_options(&self) -> Vec<SqlOption>;

    fn select(&self, query: &Query) -> Result<DaoResult, DbError> { ... }
    fn insert(&self, query: &Query) -> Result<Dao, DbError> { ... }
    fn execute_with_return(&self, query: &Query) -> Result<DaoResult, DbError> { ... }
    fn execute_with_one_return(&self, query: &Query) -> Result<Dao, DbError> { ... }
    fn execute(&self, query: &Query) -> Result<usize, DbError> { ... }
    fn execute_sql_with_one_return(&self, sql: &str, params: &Vec<Value>) -> Result<Dao, DbError> { ... }
    fn build_query(&self, query: &Query) -> SqlFrag { ... }
    fn build_operand(&self, w: &mut SqlFrag, parent_query: &Query, operand: &Operand) { ... }
    fn build_condition(&self, w: &mut SqlFrag, parent_query: &Query, cond: &Condition) { ... }
    fn build_field(&self, w: &mut SqlFrag, parent_query: &Query, field: &Field) { ... }
    fn build_filter(&self, w: &mut SqlFrag, parent_query: &Query, filter: &Filter) { ... }
    fn build_filters(&self, w: &mut SqlFrag, parent_query: &Query, filters: &Vec<Filter>) { ... }
    fn build_enumerated_fields(&self, w: &mut SqlFrag, parent_query: &Query, enumerated_fields: &Vec<Field>) { ... }
    fn build_select(&self, query: &Query) -> SqlFrag { ... }
    fn build_insert(&self, query: &Query) -> SqlFrag { ... }
    fn build_update(&self, query: &Query) -> SqlFrag { ... }
    fn build_delete(&self, query: &Query) -> SqlFrag { ... }
}

Generic Database interface This is the database interface which will should be implemented to you the specifics of each database platform At least all methods on this trait should be implemented for target deployment database A lower level API for manipulating objects in the database

TODO: acquire only a connection until a query is about to be executed. generating query don't really need database connection just yet.

Required Methods

fn version(&self) -> String

return the version of the database lower version of database has fewer supported features

fn begin(&self)

begin database transaction

fn commit(&self)

commit database transaction

fn rollback(&self)

rollback data changes executed prior to calling the begin method

fn is_transacted(&self) -> bool

determine if this transaction has been committed or rolledback

fn is_closed(&self) -> bool

determine if the database connection closed

fn is_connected(&self) -> bool

check if the database is still connected

fn close(&self)

close the database connection

fn is_valid(&self) -> bool

determine if the database connection is still valid

fn reset(&self)

reset the database connection

fn update(&self, query: &Query) -> Dao

update returns the updated Dao

fn delete(&self, query: &Query) -> Result<usize, String>

delete records returns the number of deleted records

fn execute_sql_with_return(&self, sql: &str, params: &Vec<Value>) -> Result<Vec<Dao>, DbError>

execute insert with returning clause, update with returning clause

fn execute_sql(&self, sql: &str, param: &Vec<Value>) -> Result<usize, DbError>

everything else, no required return other than error or affected number of records

fn sql_options(&self) -> Vec<SqlOption>

Provided Methods

fn select(&self, query: &Query) -> Result<DaoResult, DbError>

select returns an array to the qualified records

fn insert(&self, query: &Query) -> Result<Dao, DbError>

insert insert an object, returns the inserted Dao value including the value generated via the defaults

fn execute_with_return(&self, query: &Query) -> Result<DaoResult, DbError>

execute query with return dao, use the enumerated column for data extraction when db doesn't support returning the records column names

fn execute_with_one_return(&self, query: &Query) -> Result<Dao, DbError>

execute query with 1 return dao

fn execute(&self, query: &Query) -> Result<usize, DbError>

execute query with no return dao

fn execute_sql_with_one_return(&self, sql: &str, params: &Vec<Value>) -> Result<Dao, DbError>

fn build_query(&self, query: &Query) -> SqlFrag

build a query, return the sql string and the parameters. use by select to build the select query build all types of query TODO: need to supply the number of parameters where to start the numbering of the number parameters

fn build_operand(&self, w: &mut SqlFrag, parent_query: &Query, operand: &Operand)

build operand, i.e: columns, query, function, values

fn build_condition(&self, w: &mut SqlFrag, parent_query: &Query, cond: &Condition)

fn build_field(&self, w: &mut SqlFrag, parent_query: &Query, field: &Field)

fn build_filter(&self, w: &mut SqlFrag, parent_query: &Query, filter: &Filter)

fn build_filters(&self, w: &mut SqlFrag, parent_query: &Query, filters: &Vec<Filter>)

build the filter clause or the where clause of the query TODO: add the sub filters

fn build_enumerated_fields(&self, w: &mut SqlFrag, parent_query: &Query, enumerated_fields: &Vec<Field>)

build the enumerated, distinct, *, columns

fn build_select(&self, query: &Query) -> SqlFrag

build the select statment from the query object

fn build_insert(&self, query: &Query) -> SqlFrag

TODO complete this

fn build_update(&self, query: &Query) -> SqlFrag

fn build_delete(&self, query: &Query) -> SqlFrag

Implementors