Upgrade to Pro — share decks privately, control downloads, hide ads and more …

次世代MobileデータベースRealm

 次世代MobileデータベースRealm

Developers Summit 2016

Kishikawa Katsumi

February 19, 2016
Tweet

More Decks by Kishikawa Katsumi

Other Decks in Programming

Transcript

  1. let key = NSMutableData(length: 64)! SecRandomCopyBytes(kSecRandomDefault, key.length, UnsafeMutablePointer<UInt8>(key.mutableBytes)) let config

    = Realm.Configuration(encryptionKey: key) let realm = try! Realm(configuration: config) 农〾⻉堣腉
  2. class Article: Object { dynamic var id: Int = 0

    dynamic var title: String = "" dynamic var contents: String = "" dynamic var creationDate: NSDate = NSDate() dynamic var modificationDate: NSDate = NSDate() dynamic var deletionDate: NSDate? = nil dynamic var user: User? = nil let comments = List<Comment>() } ٌرٕذ٦ـٕ㹀纏 J04
  3. public class Article extends RealmObject { @PrimaryKey private int id;

    private String title; private String contents; private Date creationDate; private Date modificationDate; private Date deletionDate; private User user; private RealmList<Comment> user; } ٌرٕذ٦ـٕ㹀纏 "OESPJE
  4. let realm = try! Realm() // RealmίωΫγϣϯ let article =

    Article() article.title = titleTextfield.text article.contents = contentTextfield.text realm.write { // τϥϯβΫγϣϯ realm.add(article) } ر٦ةך⥂㶷 J04
  5. Realm realm = Realm.getInstance(this); // RealmίωΫγϣϯ realm.beginTransaction(); // τϥϯβΫγϣϯ։࢝ Article

    article = realm.createObject(Article.class); article.setText(titleTextfield.getText()); article.setContents(contentTextfield.getText()); realm.commitTransaction(); // τϥϯβΫγϣϯऴྃ ر٦ةך⥂㶷 "OESPJE
  6. let realm = try! Realm() letɹarticles = realm .objects(Article) .filter("user

    = %@", currentUser) .sorted("modificationDate", ascending: false) ؙؒٔ J04
  7. Realm realm = Realm.getInstance(this); RealmResults<Article> result = realm .where(Article.class) .equalTo("user.id",

    currentUser.getId()) .findAll() .sort("modificationDate", Sort.DESCENDING); ؙؒٔ "OESPJE
  8. Storage Engine ObjectStore API Objective-C Binging Java Binging Swift Binging

    C++ وٕثفٓحزؿؓ٦ي׾佄ִ׷ ،٦ؗذؙثٍ
  9. పఈͨ͠஗Ԇϩʔυ let allArticles = realm.objects(Article) let articles = allArticles.filter(“user =

    %@", currentUser) 3FTVMUT"SUJDMF 5BCMF"SUJDMF 3FTVMUT"SUJDMF 5BCMF"SUJDMF 2VFSZVTFS
  10. పఈͨ͠஗Ԇϩʔυ let articles = allArticles.filter(“user = %@", currentUser) let count

    = articles.count 3FTVMUT"SUJDMF 5BCMF"SUJDMF 2VFSZVTFS 3FTVMUT"SUJDMF 5BCMF"SUJDMF 2VFSZVTFS $PVOU 7JFX
  11. పఈͨ͠஗Ԇϩʔυ let count = articles.count let article = articles[0] 3FTVMUT"SUJDMF

    5BCMF"SUJDMF 2VFSZVTFS $PVOU 7JFX "SUJDMF 3PX*OEFY 3FTVMUT"SUJDMF 5BCMF"SUJDMF 2VFSZVTFS $PVOU 7JFX
  12. పఈͨ͠஗Ԇϩʔυ let article = articles[0] let title = article.title "SUJDMF

    3PX*OEFY 3FTVMUT"SUJDMF 5BCMF"SUJDMF 2VFSZVTFS $PVOU 7JFX "SUJDMF 3PX*OEFY 5JUMF(FUUFS 3FBMN 4USJOH 5JUMF
  13. ˖ Ⱅ䒭8FC؟؎ز!  IUUQTSFBMNJPKQ ˖ (JU)VC  IUUQTHJUIVCDPNSFBMNSFBMNDPDPB  IUUQTHJUIVCDPNSFBMNSFBMNKBWB

    ˖ ِ٦ؠ٦ؚٕ٦ف!  IUUQTXXXGBDFCPPLDPNHSPVQTSFBMNKQ ˖ ؟ه٦زثٍحز!  IUUQTMBDLSFBMNJP ˖ 5XJUUFS!  IUUQTUXJUUFSDPNSFBMN+BQBO ˖ ى٦ز،حف!  IUUQSFBMNDPOOQBTTDPN ⿫罋项俱