Because we can have several references of that database in the project, I couldn't clearly understand what counts as a connection?
struct DatabaseService {
let db = Database.database()
let ref = db.reference("/path")
let child = db.reference().child("/path")
let db2 = Database.database()
let ref2 = db2.reference()
func observeRef() {
ref.observe(.value) { snap in print("called") }
}
func observeRef2() {
ref2.observe(.value) { snap in print("called") }
}
func removeAllObservers() {
ref.removeAllObservers()
}
}
Should we create one database service class share its reference across app as singleton or is it okay to create a that service as a struct and create it whenever you need across the app?
Will having one instance or having structs affect our database connection count?
CodePudding user response:
The Firebase SDK takes care of that for you (simultaneus connections). With the "simultaneus" connections it's more about how many different users from different Apps can be connected to your database. You can read more about it here.
A simultaneous connection is equivalent to one mobile device, browser tab, or server app connected to the database. Firebase imposes hard limits on the number of simultaneous connections to your app's database.
db and db2 counts as one connection or two ?
It will count as one.
The child
syntax is more or less just a different syntax you can use to make your code better to read. Instead of reference('123/dq/123')
you can do reference(123).child("dq").child(123)
. it's just writing/syntax taste.