Skip to content

Commit

Permalink
Add example features, and block comments in library classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Ney committed Nov 2, 2014
1 parent 1a84710 commit f10a51b
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Example/Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<string>Color</string>
<string>Power</string>
</scopeButtonTitles>
<connections>
<outlet property="delegate" destination="MO9-LZ-sCd" id="ZnA-LM-wJL"/>
</connections>
</searchBar>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="cellIdentifier" textLabel="axc-oX-wmy" detailTextLabel="HJ2-O9-Jii" style="IBUITableViewCellStyleSubtitle" id="loa-MX-U9a">
Expand Down
8 changes: 7 additions & 1 deletion Example/Example/RootTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@

#import <UIKit/UIKit.h>

@interface RootTableViewController : UITableViewController
@interface RootTableViewController : UITableViewController <UISearchBarDelegate>

@property (nonatomic, strong) NSMutableArray *items;

@property (nonatomic) NSInteger orderLastIndex;
@property (nonatomic, strong) NSString *orderProperty;
@property (nonatomic) BOOL orderDirection;

@property (nonatomic, strong) NSString *where;

#pragma mark - Actions

- (IBAction)actionAddEntity:(id)sender;
Expand Down
44 changes: 43 additions & 1 deletion Example/Example/RootTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ - (void)viewDidLoad {

NSLog(@"DB path: %@ ", [[SQPDatabase sharedInstance] getDdPath]);

self.items = [Car SQPFetchAllWhere:nil orderBy:nil];
self.items = [Car SQPFetchAll];

/*
// If database exists:
Expand Down Expand Up @@ -146,6 +146,48 @@ - (IBAction)actionClearAll:(id)sender {
[self.tableView reloadData];
}

#pragma mark - UISearchBar Delagete

-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
[searchBar resignFirstResponder];
}

-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {

NSString *searchText = searchBar.text;

self.where = [NSString stringWithFormat:@"name LIKE '%%%@%%'", searchText];

self.items = [Car SQPFetchAllWhere:self.where orderBy:self.orderProperty];

[self.tableView reloadData];
}

-(void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope {

if (self.orderLastIndex == selectedScope) {
self.orderDirection = !self.orderDirection;
}

if (selectedScope == 0) {
self.orderProperty = @"name";
} else if (selectedScope == 1) {
self.orderProperty = @"color";
} else {
self.orderProperty = @"power";
}

if (self.orderDirection == YES) {
self.orderProperty = [NSString stringWithFormat:@"%@ DESC", self.orderProperty];
}

self.orderLastIndex = selectedScope;

self.items = [Car SQPFetchAllWhere:self.where orderBy:self.orderProperty];

[self.tableView reloadData];
}

#pragma mark - UITableView Datasource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Sources/SQPObject.m"
timestampString = "436619842.411582"
timestampString = "436627409.361983"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "509"
endingLineNumber = "509"
startingLineNumber = "521"
endingLineNumber = "521"
landmarkName = "+SQPObjectFromClassName:"
landmarkType = "5">
</BreakpointContent>
Expand Down Expand Up @@ -186,12 +186,12 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Sources/SQPObject.m"
timestampString = "436619839.243175"
timestampString = "436626532.888654"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "337"
endingLineNumber = "337"
landmarkName = "+SQPFetchAllForTable:andClassName:Where:orderBy:"
startingLineNumber = "344"
endingLineNumber = "344"
landmarkName = "+SQPFetchAllForTable:andClassName:Where:orderBy:pageIndex:itemsPerPage:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
Expand All @@ -202,12 +202,76 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Sources/SQPObject.m"
timestampString = "436619870.492438"
timestampString = "436626532.888654"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "345"
endingLineNumber = "345"
landmarkName = "+SQPFetchAllForTable:andClassName:Where:orderBy:pageIndex:itemsPerPage:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Example/Example/RootTableViewController.m"
timestampString = "436626697.407177"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "157"
endingLineNumber = "157"
landmarkName = "-searchBarSearchButtonClicked:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Example/Example/RootTableViewController.m"
timestampString = "436626775.229575"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "161"
endingLineNumber = "161"
landmarkName = "-searchBarSearchButtonClicked:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Example/Example/RootTableViewController.m"
timestampString = "436626798.244228"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "162"
endingLineNumber = "162"
landmarkName = "-searchBarSearchButtonClicked:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Example/Example/RootTableViewController.m"
timestampString = "436626799.764429"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "338"
endingLineNumber = "338"
landmarkName = "+SQPFetchAllForTable:andClassName:Where:orderBy:"
startingLineNumber = "160"
endingLineNumber = "160"
landmarkName = "-searchBarSearchButtonClicked:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
Expand Down
35 changes: 35 additions & 0 deletions Sources/SQPDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,53 @@
NSString *_dbPath;
}

/**
* Get the main instance of the database manager.
*
* @return Instance.
*/
+ (id)sharedInstance;

/**
* Setup the database.
*
* @param dbName Name of the database.
*/
- (void)setupDatabaseWithName:(NSString*)dbName;

/**
* Return the name of the database.
*
* @return Database name.
*/
- (NSString*)getDdName;

/**
* Return the path of the database.
*
* @return Path of the database.
*/
- (NSString*)getDdPath;

/**
* Database connector.
*
* @return Database connector.
*/
- (FMDatabase*)database;

/**
* Check if the database file exists.
*
* @return Return YES if the database exists.
*/
- (BOOL)databaseExists;

/**
* Remove the database.
*
* @return Remove the database.
*/
- (BOOL)removeDatabase;

@end
92 changes: 92 additions & 0 deletions Sources/SQPObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,123 @@

@interface SQPObject : NSObject

/**
* The name of the entity class.
*/
@property (nonatomic, strong) NSString *SQPClassName;

/**
* The name of teh associed table of the entity.
*/
@property (nonatomic, strong) NSString *SQPTableName;

/**
* Array of class properties.
*/
@property (nonatomic, strong) NSArray *SQPProperties;

/**
* Unique entity object identifier.
*/
@property (nonatomic, strong) NSString *objectID;

/**
* Set at YES, if you want remove the entity object.
* Need to call the SQPSaveEntity method to apply de DELETE SQL order.
*/
@property (nonatomic) BOOL deleteObject;

/**
* Create an entity of your object.
*
* @return Entity object
*/
+ (id)SQPCreateEntity;

/**
* Save the modification of the entity object.
*
* @return Return YES if the changes apply with succes.
*/
- (BOOL)SQPSaveEntity;

/**
* Return every entities save of table.
*
* @return Array of entities.
*/
+ (NSMutableArray*)SQPFetchAll;

/**
* Return every entities save of table, with filtering conditions.
*
* @param queryOptions Filtering conditions (clause SQL WHERE).
*
* @return Array of entities.
*/
+ (NSMutableArray*)SQPFetchAllWhere:(NSString*)queryOptions;

/**
* Return every entities save of table, with filtering conditions and order.
*
* @param queryOptions Filtering conditions (clause SQL WHERE).
* @param orderOptions Ordering conditions (clause SQL ORDER BY).
*
* @return Array of entities.
*/
+ (NSMutableArray*)SQPFetchAllWhere:(NSString*)queryOptions orderBy:(NSString*)orderOptions;

/**
* Return every entities save of table, with filtering conditions and order, and pagination system.
*
* @param queryOptions Filtering conditions (clause SQL WHERE).
* @param orderOptions Ordering conditions (clause SQL ORDER BY).
* @param pageIndex Page index (start at 0 value).
* @param itemsPerPage Number of items per page.
*
* @return Array of entities.
*/
+ (NSMutableArray*)SQPFetchAllWhere:(NSString*)queryOptions orderBy:(NSString*)orderOptions pageIndex:(NSInteger)pageIndex itemsPerPage:(NSInteger)itemsPerPage;

/**
* Return one entity object by filtering conditions.
*
* @param queryOptions Filtering conditions (clause SQL WHERE).
*
* @return The resulting entity object.
*/
+ (id)SQPFetchOneWhere:(NSString*)queryOptions;

/**
* Return one entity object.
*
* @param objectID Unique entity object identifier.
*
* @return The resulting entity object.
*/
+ (id)SQPFetchOneByID:(NSString*)objectID;

/**
* Return the number of entities save into the associated table.
*
* @return Number of entities.
*/
+ (long long)SQPCountAll;

/**
* Return the number of entities save into the associated table, with filtering conditions.
*
* @param queryOptions Filtering conditions (clause SQL WHERE).
*
* @return Number of entities.
*/
+ (long long)SQPCountAllWhere:(NSString*)queryOptions;

/**
* Remove all entities of the table (TRUNCATE).
*
* @return Return YES when the table is truncate.
*/
+ (BOOL)SQPTruncateAll;

@end
Loading

0 comments on commit f10a51b

Please sign in to comment.