Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [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.
- [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
- [2017-04-21T05:14:23-0500] netrino (~netrino@199.101.96.70) joined the channel
- [2017-04-21T05:22:00-0500] bonghitz (~bonghitz@c-67-174-204-63.hsd1.ca.comcast.net) joined the channel
- [2017-04-21T05:22:38-0500] <arietis> ultra-: How about this one? http://stackoverflow.com/questions/39323906/swift-firebase-one-to-many-example
- [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
- [2017-04-21T05:24:15-0500] <davidvs> you probably want to create a new key in root called favorites > userID > ...
- [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
- [2017-04-21T05:24:26-0500] <davidvs> firebase is all about flattening the structure
- [2017-04-21T05:24:43-0500] <ultra-> I have /users/user, I want /users/user/favorites and then multiple key/value pairs in favorites
- [2017-04-21T05:24:47-0500] <davidvs> ok
- [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…)
- [2017-04-21T05:25:19-0500] <davidvs> so you'd do users.child(userId).child("favorites").update([key: value])
- [2017-04-21T05:25:37-0500] <davidvs> or set([key: value]) if you want to overwrite the entire location
- [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
- [2017-04-21T05:26:16-0500] splendor (~splendor@2605:a601:1100:7100:1c70:55c5:ab00:d06) joined the channel
- [2017-04-21T05:26:26-0500] <davidvs> otherwise you have to download the entire user node to get to the favorites
- [2017-04-21T05:26:36-0500] <ultra-> will that automatically create the “favorites” node if it doesn’t exist?
- [2017-04-21T05:26:41-0500] <davidvs> yes
- [2017-04-21T05:26:43-0500] <davidvs> it just works
- [2017-04-21T05:26:49-0500] <davidvs> you can't have an empty node
- [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
- [2017-04-21T05:27:13-0500] <davidvs> foo.child("bar").child("baz").child("value") creates all the subnodes
- [2017-04-21T05:27:25-0500] <davidvs> still
- [2017-04-21T05:27:33-0500] <davidvs> flatten it as much as possible right now to avoid headaches later
- [2017-04-21T05:27:39-0500] <davidvs> it's nosql
- [2017-04-21T05:28:10-0500] gargs (~gargs@h8239.upc-h.chello.nl) joined the channel
- [2017-04-21T05:28:56-0500] <ultra-> if I create a favorites key on root, what does the data structure look like?
- [2017-04-21T05:29:14-0500] <ultra-> Essentially, I use the user to retrieve their favorites, and possibly a small amount of other information
- [2017-04-21T05:30:13-0500] <davidvs> favorites > userId > whatever
- [2017-04-21T05:30:20-0500] <davidvs> base everything off the user id
- [2017-04-21T05:30:33-0500] <davidvs> that allows you to set firebase rules easier, too
- [2017-04-21T05:31:10-0500] <ultra-> ok, so I access the favorites from favorites using userid as the key
- [2017-04-21T05:31:16-0500] <davidvs> right
- [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
- [2017-04-21T05:31:54-0500] <davidvs> yeah
- [2017-04-21T05:32:20-0500] <ultra-> This makes sense then… thanks a lot
- [2017-04-21T05:32:51-0500] <davidvs> firebase is amazing but the 'structuring data' docs need more examples
- [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
- [2017-04-21T05:34:15-0500] <davidvs> are you doing web, ios or android
- [2017-04-21T05:34:23-0500] <ultra-> but i can see how firebase is gonna be great once i get it down
- [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
- [2017-04-21T05:34:51-0500] <davidvs> ever since google acquired them they've been rock solid
- [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
- [2017-04-21T05:35:05-0500] <davidvs> ah good ios is a cinch
- [2017-04-21T05:35:15-0500] <davidvs> plus it's cheap as shit now under the new pricing plan
- [2017-04-21T05:35:23-0500] <davidvs> i have thousands of users and pay like $30 a month
- [2017-04-21T05:35:44-0500] hphuoc25 (~hphuoc25@bb121-7-103-152.singnet.com.sg) joined the channel
- [2017-04-21T05:36:00-0500] <davidvs> make sure to use FirebaseQuery to keep your data transfers low
- [2017-04-21T05:36:09-0500] <ultra-> does your app have a one time cost or do you get constant revenue from the users?
- [2017-04-21T05:36:29-0500] <davidvs> subscription model
- [2017-04-21T05:36:41-0500] <davidvs> it's the only way to go nowadays
- [2017-04-21T05:36:48-0500] <davidvs> even if it's like $5 a year
- [2017-04-21T05:37:01-0500] <ultra-> yeah… I just don’t know how to work that out
- [2017-04-21T05:37:27-0500] <ultra-> i hate the business and marketing side of it all, i just want to build things
- [2017-04-21T05:37:41-0500] pretty_function (~pretty_fu@182.76.50.66) joined the channel
- [2017-04-21T05:37:48-0500] <davidvs> build a better mousetrap and the whole world will flock to your door
- [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
- [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
- [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
- [2017-04-21T05:40:54-0500] <davidvs> so individual clients don't have to fetch anything from the API at all
- [2017-04-21T05:41:04-0500] hphuoc25 (~hphuoc25@bb121-7-103-152.singnet.com.sg) left IRC (Ping timeout: 260 seconds)
- [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
- [2017-04-21T05:41:51-0500] <davidvs> it looks like your own data, from their POV
- [2017-04-21T05:42:41-0500] <ultra-> Yeah, in certain ways I’ll be doing that to replace certain information with my own
- [2017-04-21T05:42:44-0500] <davidvs> so if they revoke your api token, fuck them, make a new one
- [2017-04-21T05:42:50-0500] <ultra-> or append information to theirs
- [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
- [2017-04-21T05:43:34-0500] Cabanossi (~Cabanossi@pD9F852F4.dip0.t-ipconnect.de) left IRC (Ping timeout: 245 seconds)
- [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
- [2017-04-21T05:43:56-0500] <davidvs> cool
- [2017-04-21T05:43:57-0500] <davidvs> yep
- [2017-04-21T05:44:10-0500] kr1shnak (~kr1shnak@46-227-66-221.static.obenetwork.net) left IRC (Ping timeout: 255 seconds)
- [2017-04-21T05:44:25-0500] <davidvs> at some point you'll have to learn node to automate all that
- [2017-04-21T05:44:51-0500] <davidvs> spinning up a heroku dyno is relatively cheap though
- [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
- [2017-04-21T05:45:29-0500] <ultra-> so I might have to do it 50 times, once for each state
- [2017-04-21T05:45:42-0500] kr1shnak (~kr1shnak@46-227-66-219.static.obenetwork.net) joined the channel
- [2017-04-21T05:46:28-0500] Cabanossi (~Cabanossi@pD9F852F4.dip0.t-ipconnect.de) joined the channel
- [2017-04-21T05:46:38-0500] <ultra-> is this what you meant? https://firebase.google.com/docs/reference/js/firebase.database.Query
- [2017-04-21T05:46:55-0500] <davidvs> yeah
- [2017-04-21T05:47:14-0500] <ultra-> ok, i’ll add that into my bag of tricks too
- [2017-04-21T05:47:16-0500] <davidvs> you can set the intial query , then it gets updated atomically whenever anything changes
- [2017-04-21T05:47:25-0500] <davidvs> as opposed to fetching the entire tree every time you want to refresh the data
- [2017-04-21T05:47:32-0500] <ultra-> that is awesome
- [2017-04-21T05:47:35-0500] <davidvs> so cache the local copy and you've saved yourself some $$$
- [2017-04-21T05:48:10-0500] PickAndMix (~Max@66.96.193.105) left IRC (Ping timeout: 240 seconds)
- [2017-04-21T05:48:26-0500] <ultra-> ok
- [2017-04-21T05:48:35-0500] dardevelin (~dardeveli@unaffiliated/dardevelin) left IRC (Ping timeout: 258 seconds)
- [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
- [2017-04-21T05:48:56-0500] <davidvs> good luck
- [2017-04-21T05:49:10-0500] ultra- (~Drew@cpe-65-27-66-242.new.res.rr.com) left IRC (Quit: ultra-)
- [2017-04-21T05:50:09-0500] ultra- (~Drew@cpe-65-27-66-242.new.res.rr.com) joined the channel
- [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