Save 37% off PRO during our Black Friday Sale! »

RealtimeDatabaseDesign.firebase.yebisu.pdf

F45851534f21f9469d296950653464be?s=47 1amageek
November 24, 2017
60

 RealtimeDatabaseDesign.firebase.yebisu.pdf

F45851534f21f9469d296950653464be?s=128

1amageek

November 24, 2017
Tweet

Transcript

  1. Firebase.yebisu SSID: COODPADGUEST Password: Edamame@2017 #firebase_yebisu

  2. Firebase Realtime Database Design nori Nov 2017 @1amageek Hello. #firebase.yebisu

    How are you
  3. System Device Technology LSI design engineer iOS engineer iOS engineer

    2017.5 2015.10 2009.4 Bio About 1amageek
  4. Salada Firebase Model Framework Pring Firestore Model Framework Bleu Bluetooth

    Library https://qiita.com/1amageek OSS Library
  5. Why design is necessary?

  6. Because, We want to 1. Simple 2. Safe 3. Efficient

    4. Functional
  7. What is design in IT?

  8. Organize data Connect data and data together

  9. What is design for engineers?

  10. Easy to connect Making data and data easier to connect

  11. Why use Firebase? https://qiita.com/1amageek

  12. Design for Firebase Model Relationship Rule

  13. Model 1. Typesafe 2. Common understanding

  14. model id_0 property_0: “model” id_1 property_1: 0 property_0: “model” property_1:

    0 class Model { let id: String let property_0: String let property_1: Int } let model0: Model = Model() model.property_0 = "model" model.property_1 = 0 let model1: Model = Model() model.property_0 = "model" model.property_1 = 0
  15. Key points of model design ID let model: Model =

    Model() let model: Model = Model(id: “ID”)
  16. /// Initialize Object public override init() { self.createdAt = Date()

    self.updatedAt = Date() self._ref = type(of: self).databaseRef.childByAutoId() self.id = self._ref.key super.init() } /// Initialize Object from snapshot. convenience required public init?(snapshot: DataSnapshot) { self.init() _setSnapshot(snapshot) } /// Initialize the object with the specified ID. convenience required public init?(id: String) { self.init() self.id = id self._ref = type(of: self).databaseRef.child(id) }
  17. Relationship 1. Essential

  18. 1 : 1 1 : N N : N

  19. 1 : 1 1 : N N : N Just

    think about N : N
  20. 1 : 1

  21. class Company { let id: String let name: String let

    CEO: String } class People { let id: String let name: String let company: String } let tesla: Company = Company() tesla.name = "Tesla" let mask: People = People() mask.name = "Elon Musk" tesla.CEO = mask.id mask.company = tesla.id
  22. 1 : N

  23. class Company { let id: String let name: String let

    CEO: String } class People { let id: String let name: String let companies: [String] } let tesla: Company = Company() tesla.name = "Tesla" let mask: People = People() mask.name = "Elon Musk" tesla.CEO = mask.id mask.companies.append(tesla.id)
  24. class Company { let id: String let name: String let

    CEO: String } class People { let id: String let name: String let companies: [String] } let tesla: Company = Company() tesla.name = "Tesla" let mask: People = People() mask.name = "Elon Musk" tesla.CEO = mask.id mask.companies.append(tesla.id) Growth Property
  25. people id_0 name: “Elon Musk” companies id_1 id_2 ɾ ɾ

    id_ 0 becomes heavier
  26. people-company people_id company_id_0: true company_id_1: true Separate into separate nodes

    company company_id_0 people people_id
  27. N : N

  28. people-company people_id company_id_0: true company_id_1: true company company_id_0 people people_id

  29. Key points of relationship design N : N let userA:

    User = User() let userB: User = User() userA.follow(userB) userB.frined(userA)
  30. Security 1. Essential

  31. Use Firebase bolt

  32. /** User */ path /user { read() { isSignedIn() }

    index() { [ “name" ] } path /{id} is User { read() { isSignedIn() } write() { isUser(id) } path /property { read() { isSignedIn() } } } } type User { name: String } isSignedIn() { auth != null } isUser(uid) { isSignedIn() && auth.uid == uid }
  33. /** User */ path /user { read() { isSignedIn() }

    index() { [ “name" ] } path /{id} is User { read() { isSignedIn() } write() { isUser(id) } path /property { read() { isSignedIn() } } } } type User { name: String } isSignedIn() { auth != null } isUser(uid) { isSignedIn() && auth.uid == uid } Type Permissions
  34. Key points of security design Multiple permission management isSignedIn() {

    auth != null } isUser(uid) { isSignedIn() && auth.uid == uid } canRead() { data.val() == null || data.child('userID').val() === auth.uid } canWrite() { data.child('userID').val() == auth.uid || newData.child('userID').val() == auth.uid } createOnly(value) { prior(value) == null && value != null }
  35. Model is important for engineers

  36. Salada Firebase Model Framework Let's use Salada

  37. Sample code https://github.com/1amageek/SaladaSample

  38. Thank you %