Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/freesuraj/coredatamanager
A simple core-data manager library for Objective C
https://github.com/freesuraj/coredatamanager
Last synced: about 1 month ago
JSON representation
A simple core-data manager library for Objective C
- Host: GitHub
- URL: https://github.com/freesuraj/coredatamanager
- Owner: freesuraj
- Created: 2012-07-06T14:43:50.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-07-06T14:57:56.000Z (over 12 years ago)
- Last Synced: 2023-03-24T11:53:11.668Z (over 1 year ago)
- Size: 92.8 KB
- Stars: 2
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Overview
CoreDataManager is a simple core data management library that supports following SQL operations:
- Insert
- Update
- Delete
- Search### Creating shared Instance and global context
* create a shared Instance of `CoreDataManager` by the following code:+ (CoreDataManager *)sharedCoreDataManager;
* A global `NSManagedObjectContext` (one for all database operations throught) will be created using following method:
+ (NSManagedObjectContext *)globalContext;
#### Insert
*Insert a record to an existing table*+ (NSError *)insertARecordWithRecordValues:(NSDictionary *)values ToTable:(NSString *)tableName InContext:(NSManagedObjectContext *)context;
#### Update
*Update a record for a property (if the record exists) in an existing table*+ (NSError *)updateARecord:(NSManagedObject *)record WithNewRecordValues:(NSDictionary *)values InTable:(NSString *)tableName InContext:(NSManagedObjectContext *)context;
#### Delete
*Delete a record from an existing table*
+ (NSError *)deleteARecord:(NSManagedObject *)record InContext:(NSManagedObjectContext *)context;#### Search
1. *fetch all records from a single table*+ (NSMutableArray *)fetchAllRecordsFromTable:(NSString *)tableName InContext:(NSManagedObjectContext *)context;
2. *fetch all records sorted by certain attribute*+ (NSMutableArray *)fetchAllRecordsFromTable:(NSString *)tableName sortedByAttribute:(NSString *)attributeName IsAscending:(BOOL)ascending InContext:(NSManagedObjectContext *)context;
3. *fetch records matched by a predicate*
+ (NSMutableArray *)fetchRecordsFromTable:(NSString *)tableName MatchedByPredicate:(NSPredicate *)predicate InContext:(NSManagedObjectContext *)context;
4. *fetch records matched by a predicate, and sorted by certain attribute*
+ (NSMutableArray *)fetchRecordsFromTable:(NSString *)tableName MatchedByPredicate:(NSPredicate *)predicate sortedByAttribute:(NSString *)attributeName IsAscending:(BOOL)ascending InContext:(NSManagedObjectContext *)context;
5. *fetch records defined by the criteria in `NSFetchRequest`*
+ (NSMutableArray *)fetchRecordsWithFetchRequest:(NSFetchRequest *)request InContext:(NSManagedObjectContext *)context;
6. *fetch records with a value for an attribute*
+ (NSMutableArray *)fetchRecordsFromTable:(NSString *)tableName AttributeName:(NSString *)attribute AndValue:(id)value InContext:(NSManagedObjectContext *)context;
7. *fetch records with a value for an attribute, and sorted by certain attribute*
+ (NSMutableArray *)fetchRecordsFromTable:(NSString *)tableName AttributeName:(NSString *)attribute AndValue:(id)value sortedByAttribute:(NSString *)attributeName IsAscending:(BOOL)ascending InContext:(NSManagedObjectContext *)context;
8. *fetch the unique record with the given predicate*
+ (id)fetchFirstRecordFromTable:(NSString *)tableName withPredicate:(NSPredicate *)predicate InContext:(NSManagedObjectContext *)context;
9. *fetch the first record with the given predicate, and sorted by certain attribute*
+ (id)fetchFirstRecordFromTable:(NSString *)tableName withPredicate:(NSPredicate *)predicate sortedByAttribute:(NSString *)attributeName IsAscending:(BOOL)ascending InContext:(NSManagedObjectContext *)context;
### More Features
Obviously this is a very very simple core-data handler, for complicated operations you can look into [MagicalRecord](http://github.com/magicalpanda/MagicalRecord). More Features will be updated as required in future.**Thank You ! **