All Projects → Chasel-Shao → Crystdb

Chasel-Shao / Crystdb

Licence: mit
CrystDB is a thread-safe and convenient Object Relational Mapping database that based on SQLite.

Projects that are alternatives of or similar to Crystdb

Csmodel
CSModel is a concise and efficient model framework for iOS/OSX, and provides nested Model to compare values and copy values.
Stars: ✭ 192 (+31.51%)
Mutual labels:  model, runtime
Swizzleswift
Swizzle selectors with just one clean and elegant API
Stars: ✭ 140 (-4.11%)
Mutual labels:  runtime
Dotnetbook
.NET Platform Architecture book (English, Chinese, Russian)
Stars: ✭ 1,763 (+1107.53%)
Mutual labels:  runtime
Eager Load Pivot Relations
Eager load pivot relations for Laravel Eloquent's BelongsToMany relation.
Stars: ✭ 134 (-8.22%)
Mutual labels:  model
Prowide Core
Model and parsers for all SWIFT MT (FIN) messages
Stars: ✭ 125 (-14.38%)
Mutual labels:  model
Framework
Strongly-typed JavaScript object with support for validation and error handling.
Stars: ✭ 136 (-6.85%)
Mutual labels:  model
Covasim
COVID-19 Agent-based Simulator (Covasim): a model for exploring coronavirus dynamics and interventions
Stars: ✭ 122 (-16.44%)
Mutual labels:  model
Jmri
JMRI model railroad digital command & control software
Stars: ✭ 143 (-2.05%)
Mutual labels:  model
Nconcern
NConcern .NET AOP Framework
Stars: ✭ 139 (-4.79%)
Mutual labels:  runtime
Debugengine
Delphi debug framework
Stars: ✭ 133 (-8.9%)
Mutual labels:  runtime
Readme Model
💾 A beautiful readme model for you to put in your projects.
Stars: ✭ 131 (-10.27%)
Mutual labels:  model
Runtypes
Runtime validation for static types
Stars: ✭ 1,950 (+1235.62%)
Mutual labels:  runtime
Ngx Model
Angular Model. Simple state management with minimalistic API, one way data flow, multiple model support and immutable data exposed as RxJS Observable.
Stars: ✭ 137 (-6.16%)
Mutual labels:  model
Codeigniter Model
CodeIgniter 3 Active Record (ORM) Standard Model with Laravel Eloquent & Yii2 AR like
Stars: ✭ 124 (-15.07%)
Mutual labels:  model
Django Treenode
probably the best abstract model / admin for your tree based stuff. 🌳
Stars: ✭ 142 (-2.74%)
Mutual labels:  model
Awesome Python Models
A curated list of awesome Python libraries, which implement models, schemas, serializers/deserializers, ODM's/ORM's, Active Records or similar patterns.
Stars: ✭ 124 (-15.07%)
Mutual labels:  model
Voc
A physical model of the human vocal tract using literate programming, based on Pink Trombone.
Stars: ✭ 129 (-11.64%)
Mutual labels:  model
Sandman2
Automatically generate a RESTful API service for your legacy database. No code required!
Stars: ✭ 1,765 (+1108.9%)
Mutual labels:  sqlite-database
Rapidgui
Unity OnGUI(IMGUI) extensions for Rapid prototyping/development
Stars: ✭ 144 (-1.37%)
Mutual labels:  runtime
Gf Cli
GoFrame Command Line Interface, which is your helpmate for building GoFrame application with convenience.
Stars: ✭ 143 (-2.05%)
Mutual labels:  model

CrystDB

License MIT  CocoaPods 

📖 English Documentation | 📖 中文文档

Introduce

CrystDB is a thread-safe and convenient Object Relational Mapping database that based on SQLite. It's lightweight and high-efficiency. When dealing with simple data object, it has processing speed especially in the aspect of the operation of query and storage. It's a fabulous alternative to Realm and Core Data.

Features

  • Lightweight: Less source files, easily and conveniently to use
  • Noninvasive: No need to inherit other base class or use other auxiliary class
  • Supported Type: Support almost all of the types of Objective-C and C
  • Safe Mapping: Check every object types and can be safe in conversion between the SQLite and Objective-C
  • High Performance: Fast storage speed, and the stroage speed of the simple object is 2-4 times fast than Realm, as well as the query speed is also fast than Realm

Performance

The time cost of disposing 2000 times GithubUser objects (iPhone 6s).

Benchmark result

Getting Started

Create and Open the database

// 1. create an default database:
CrystManager *db = [CrystManager defaultCrystDB];

// 2. create an database with the name of `Person`:
CrystManager *db = [[CrystManager alloc] initWithName:@"Person"];

Add and Update objects

// Person Model
@interface Person : NSObject <CrystDB>
@property (nonatomic,assign) UInt64 uid;
@property (nonatomic,copy) NSString *name;
@property (nonatomic,assign) NSInteger age;
@end
@implementation Person
@end

// 0. Create an Person object:
Person *p =  [[Person alloc] init];
p.uid = 8082;
p.name = @"Ares";
p.age = 27;

// 1. Add an object,if there have been the object,then update the object:
BOOL result = [db addOrUpdateObject:p];

// 2. Add an object, if there have benn the object, then return with no processing:
BOOL result = [db addOrIgnoreObject:p];

// 3. If the object is already in the database and the object also have implemented the method of `CrystDBPrimaryKey`, then you can update the object directly(otherwise it's recommended to use `addOrUpdateObject:` method instead):
BOOL result = [db updateObject:p];

// 4. Use Transaction:
[db inTransaction:^(BOOL * _Nonnull rollback) {
   BOOL result = [db addOrUpdateObject:p];
   if (result == NO) {
      *rollback = YES;
   }
}];  

Query objects

// 1. Query objects with the Class of this object:
NSArray *persons = [db queryWithClass:[Person class] condition:nil];

// 2. Query objects with conditions:
NSArray *persons = [db queryWithClass:[Person class] condition:@"age > 25 or name == 'Ares' "];

// 3. Query objects with format conditions:
NSArray *persons = [db queryWithClass:[Person class] conditions:@"age > %d or name == '%@' ",25,@"Ares"];

// 4. Query with sql sentence syntax:
NSArray *persons = [db queryWithClass:[Person class] where:@"age > 8082" orderBy:@"uid desc" limit:@"1,10"];

Delete objects

// 1. Delete objects with conditions:
BOOL result = [db deleteClass:[Person class] where:@"name = 'Ares' "];

// 2. Delete all the object related to the class:
BOOL result = [db dropClass:[Person class]];

// 3. Delete all the objects in this database:
BOOL result = [db dropAll];

// 4. Delete the object which implement the method of `CrystDBPrimaryKey` and the object has the vlaue of primary key, otherwise it will fail:
BOOL result = [db deleteObject:p];

Use Protocol

// 1. Specify the primary key
+ (NSString *)CrystDBPrimaryKey{
    return @"uid";
}

// 2. Appoint the default database of this object
+ (NSString *)CrystDBName{
    return @"child.db";
}

// 3. Set the property whitelist of this object
+ (NSArray<NSString *> *)CrystDBWhitelistProperties{
    return @[@"uid"@"name"@"age"];
}

// 4. Set the property blacklist of this object
+ (NSArray<NSString *> *)CrystDBBlacklistProperties{
    return @[@"age"];
}

// 5. If the object has parent class which have properties involved
+ (BOOL)CrystDBObjectIsHasSuperClass{
    return YES;
}

// 6. If there are objects nested in this object, it needs to implement the Coding method, or it's strongly recommended to use `CSModel` to implement the following method:
- (void)encodeWithCoder:(NSCoder *)aCoder{
    [self cs_encode:aCoder];
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    return [self cs_decoder:aDecoder];
}

Use the Category Method to simpify the call

// 1. Add an object,if there have been the object,then update the object:
BOOL result = [p cs_addOrUpdateToDB];

// 2. Add an object with no processing if there have benn the object:
BOOL result = [p cs_addOrIgnoreToDB];

// 3. Query objects with conditions:
Person *p = [Person cs_queryObjectsWithCondition:@"age > 25"];

// 4. Query the object by primary key which must implement the `CrystDBPrimaryKey` method:
Person *p = [Person cs_queryObjectOnPrimary:@"8082"];

// 5. Query the number of all the objects:
NSInteger count = [Person cs_queryObjectCount];

// 6. Query the create time of an object:
NSInteger createTime = [p cs_queryObjectCreateTime];

// 7. Query the update time of an object:
NSInteger updateTime = [p cs_queryObjectUpdateTime];

// 8. Delete objects with the conditions:
[Person cs_deleteFromDBWithCondition:@"name = 'Ares' "];

// 9. Delete all the objects in the database:
BOOL result = [p cs_deleteFromDB];
  
// 10. Execute the transaction in a block
[Person cs_inTransaction:^(CrystDB *db, BOOL *rollback) {
   BOOL result = [db addOrUpdateObject:p];
   if (result == NO) {
      *rollback = YES;
    }
}];

Installation

Installation with CocoaPods

  1. Specify the pod 'CrystDB' in your Podfile
  2. Then run the pod install or pod update
  3. Import the header file <CrystDB/CrystDB.h>

Manual Installation

  1. Download the CrystDB
  2. Import the CrystDB.h and the relevent source files

Author

License

CrystDB is released under the MIT license. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].