-
Notifications
You must be signed in to change notification settings - Fork 0
Absrd Home
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.
Here we are creating 5 different query blocks. 1 of them query db called default and 4 of them query db called web1
Partial code as follows:
#import "ABSRD/MODELS/AbsrdConf.h"
#import "ABSRD/MODELS/QueryBlockBuster.h"
#import "ABSRD/MODELS/DbManager.h"
#import "ABSRD/MODELS/DbConnector.h"
// first step is to setup the conf for both databases we are going to use
NSDictionary *conf = @{ @"absrd":
@{@"databases":@{
@"default": @{
@"type": @"mysql" ,
@"port": @3306,
@"host":@"localhost",
@"user": @"root",
@"password":@"myroot",
@"database": @"fb"
},
@"web1": @{
@"type": @"mysql",
@"port": @3306,
@"host":@"web1",
@"user": @"root",
@"password":@"myroot",
@"database": @"Proficiency"
}
}
}};
// listenSocket = [[AsyncSocket alloc] initWithDelegate:self];
[AbsrdConf setConfiguration:conf];
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"];
Make sure you have the mysql client installed in your mac. Go to the following link for details: http://dev.mysql.com/doc/refman/5.0/en/macosx-installation.html
After installation if you didn't try anything fancy you should have a directory exactly like the following: /usr/local/mysql This means you should have the following paths that you will use in the project settings /usr/local/mysql/lib /usr/local/mysql/include
Now here is another fancy step. After installation inside /usr/local/mysql/lib there should be a file called libmysqlclient.18.dylib or libmysqlclient.19.dylib or 20 or so. Version doesn't matter.
/usr/local/mysql is a virtual link. Find the actual link and run a command like the following (please don't ask. If you don't do it, XCODE will not be able to perform sql queries). The goal in here is to find the actual full path of file libmysqlclient.18.dylib (or whatever version you get)
sudo install_name_tool -id /usr/local/mysql-5.5.14-osx10.6-x86_64/lib/libmysqlclient.18.dylib /usr/local/mysql-5.5.14-osx10.6-x86_64/lib/libmysqlclient.18.dylib
The actual link, as I implied before, can vary.
--------
XCODE Steps
1. Add the following path to "header search paths under "build settings" /usr/local/mysql/include
2. Add the following path to "library search paths under "build settings" /usr/local/mysql/bin
3. Drag and drop file libmysqlclient.18.dylib (or whatever number you get) to your project. You can chose to copy it or reference it in your project. I chose to reference it.
4. Now drag and drop the ABSRD path into your project inside the github project for absrd. Make sure you chose the "copy items into destination" and "create folder references" and the target must checked.