iOS Development line of code series: one line to get the database

Source: Internet
Author: User

Principle

The corresponding relationship between IOS and SQL

Model class structure = SQL table structure

Model instance = one row in the SQL table

Properties of the model instance-a column in the SQL table


The corresponding model and table

@interface Testmodel:nsobject@property (Assign, nonatomic) Nsinteger age; @property (assign, nonatomic) CGFloat height;@ Property (Assign, nonatomic) long distance; @property (assign, nonatomic) double maxdistance; @property (Assign, nonatomic ) BOOL IsOK; @property (assign, nonatomic) char Mchar; @property (assign, nonatomic) CGRect rect; @property (Assign, Nonatomi  c) Cgpoint Point; @property (assign, nonatomic) cgsize size; @property (assign, nonatomic) Nsrange range; @property (Strong, nonatomic) NSNumber *number; @property (Strong, nonatomic) NSString *string; @property (Strong, nonatomic) Uicolor *color;  @property (Strong, nonatomic) NSDate *date; @property (Strong, nonatomic) NSData *data;//Convert to Data@property (strong, nonatomic) Nsvalue *value; @property (Strong, nonatomic) UIImage *image; @end


The appropriate table structure is table Testmodel (age type,height type,distance type,isok Type,mchar type,...)


Method

Here are some available methods, still in good condition ...


+ (modeltotablemap*) getmodeltotablemap;+ (nsstring*) getdbpath;+ (nsstring*) gettablename;+ (NSArray*) GetPrimaryKeys ; + (Nsdictionary *) getpropertytocolumnmap;+ (nsdictionary *) getdefaultvaluedictionary;+ (NSDictionary *) getlengthdictionary;+ (Nsdictionary *) getcheckvaluedictionary;+ (nsdictionary *) getisuniquedictionary;+ ( Nsdictionary *) getisnotnulldictionary;+ (BOOL) shouldmodeltotablemapcontainparentproperties;+ (BOOL) shouldmodeltotablemapcontainselfproperties;+ (NSString *) getdateformatterstring;+ (NSString *) Getdbimagepathwithimagename: (NSString *) imgname; + (NSString *) Getdbdatapathwithdataname: (NSString *) dataName;+ ( BOOL) createtable;+ (BOOL) droptable;+ (ID) Firstmodelwhere: (NSObject *) where;+ (ID) Firstmodelwhere: (NSObject *) where By: (nsstring*), + (Nsarray *) allmodels;+ (Nsarray *) Findmodelswhere: (NSObject *) where;+ (Nsarray *) Findmodelswhere: (NSObject *) where the clause is: (nsstring*) by offset: (int) offset count: (int) count;+ (BOOL) Insertmodel: (NSObject *) model;+ (BOOL) insertmodelwhennotexists: (NSObject *) model;+ (BOOL) Deletemodel: (NSObject *) model;+ (BOOL) Deletemodelswhere: (NSObject *) where;+ (BOOL) Updatemodelswithmodel: (NSObject *) model Where: (NSObject *) where;+ (BOOL) updatemodelswithdictionary: (Nsdictionary *) DIC Where: (NSObject *) where;+ (BOOL) ismodelexists: (NSObject *) model;-(BOOL) savemodel;-(BOOL) deletemodel;-(BOOL) Updatemodel: (NSObject *) thenewmodel;-(BOOL) updatemodelwithdictionary: (Nsdictionary *) dic;


Use

Testmodel *model = [[Testmodel alloc] init];model.age = 20;model.image = [UIImage imagenamed:@ "img.jpg"];
Add [model Savemodel]
Delete [model Deletemodel]
Change [model updatemodelwithdictionary:@{@ "age": @ (21)}]
Find [Testmodel Allmodels]

: Click here

iOS Development line of code series: one line to get the database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.