Advertisement
Guest User

Untitled

a guest
Apr 21st, 2017
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.44 KB | None | 0 0
  1. [2017-04-21T05:12:47-0500] <ultra-> Can someone help me update a database record in firebase? I’m using the docs, but I’m having a hard time wrapping my head around it.
  2. [2017-04-21T05:13:51-0500] <ultra-> I have “users” to hold all users, then “user” for their unique ID, and I want to add a node called “favorites” where multiple key/value pairs can be stored
  3. [2017-04-21T05:14:23-0500] netrino (~netrino@199.101.96.70) joined the channel
  4. [2017-04-21T05:22:00-0500] bonghitz (~bonghitz@c-67-174-204-63.hsd1.ca.comcast.net) joined the channel
  5. [2017-04-21T05:22:38-0500] <arietis> ultra-: How about this one? http://stackoverflow.com/questions/39323906/swift-firebase-one-to-many-example
  6. [2017-04-21T05:23:55-0500] <ultra-> This will help in the future when I need to relate the data (bookmarked), but I need to add the records
  7. [2017-04-21T05:24:15-0500] <davidvs> you probably want to create a new key in root called favorites > userID > ...
  8. [2017-04-21T05:24:19-0500] <ultra-> I know how to add a new user, I just don’t know how to add a node and new data to the node
  9. [2017-04-21T05:24:26-0500] <davidvs> firebase is all about flattening the structure
  10. [2017-04-21T05:24:43-0500] <ultra-> I have /users/user, I want /users/user/favorites and then multiple key/value pairs in favorites
  11. [2017-04-21T05:24:47-0500] <davidvs> ok
  12. [2017-04-21T05:25:15-0500] splendor (~splendor@2605:a601:1100:7100:1c70:55c5:ab00:d06) left IRC (Quit: My MacBook has gone to sleep. ZZZzzz…)
  13. [2017-04-21T05:25:19-0500] <davidvs> so you'd do users.child(userId).child("favorites").update([key: value])
  14. [2017-04-21T05:25:37-0500] <davidvs> or set([key: value]) if you want to overwrite the entire location
  15. [2017-04-21T05:26:11-0500] <davidvs> but if you're accessing arbitrary favortes by user id, you'll want to create a favorites key on root
  16. [2017-04-21T05:26:16-0500] splendor (~splendor@2605:a601:1100:7100:1c70:55c5:ab00:d06) joined the channel
  17. [2017-04-21T05:26:26-0500] <davidvs> otherwise you have to download the entire user node to get to the favorites
  18. [2017-04-21T05:26:36-0500] <ultra-> will that automatically create the “favorites” node if it doesn’t exist?
  19. [2017-04-21T05:26:41-0500] <davidvs> yes
  20. [2017-04-21T05:26:43-0500] <davidvs> it just works
  21. [2017-04-21T05:26:49-0500] <davidvs> you can't have an empty node
  22. [2017-04-21T05:27:02-0500] <ultra-> well, favorites is the primary information I want anyway, so there won’t be a lot of data
  23. [2017-04-21T05:27:13-0500] <davidvs> foo.child("bar").child("baz").child("value") creates all the subnodes
  24. [2017-04-21T05:27:25-0500] <davidvs> still
  25. [2017-04-21T05:27:33-0500] <davidvs> flatten it as much as possible right now to avoid headaches later
  26. [2017-04-21T05:27:39-0500] <davidvs> it's nosql
  27. [2017-04-21T05:28:10-0500] gargs (~gargs@h8239.upc-h.chello.nl) joined the channel
  28. [2017-04-21T05:28:56-0500] <ultra-> if I create a favorites key on root, what does the data structure look like?
  29. [2017-04-21T05:29:14-0500] <ultra-> Essentially, I use the user to retrieve their favorites, and possibly a small amount of other information
  30. [2017-04-21T05:30:13-0500] <davidvs> favorites > userId > whatever
  31. [2017-04-21T05:30:20-0500] <davidvs> base everything off the user id
  32. [2017-04-21T05:30:33-0500] <davidvs> that allows you to set firebase rules easier, too
  33. [2017-04-21T05:31:10-0500] <ultra-> ok, so I access the favorites from favorites using userid as the key
  34. [2017-04-21T05:31:16-0500] <davidvs> right
  35. [2017-04-21T05:31:48-0500] <ultra-> and under users/user, i’d just keep the other information i want, such as their email address
  36. [2017-04-21T05:31:54-0500] <davidvs> yeah
  37. [2017-04-21T05:32:20-0500] <ultra-> This makes sense then… thanks a lot
  38. [2017-04-21T05:32:51-0500] <davidvs> firebase is amazing but the 'structuring data' docs need more examples
  39. [2017-04-21T05:33:47-0500] <ultra-> Yeah, and it needs continuity… the examples for adding new data and updating data don’t seem to relate too well
  40. [2017-04-21T05:34:15-0500] <davidvs> are you doing web, ios or android
  41. [2017-04-21T05:34:23-0500] <ultra-> but i can see how firebase is gonna be great once i get it down
  42. [2017-04-21T05:34:43-0500] <ultra-> ios and eventually android, small chance of web in the future but for now I’m just building my iOS app
  43. [2017-04-21T05:34:51-0500] <davidvs> ever since google acquired them they've been rock solid
  44. [2017-04-21T05:35:04-0500] <ultra-> I’m not a programming professional and it’s just a hobby, so i don’t know where this will go
  45. [2017-04-21T05:35:05-0500] <davidvs> ah good ios is a cinch
  46. [2017-04-21T05:35:15-0500] <davidvs> plus it's cheap as shit now under the new pricing plan
  47. [2017-04-21T05:35:23-0500] <davidvs> i have thousands of users and pay like $30 a month
  48. [2017-04-21T05:35:44-0500] hphuoc25 (~hphuoc25@bb121-7-103-152.singnet.com.sg) joined the channel
  49. [2017-04-21T05:36:00-0500] <davidvs> make sure to use FirebaseQuery to keep your data transfers low
  50. [2017-04-21T05:36:09-0500] <ultra-> does your app have a one time cost or do you get constant revenue from the users?
  51. [2017-04-21T05:36:29-0500] <davidvs> subscription model
  52. [2017-04-21T05:36:41-0500] <davidvs> it's the only way to go nowadays
  53. [2017-04-21T05:36:48-0500] <davidvs> even if it's like $5 a year
  54. [2017-04-21T05:37:01-0500] <ultra-> yeah… I just don’t know how to work that out
  55. [2017-04-21T05:37:27-0500] <ultra-> i hate the business and marketing side of it all, i just want to build things
  56. [2017-04-21T05:37:41-0500] pretty_function (~pretty_fu@182.76.50.66) joined the channel
  57. [2017-04-21T05:37:48-0500] <davidvs> build a better mousetrap and the whole world will flock to your door
  58. [2017-04-21T05:38:35-0500] <ultra-> also, i’m using a free api and i don’t know if i’m allowed to monetize the data i get from it
  59. [2017-04-21T05:40:10-0500] <ultra-> I’m essentially pulling in data from it, and then making it more useful by adding other information and ways to organize it
  60. [2017-04-21T05:40:42-0500] <davidvs> the cool thing about firebase is that with the rules, you can make all that information publically accessible within your firebase
  61. [2017-04-21T05:40:54-0500] <davidvs> so individual clients don't have to fetch anything from the API at all
  62. [2017-04-21T05:41:04-0500] hphuoc25 (~hphuoc25@bb121-7-103-152.singnet.com.sg) left IRC (Ping timeout: 260 seconds)
  63. [2017-04-21T05:41:23-0500] <davidvs> as long as someone can call the API or scrape the website and update the firebase, the clients are none the wiser
  64. [2017-04-21T05:41:51-0500] <davidvs> it looks like your own data, from their POV
  65. [2017-04-21T05:42:41-0500] <ultra-> Yeah, in certain ways I’ll be doing that to replace certain information with my own
  66. [2017-04-21T05:42:44-0500] <davidvs> so if they revoke your api token, fuck them, make a new one
  67. [2017-04-21T05:42:50-0500] <ultra-> or append information to theirs
  68. [2017-04-21T05:43:26-0500] <ultra-> Also, their website doesn’t allow users to change information when needed, and I figure I’d allow that as a feature
  69. [2017-04-21T05:43:34-0500] Cabanossi (~Cabanossi@pD9F852F4.dip0.t-ipconnect.de) left IRC (Ping timeout: 245 seconds)
  70. [2017-04-21T05:43:51-0500] <ultra-> So at some point I might just dump all theirs into mine, and eventually it’ll change enough so it’ll be my own
  71. [2017-04-21T05:43:56-0500] <davidvs> cool
  72. [2017-04-21T05:43:57-0500] <davidvs> yep
  73. [2017-04-21T05:44:10-0500] kr1shnak (~kr1shnak@46-227-66-221.static.obenetwork.net) left IRC (Ping timeout: 255 seconds)
  74. [2017-04-21T05:44:25-0500] <davidvs> at some point you'll have to learn node to automate all that
  75. [2017-04-21T05:44:51-0500] <davidvs> spinning up a heroku dyno is relatively cheap though
  76. [2017-04-21T05:45:09-0500] <ultra-> Well, I do understand how to retrieve and structure their JSON data, and I can do it with large groups of data at once
  77. [2017-04-21T05:45:29-0500] <ultra-> so I might have to do it 50 times, once for each state
  78. [2017-04-21T05:45:42-0500] kr1shnak (~kr1shnak@46-227-66-219.static.obenetwork.net) joined the channel
  79. [2017-04-21T05:46:28-0500] Cabanossi (~Cabanossi@pD9F852F4.dip0.t-ipconnect.de) joined the channel
  80. [2017-04-21T05:46:38-0500] <ultra-> is this what you meant? https://firebase.google.com/docs/reference/js/firebase.database.Query
  81. [2017-04-21T05:46:55-0500] <davidvs> yeah
  82. [2017-04-21T05:47:14-0500] <ultra-> ok, i’ll add that into my bag of tricks too
  83. [2017-04-21T05:47:16-0500] <davidvs> you can set the intial query , then it gets updated atomically whenever anything changes
  84. [2017-04-21T05:47:25-0500] <davidvs> as opposed to fetching the entire tree every time you want to refresh the data
  85. [2017-04-21T05:47:32-0500] <ultra-> that is awesome
  86. [2017-04-21T05:47:35-0500] <davidvs> so cache the local copy and you've saved yourself some $$$
  87. [2017-04-21T05:48:10-0500] PickAndMix (~Max@66.96.193.105) left IRC (Ping timeout: 240 seconds)
  88. [2017-04-21T05:48:26-0500] <ultra-> ok
  89. [2017-04-21T05:48:35-0500] dardevelin (~dardeveli@unaffiliated/dardevelin) left IRC (Ping timeout: 258 seconds)
  90. [2017-04-21T05:48:47-0500] <ultra-> well i’m headed off on a road trip for the weekend, have a good day and thanks for the information
  91. [2017-04-21T05:48:56-0500] <davidvs> good luck
  92. [2017-04-21T05:49:10-0500] ultra- (~Drew@cpe-65-27-66-242.new.res.rr.com) left IRC (Quit: ultra-)
  93. [2017-04-21T05:50:09-0500] ultra- (~Drew@cpe-65-27-66-242.new.res.rr.com) joined the channel
  94. [2017-04-21T05:50:45-0500] <ultra-> davidvs: I just screwed up and closed colloquoy… would you mind pasting what you initially said (the swift code) about updating the data?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement