Skip to content

Absrd Home

hernansaab edited this page Aug 28, 2012 · 28 revisions

Welcome to the absrd wiki! This tool takes advantage of parallel gcd and allows for for concurrent running sql queries. It also offers a lean object oriented wrapper to sql.

Sample Show Off Code

Here we are creating 5 different query blocks. 1 of them query db called default and 4 of them query db called web1

Code as follows:

AbsrdQueryBlock block1 = ^(){
        DbConnector *default_conn = [DbManager getConnector:@"default"];;
        // you can also use queries like this anywhere in your code. The data returned in an array 
        // of dictionaries. where the elements of the array are the rows. Each row is a dict with keys as
        // columns in NSString format with values in NSString format.
        NSMutableArray *res = [default_conn query:@"select * from courses limit 1"];
        return res;
    };

    AbsrdQueryBlock block2 = ^(){
        DbConnector *web1_conn    = [DbManager getConnector:@"web1"];;
        NSMutableArray *res = [web1_conn query:@"select * from t_contents limit 1"];
        return res;
    };

    AbsrdQueryBlock block3 = ^(){
        DbConnector *web1_conn    = [DbManager getConnector:@"web1"];;
        NSMutableArray *res = [web1_conn query:@"select * from t_resources limit 1"];
        return res;

   };
    
    AbsrdQueryBlock block4 = ^(){
        DbConnector *web1_conn    = [DbManager getConnector:@"web1"];;
        NSMutableArray *res = [web1_conn query:@"select * from t_activities limit 1"];
        return res;
    };
    
   AbsrdQueryBlock block5 = ^(){
        DbConnector *web1_conn    = [DbManager getConnector:@"web1"];;
        NSMutableArray *res = [web1_conn query:@"select * from t_content_thumbnails limit 1"];
        return res;
    };

// Now we add these query blocks to the query blaster

    QueryBlockBuster *bb = [[QueryBlockBuster alloc] init];
    [bb addQueryBlock:block1];
    [bb addQueryBlock:block2];
    [bb addQueryBlock:block3];
    [bb addQueryBlock:block4];
    [bb addQueryBlock:block5];


// And now we execute all queries in 5 concurrent queries saving you a fracion of a time compared to
// querying them sequentially

## And here is the Awesome command!!##
    NSMutableArray *result = [bb multiQueryParallel];

// The initial queries will be slower because connections are created. But connections are recycled and are used to make sure that every concurrent queue has its own connection for a given db.


function addQueryBlock: allows you to add a block query. This means that you can also perform a rest request in parallel with other queries. If addQueryBlock is too powerful for you you can try function addQuerySqlString:(NSString*) query forDb: (NSString*) db.
For example adding block2 is equivalent to the following:

[bb addQuerySqlString:@"select * from courses limit 1" :forDb:@"default"];








              

Clone this wiki locally