SlideShare a Scribd company logo
1 of 34
DBACCESS RESEARCH
2016/6/3
HappyMan
DBACCESS IOS ORM
• [DBAccess] is a fully featured and FREE to use ORM for iOS.
• Replace CoreData whilst keeping your existing managed objects, but dump the
predicates and long-winded syntax.
• Instead use a simple and clean object syntax, with fast and concise inline
queries.
• DBAccess even has a conversion method to migrate your existing CoreData
tables across.
• Regularly updated and in constant use within many public applications it thrives
on feedback from other developers and is supported by the authors via
StackOverflow or directly via email.
• It's mantra is simple, to be fast, simple to implement and the first choice for any
WHY SHOULD I USE
[DBACCESS] ?
• An ORM should not be a chore to work with,
or require you to change your way of working
to compensate for its shortcomings. With
[DBAccess] you simply add it to your project
and start using it straight away.
WHY SHOULD I USE
[DBACCESS] ?
• The developer has full control over how the
ORM operates, deciding where it puts its
files, how queries are performed and on
which thread. Objects can be managed or
unmanaged, whilst being members of
domains which may share changes or be
isolated from them.
WHY SHOULD I USE
[DBACCESS] ?
• If memory is a concern, you can mix and
match lightweight objects to preserve system
resources when you are expecting large
result sets, or retrieve only the properties
you need with the remainder being lazily
loaded when accessed.
HEADLINE FEATURES
• Automatic modeling and upgrading from your class structures.
• Amazingly simple FLUENT interface for dealing with the ORM
• KILLER event model, for individual objects or tables. Makes coding apps a breeze
• Inline or Async queries
• Transaction support
• Managed and unmanaged objects supported to be used however you want
• Relationships mirror your class structures automatically, and all relationships are
automatically indexed
• Property level encryption so databases remain human readable whilst securing
individual columns.
SHARK吃掉DBACCESS
參考文件轉移
• http://www.db-access.org/
• http://sharkorm.com/
• Fast, Fluid, Effective
an open source iOS ORM, designed from the
start to be low maintenance and natural to use,
developers choose shark for its power and
simplicity.
SETTING UP YOUR
PROJECT
• AppDelegate.h
#import <UIKit/UIKit.h>
#import <DBAccess/DBAccess.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, DBDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
SETTING UP YOUR
PROJECT
• AppDelegate.m
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[DBAccess setDelegate:self];
[DBAccess openDatabaseNamed:@"happyDatabase"];
return YES;
}
@end
SQLITE位置
CREATING DATA OBJECTS
• Person.h
#import <Foundation/Foundation.h>
#import <DBAccess/DBAccess.h>
@interface Person : DBObject
@property NSString *name;
@property NSInteger age;
@property NSString *email;
@property NSString *phone;
@end
CREATING DATA OBJECTS
• Person.m
#import "Person.h"
@implementation Person
@dynamic name, age, email, phone;
@end
CREATING OBJECTS,
SETTING VALUES &
PERSISTANCE-(void)createData
{
// Create a new object
Person *thisPerson = [Person new];
// Set some properties
thisPerson.age = 27;
thisPerson.email = @"happyboy@gmail.com";
thisPerson.name = @"HappyBoy";
thisPerson.phone = @"0987654321";
// Persist the object into the datastore
[thisPerson commit];
// Create a new object
Person *thatPerson = [Person new];
// Set some properties
thatPerson.age = 11;
thatPerson.email = @"happygirl@gmail.com";
thatPerson.name = @"HappyGirl";
thatPerson.phone = @"0912345678";
// Persist the object into the datastore
[thatPerson commit];
}
QUERYING OBJECTS
-(void)fetchData
{
DBResultSet *results = [[[[[Person query]
where:@"age <= 40"]
limit:99]
orderBy:@"name"]
fetch];
for (Person *person in results) {
NSString *result = [NSString stringWithFormat:@"name: %@, age: %li, email: %@", person.name, (long)person.age,
person.email];
NSLog(@"%@", result);
}
displayTV.text = [[results description] stringByReplacingOccurrencesOfString:@"n" withString:@"n"];
}
DBRESULTSET *RESULTS
真不敢相信可以直接在console列印出來!!!
-------------------------------------------------------------------------------------------
| Entity : Person Primary Key : Id Value: 25.000000 |
-------------------------------------------------------------------------------------------
| Field Name | Type | Value |
-------------------------------------------------------------------------------------------
| age | NUMBER | 11.000000 |
| email | TEXT | happygirl@gmail.com |
| phone | TEXT | 0912345678 |
| name | TEXT | HappyGirl |
| Id | NUMBER | 25.000000 |
-------------------------------------------------------------------------------------------
| Relationships |
-------------------------------------------------------------------------------------------
| Entity Name | Target Table | Status |
-------------------------------------------------------------------------------------------
| NONE | | |
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
| Entity : Person Primary Key : Id Value: 24.000000 |
-------------------------------------------------------------------------------------------
| Field Name | Type | Value |
-------------------------------------------------------------------------------------------
| age | NUMBER | 27.000000 |
| email | TEXT | happyboy@gmail.com |
| phone | TEXT | 0987654321 |
| name | TEXT | HappyBoy |
| Id | NUMBER | 24.000000 |
-------------------------------------------------------------------------------------------
| Relationships |
-------------------------------------------------------------------------------------------
| Entity Name | Target Table | Status |
-------------------------------------------------------------------------------------------
| NONE | | |
-------------------------------------------------------------------------------------------
REMOVING OBJECTS
-(void)removeData
{
for (Person* person in [[Person query] fetch]) {
[person remove];
}
// or the shorthand is to use the removeAll method on the DBResultSet object
[[[Person query] fetch] removeAll];
}
OTHER TYPES OF QUERY
-(void)queryData
{
/* count the rows within the Person table */
int count = [[Person query] count];
/* add all of the ages together */
double total = [[Person query] sumOf:@"age"];
/* group all the people together by the surname property */
NSDictionary *peopleBySurname = [[Person query] groupBy:@"name"];
/* get just the primary keys for a query, useful to save memory */
NSArray *ids = [[Person query] ids];
}
創建時可以不設值
• 預設為0或NULL
可設定巢狀
• Person.h
#import <Foundation/Foundation.h>
#import <DBAccess/DBAccess.h>
@interface Person : DBObject
@property NSString *name;
@property NSInteger age;
@property NSString *email;
@property NSString *phone;
@property Pet *pet;
@end
資料庫巢狀
• 記錄ID
問題:撈回無法參照
• Status: Unloaded
-------------------------------------------------------------------------------------------
| Entity : Person Primary Key : Id Value: 5.000000 |
-------------------------------------------------------------------------------------------
| Field Name | Type | Value |
-------------------------------------------------------------------------------------------
| age | NUMBER | 27.000000 |
| name | UNKNOWN | Nil value |
| phone | UNKNOWN | Nil value |
| pet | NUMBER | 5.000000 |
| email | TEXT | happyboy@gmail.com |
| Id | NUMBER | 5.000000 |
-------------------------------------------------------------------------------------------
| Relationships |
-------------------------------------------------------------------------------------------
| Entity Name | Target Table | Status |
-------------------------------------------------------------------------------------------
| pet | Pet | Unloaded |
-------------------------------------------------------------------------------------------
可讀取外來資料庫
建立對應CLASS
• Pet.h
#import <DBAccess/DBAccess.h>
@interface Pet : DBObject
@property NSString *name;
@property NSString *breed;
@property NSString *photo;
@property NSInteger birthday;
@property NSInteger gender;
@property NSInteger type;
@property NSInteger neuter;
@property NSInteger sortOrder;
@property NSInteger createTime;
@end
建立對應CLASS
• Pet.m
#import "Pet.h"
@implementation Pet
@dynamic name, birthday, breed, photo, gender, type, neuter, sortOrder, createTime;
@end
取得顯示
for (Pet *pet in [[Pet query] fetch]) {
NSString *result = [NSString stringWithFormat:@"name: %@, birthday: %li, photo: %@", pet.name, (long)pet.birthday, pet.photo];
NSLog(@"%@", result);
}
• name: happyPet, birthday: 0, photo: (null)
問題:無法繼承
• Superman.h
#import "Person.h"
@interface Superman : Person
@property NSString *weapon;
@property NSInteger power;
@end
問題:無法繼承
• Superman.m
#import "Superman.h"
@implementation Superman
@dynamic weapon, power;
@end
問題:無法繼承
• 編譯時沒事,執行時掛掉
• Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '***
setObjectForKey: key cannot be nil’
Superman *thisSuperman = [Superman new];
// Set some properties
thisSuperman.age = 27;
thisSuperman.email = @"QQQhappyboy@gmail.com";
thisSuperman.pet = thisPet;
thisSuperman.power = 99;
[thisSuperman commit];
QUERIES & RESULTS
• DEALING WITH DATA
• RETRIEVING OBJECTS
• WHERE CLAUSES
• JOIN
• ASYNC QUERIES
• THE RESULTS (AKA DBRESULTSET*)
• DIFFERENT TYPES OF QUERY (COUNT, SUM)
THE EVENT MODEL
• The event handler is probably DBAccess’s most useful
feature, it enables the developer to ‘hook’ into the events
raised by the database engine.
• There are 3 event types, INSERT, UPDATE & DELETE.
These are bitwise operators so can be combined together
to register blocks against multiple events at the same time.
• There are two DBEventHandler objects you can use, one
derived from the class object and another that can be used
from within an instance of a class.
RELATIONSHIPS
• UNDERSTANDING HOW RELATIONSHIPS
WORK
• NESTED OBJECTS
• ONE TO MANY RELATIONSHIPS
TRANSACTIONS
• Transactions in DBAccess are handled using
a class method on DBTransaction,
transactions can be started from anywhere
at anytime, are entirely thread-safe. Any
modifications to records that are due to
event triggers being raised are also included
within the transaction and rolled back on
failure.
REFERENCE
• Cocoapods - DBAccess
https://cocoapods.org/pods/DBAccess
• Github - DBAccess
https://github.com/editfmah/DBAccess
• [DBAccess]
http://www.db-access.org/

More Related Content

Similar to DBAccess 研究

User Profiles: I Didn't Know I Could Do That? (Demo Slides)
User Profiles:  I Didn't Know I Could Do That?  (Demo Slides)User Profiles:  I Didn't Know I Could Do That?  (Demo Slides)
User Profiles: I Didn't Know I Could Do That? (Demo Slides)Stacy Deere
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLEDB
 
Getting Started With Apex REST Services
Getting Started With Apex REST ServicesGetting Started With Apex REST Services
Getting Started With Apex REST ServicesSalesforce Developers
 
Cloud Integration with Database.com and Heroku
Cloud Integration with Database.com and HerokuCloud Integration with Database.com and Heroku
Cloud Integration with Database.com and HerokuSalesforce Developers
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLEDB
 
Using PostgreSQL for Data Privacy
Using PostgreSQL for Data PrivacyUsing PostgreSQL for Data Privacy
Using PostgreSQL for Data PrivacyMason Sharp
 
MySQL 8.0 Released Update
MySQL 8.0 Released UpdateMySQL 8.0 Released Update
MySQL 8.0 Released UpdateKeith Hollman
 
Building Ranking Infrastructure: Data-Driven, Lean, Flexible - Sergii Khomenk...
Building Ranking Infrastructure: Data-Driven, Lean, Flexible - Sergii Khomenk...Building Ranking Infrastructure: Data-Driven, Lean, Flexible - Sergii Khomenk...
Building Ranking Infrastructure: Data-Driven, Lean, Flexible - Sergii Khomenk...Sergii Khomenko
 
Using power shell to improve sharepoint management
Using power shell to improve sharepoint managementUsing power shell to improve sharepoint management
Using power shell to improve sharepoint managementMitch Darrow
 
Engage 2013 - Flexible Data Access with APIs
Engage 2013 - Flexible Data Access with APIsEngage 2013 - Flexible Data Access with APIs
Engage 2013 - Flexible Data Access with APIsWebtrends
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLEDB
 
7 Awesomely Techie Jobs
7 Awesomely Techie Jobs7 Awesomely Techie Jobs
7 Awesomely Techie JobsSchaalra01
 
Postgres Foreign Data Wrappers
Postgres Foreign Data Wrappers  Postgres Foreign Data Wrappers
Postgres Foreign Data Wrappers EDB
 
Enabling the Cisco Decoder Ring
Enabling the Cisco Decoder RingEnabling the Cisco Decoder Ring
Enabling the Cisco Decoder RingNeo4j
 

Similar to DBAccess 研究 (20)

User Profiles: I Didn't Know I Could Do That? (Demo Slides)
User Profiles:  I Didn't Know I Could Do That?  (Demo Slides)User Profiles:  I Didn't Know I Could Do That?  (Demo Slides)
User Profiles: I Didn't Know I Could Do That? (Demo Slides)
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQL
 
CURRICULUM VITAE-Lomesh
CURRICULUM VITAE-LomeshCURRICULUM VITAE-Lomesh
CURRICULUM VITAE-Lomesh
 
SOA the Oracle way
SOA the Oracle waySOA the Oracle way
SOA the Oracle way
 
Getting Started With Apex REST Services
Getting Started With Apex REST ServicesGetting Started With Apex REST Services
Getting Started With Apex REST Services
 
Cloud Integration with Database.com and Heroku
Cloud Integration with Database.com and HerokuCloud Integration with Database.com and Heroku
Cloud Integration with Database.com and Heroku
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQL
 
Using PostgreSQL for Data Privacy
Using PostgreSQL for Data PrivacyUsing PostgreSQL for Data Privacy
Using PostgreSQL for Data Privacy
 
MySQL 8.0 Released Update
MySQL 8.0 Released UpdateMySQL 8.0 Released Update
MySQL 8.0 Released Update
 
Building Ranking Infrastructure: Data-Driven, Lean, Flexible - Sergii Khomenk...
Building Ranking Infrastructure: Data-Driven, Lean, Flexible - Sergii Khomenk...Building Ranking Infrastructure: Data-Driven, Lean, Flexible - Sergii Khomenk...
Building Ranking Infrastructure: Data-Driven, Lean, Flexible - Sergii Khomenk...
 
Using power shell to improve sharepoint management
Using power shell to improve sharepoint managementUsing power shell to improve sharepoint management
Using power shell to improve sharepoint management
 
Laxmikant_Resume
Laxmikant_ResumeLaxmikant_Resume
Laxmikant_Resume
 
Engage 2013 - Flexible Data Access with APIs
Engage 2013 - Flexible Data Access with APIsEngage 2013 - Flexible Data Access with APIs
Engage 2013 - Flexible Data Access with APIs
 
Best Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQLBest Practices in Security with PostgreSQL
Best Practices in Security with PostgreSQL
 
7 Awesomely Techie Jobs
7 Awesomely Techie Jobs7 Awesomely Techie Jobs
7 Awesomely Techie Jobs
 
20150423 m3
20150423 m320150423 m3
20150423 m3
 
CV_PraveenKumar
CV_PraveenKumarCV_PraveenKumar
CV_PraveenKumar
 
Postgres Foreign Data Wrappers
Postgres Foreign Data Wrappers  Postgres Foreign Data Wrappers
Postgres Foreign Data Wrappers
 
Resume
Resume Resume
Resume
 
Enabling the Cisco Decoder Ring
Enabling the Cisco Decoder RingEnabling the Cisco Decoder Ring
Enabling the Cisco Decoder Ring
 

More from ShengWen Chiou

Crashlytics 使用教學
Crashlytics 使用教學Crashlytics 使用教學
Crashlytics 使用教學ShengWen Chiou
 
Xamarin.iOS中引用第三方Objective-C的Class Library
Xamarin.iOS中引用第三方Objective-C的Class LibraryXamarin.iOS中引用第三方Objective-C的Class Library
Xamarin.iOS中引用第三方Objective-C的Class LibraryShengWen Chiou
 
Xamarin.iOS中引用自製Objective-C的Class Library
Xamarin.iOS中引用自製Objective-C的Class LibraryXamarin.iOS中引用自製Objective-C的Class Library
Xamarin.iOS中引用自製Objective-C的Class LibraryShengWen Chiou
 
What’s New In watch OS
What’s New In watch OSWhat’s New In watch OS
What’s New In watch OSShengWen Chiou
 
Symbolicate Crash 使用教學
Symbolicate Crash 使用教學Symbolicate Crash 使用教學
Symbolicate Crash 使用教學ShengWen Chiou
 
Apple Watch Specifications
Apple Watch SpecificationsApple Watch Specifications
Apple Watch SpecificationsShengWen Chiou
 
Apple Watch UI Elements
Apple Watch UI ElementsApple Watch UI Elements
Apple Watch UI ElementsShengWen Chiou
 
Apple Watch Human Interface Guidelines
Apple Watch Human Interface GuidelinesApple Watch Human Interface Guidelines
Apple Watch Human Interface GuidelinesShengWen Chiou
 
CocoaPods 使用教學
CocoaPods 使用教學CocoaPods 使用教學
CocoaPods 使用教學ShengWen Chiou
 
Parental Gate 使用教學
Parental Gate 使用教學Parental Gate 使用教學
Parental Gate 使用教學ShengWen Chiou
 

More from ShengWen Chiou (20)

iOS Extension
iOS ExtensioniOS Extension
iOS Extension
 
FMDB 研究
FMDB 研究FMDB 研究
FMDB 研究
 
Realm 研究
Realm 研究Realm 研究
Realm 研究
 
Crashlytics 使用教學
Crashlytics 使用教學Crashlytics 使用教學
Crashlytics 使用教學
 
Xamarin.iOS中引用第三方Objective-C的Class Library
Xamarin.iOS中引用第三方Objective-C的Class LibraryXamarin.iOS中引用第三方Objective-C的Class Library
Xamarin.iOS中引用第三方Objective-C的Class Library
 
Xamarin.iOS中引用自製Objective-C的Class Library
Xamarin.iOS中引用自製Objective-C的Class LibraryXamarin.iOS中引用自製Objective-C的Class Library
Xamarin.iOS中引用自製Objective-C的Class Library
 
iBeacon 相關應用
iBeacon 相關應用iBeacon 相關應用
iBeacon 相關應用
 
Xamarin 研究
Xamarin 研究Xamarin 研究
Xamarin 研究
 
What’s New In watch OS
What’s New In watch OSWhat’s New In watch OS
What’s New In watch OS
 
Apple Watch Feature
Apple Watch FeatureApple Watch Feature
Apple Watch Feature
 
Symbolicate Crash 使用教學
Symbolicate Crash 使用教學Symbolicate Crash 使用教學
Symbolicate Crash 使用教學
 
Apple Watch Specifications
Apple Watch SpecificationsApple Watch Specifications
Apple Watch Specifications
 
Apple Watch UI Elements
Apple Watch UI ElementsApple Watch UI Elements
Apple Watch UI Elements
 
Apple Watch Human Interface Guidelines
Apple Watch Human Interface GuidelinesApple Watch Human Interface Guidelines
Apple Watch Human Interface Guidelines
 
AppleDoc 使用教學
AppleDoc 使用教學AppleDoc 使用教學
AppleDoc 使用教學
 
Auto layout 介紹
Auto layout 介紹Auto layout 介紹
Auto layout 介紹
 
iOS Touch ID 介紹
iOS Touch ID 介紹iOS Touch ID 介紹
iOS Touch ID 介紹
 
iOS Keychain 介紹
iOS Keychain 介紹iOS Keychain 介紹
iOS Keychain 介紹
 
CocoaPods 使用教學
CocoaPods 使用教學CocoaPods 使用教學
CocoaPods 使用教學
 
Parental Gate 使用教學
Parental Gate 使用教學Parental Gate 使用教學
Parental Gate 使用教學
 

Recently uploaded

CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 

Recently uploaded (20)

CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 

DBAccess 研究

  • 2. DBACCESS IOS ORM • [DBAccess] is a fully featured and FREE to use ORM for iOS. • Replace CoreData whilst keeping your existing managed objects, but dump the predicates and long-winded syntax. • Instead use a simple and clean object syntax, with fast and concise inline queries. • DBAccess even has a conversion method to migrate your existing CoreData tables across. • Regularly updated and in constant use within many public applications it thrives on feedback from other developers and is supported by the authors via StackOverflow or directly via email. • It's mantra is simple, to be fast, simple to implement and the first choice for any
  • 3. WHY SHOULD I USE [DBACCESS] ? • An ORM should not be a chore to work with, or require you to change your way of working to compensate for its shortcomings. With [DBAccess] you simply add it to your project and start using it straight away.
  • 4. WHY SHOULD I USE [DBACCESS] ? • The developer has full control over how the ORM operates, deciding where it puts its files, how queries are performed and on which thread. Objects can be managed or unmanaged, whilst being members of domains which may share changes or be isolated from them.
  • 5. WHY SHOULD I USE [DBACCESS] ? • If memory is a concern, you can mix and match lightweight objects to preserve system resources when you are expecting large result sets, or retrieve only the properties you need with the remainder being lazily loaded when accessed.
  • 6. HEADLINE FEATURES • Automatic modeling and upgrading from your class structures. • Amazingly simple FLUENT interface for dealing with the ORM • KILLER event model, for individual objects or tables. Makes coding apps a breeze • Inline or Async queries • Transaction support • Managed and unmanaged objects supported to be used however you want • Relationships mirror your class structures automatically, and all relationships are automatically indexed • Property level encryption so databases remain human readable whilst securing individual columns.
  • 8. 參考文件轉移 • http://www.db-access.org/ • http://sharkorm.com/ • Fast, Fluid, Effective an open source iOS ORM, designed from the start to be low maintenance and natural to use, developers choose shark for its power and simplicity.
  • 9. SETTING UP YOUR PROJECT • AppDelegate.h #import <UIKit/UIKit.h> #import <DBAccess/DBAccess.h> @interface AppDelegate : UIResponder <UIApplicationDelegate, DBDelegate> @property (strong, nonatomic) UIWindow *window; @end
  • 10. SETTING UP YOUR PROJECT • AppDelegate.m #import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [DBAccess setDelegate:self]; [DBAccess openDatabaseNamed:@"happyDatabase"]; return YES; } @end
  • 12. CREATING DATA OBJECTS • Person.h #import <Foundation/Foundation.h> #import <DBAccess/DBAccess.h> @interface Person : DBObject @property NSString *name; @property NSInteger age; @property NSString *email; @property NSString *phone; @end
  • 13. CREATING DATA OBJECTS • Person.m #import "Person.h" @implementation Person @dynamic name, age, email, phone; @end
  • 14. CREATING OBJECTS, SETTING VALUES & PERSISTANCE-(void)createData { // Create a new object Person *thisPerson = [Person new]; // Set some properties thisPerson.age = 27; thisPerson.email = @"happyboy@gmail.com"; thisPerson.name = @"HappyBoy"; thisPerson.phone = @"0987654321"; // Persist the object into the datastore [thisPerson commit]; // Create a new object Person *thatPerson = [Person new]; // Set some properties thatPerson.age = 11; thatPerson.email = @"happygirl@gmail.com"; thatPerson.name = @"HappyGirl"; thatPerson.phone = @"0912345678"; // Persist the object into the datastore [thatPerson commit]; }
  • 15. QUERYING OBJECTS -(void)fetchData { DBResultSet *results = [[[[[Person query] where:@"age <= 40"] limit:99] orderBy:@"name"] fetch]; for (Person *person in results) { NSString *result = [NSString stringWithFormat:@"name: %@, age: %li, email: %@", person.name, (long)person.age, person.email]; NSLog(@"%@", result); } displayTV.text = [[results description] stringByReplacingOccurrencesOfString:@"n" withString:@"n"]; }
  • 16. DBRESULTSET *RESULTS 真不敢相信可以直接在console列印出來!!! ------------------------------------------------------------------------------------------- | Entity : Person Primary Key : Id Value: 25.000000 | ------------------------------------------------------------------------------------------- | Field Name | Type | Value | ------------------------------------------------------------------------------------------- | age | NUMBER | 11.000000 | | email | TEXT | happygirl@gmail.com | | phone | TEXT | 0912345678 | | name | TEXT | HappyGirl | | Id | NUMBER | 25.000000 | ------------------------------------------------------------------------------------------- | Relationships | ------------------------------------------------------------------------------------------- | Entity Name | Target Table | Status | ------------------------------------------------------------------------------------------- | NONE | | | ------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------- | Entity : Person Primary Key : Id Value: 24.000000 | ------------------------------------------------------------------------------------------- | Field Name | Type | Value | ------------------------------------------------------------------------------------------- | age | NUMBER | 27.000000 | | email | TEXT | happyboy@gmail.com | | phone | TEXT | 0987654321 | | name | TEXT | HappyBoy | | Id | NUMBER | 24.000000 | ------------------------------------------------------------------------------------------- | Relationships | ------------------------------------------------------------------------------------------- | Entity Name | Target Table | Status | ------------------------------------------------------------------------------------------- | NONE | | | -------------------------------------------------------------------------------------------
  • 17. REMOVING OBJECTS -(void)removeData { for (Person* person in [[Person query] fetch]) { [person remove]; } // or the shorthand is to use the removeAll method on the DBResultSet object [[[Person query] fetch] removeAll]; }
  • 18. OTHER TYPES OF QUERY -(void)queryData { /* count the rows within the Person table */ int count = [[Person query] count]; /* add all of the ages together */ double total = [[Person query] sumOf:@"age"]; /* group all the people together by the surname property */ NSDictionary *peopleBySurname = [[Person query] groupBy:@"name"]; /* get just the primary keys for a query, useful to save memory */ NSArray *ids = [[Person query] ids]; }
  • 20. 可設定巢狀 • Person.h #import <Foundation/Foundation.h> #import <DBAccess/DBAccess.h> @interface Person : DBObject @property NSString *name; @property NSInteger age; @property NSString *email; @property NSString *phone; @property Pet *pet; @end
  • 22. 問題:撈回無法參照 • Status: Unloaded ------------------------------------------------------------------------------------------- | Entity : Person Primary Key : Id Value: 5.000000 | ------------------------------------------------------------------------------------------- | Field Name | Type | Value | ------------------------------------------------------------------------------------------- | age | NUMBER | 27.000000 | | name | UNKNOWN | Nil value | | phone | UNKNOWN | Nil value | | pet | NUMBER | 5.000000 | | email | TEXT | happyboy@gmail.com | | Id | NUMBER | 5.000000 | ------------------------------------------------------------------------------------------- | Relationships | ------------------------------------------------------------------------------------------- | Entity Name | Target Table | Status | ------------------------------------------------------------------------------------------- | pet | Pet | Unloaded | -------------------------------------------------------------------------------------------
  • 24. 建立對應CLASS • Pet.h #import <DBAccess/DBAccess.h> @interface Pet : DBObject @property NSString *name; @property NSString *breed; @property NSString *photo; @property NSInteger birthday; @property NSInteger gender; @property NSInteger type; @property NSInteger neuter; @property NSInteger sortOrder; @property NSInteger createTime; @end
  • 25. 建立對應CLASS • Pet.m #import "Pet.h" @implementation Pet @dynamic name, birthday, breed, photo, gender, type, neuter, sortOrder, createTime; @end
  • 26. 取得顯示 for (Pet *pet in [[Pet query] fetch]) { NSString *result = [NSString stringWithFormat:@"name: %@, birthday: %li, photo: %@", pet.name, (long)pet.birthday, pet.photo]; NSLog(@"%@", result); } • name: happyPet, birthday: 0, photo: (null)
  • 27. 問題:無法繼承 • Superman.h #import "Person.h" @interface Superman : Person @property NSString *weapon; @property NSInteger power; @end
  • 29. 問題:無法繼承 • 編譯時沒事,執行時掛掉 • Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil’ Superman *thisSuperman = [Superman new]; // Set some properties thisSuperman.age = 27; thisSuperman.email = @"QQQhappyboy@gmail.com"; thisSuperman.pet = thisPet; thisSuperman.power = 99; [thisSuperman commit];
  • 30. QUERIES & RESULTS • DEALING WITH DATA • RETRIEVING OBJECTS • WHERE CLAUSES • JOIN • ASYNC QUERIES • THE RESULTS (AKA DBRESULTSET*) • DIFFERENT TYPES OF QUERY (COUNT, SUM)
  • 31. THE EVENT MODEL • The event handler is probably DBAccess’s most useful feature, it enables the developer to ‘hook’ into the events raised by the database engine. • There are 3 event types, INSERT, UPDATE & DELETE. These are bitwise operators so can be combined together to register blocks against multiple events at the same time. • There are two DBEventHandler objects you can use, one derived from the class object and another that can be used from within an instance of a class.
  • 32. RELATIONSHIPS • UNDERSTANDING HOW RELATIONSHIPS WORK • NESTED OBJECTS • ONE TO MANY RELATIONSHIPS
  • 33. TRANSACTIONS • Transactions in DBAccess are handled using a class method on DBTransaction, transactions can be started from anywhere at anytime, are entirely thread-safe. Any modifications to records that are due to event triggers being raised are also included within the transaction and rolled back on failure.
  • 34. REFERENCE • Cocoapods - DBAccess https://cocoapods.org/pods/DBAccess • Github - DBAccess https://github.com/editfmah/DBAccess • [DBAccess] http://www.db-access.org/