{"id":1005,"url":"https://github.com/quanvo87/FirebaseHelper","last_synced_at":"2025-07-30T20:32:52.093Z","repository":{"id":56911277,"uuid":"119306887","full_name":"quanvo87/FirebaseHelper","owner":"quanvo87","description":"Safe and easy wrappers for common Firebase Realtime Database functions.","archived":false,"fork":false,"pushed_at":"2018-01-30T05:29:54.000Z","size":23944,"stargazers_count":15,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-27T00:41:18.920Z","etag":null,"topics":["database","firebase","firebase-database"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quanvo87.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-28T23:16:30.000Z","updated_at":"2023-07-27T16:45:12.000Z","dependencies_parsed_at":"2022-08-21T03:20:12.511Z","dependency_job_id":null,"html_url":"https://github.com/quanvo87/FirebaseHelper","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quanvo87%2FFirebaseHelper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quanvo87%2FFirebaseHelper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quanvo87%2FFirebaseHelper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quanvo87%2FFirebaseHelper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quanvo87","download_url":"https://codeload.github.com/quanvo87/FirebaseHelper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228187535,"owners_count":17882322,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","firebase","firebase-database"],"created_at":"2024-01-05T20:15:36.776Z","updated_at":"2024-12-04T20:31:01.162Z","avatar_url":"https://github.com/quanvo87.png","language":"Swift","funding_links":[],"categories":["Database"],"sub_categories":["Getting Started","Other free courses","Linter"],"readme":"# FirebaseHelper\n\n\u003c!--[![CI Status](http://img.shields.io/travis/quanvo87/FirebaseHelper.svg?style=flat)](https://travis-ci.org/quanvo87/FirebaseHelper)--\u003e\n[![Version](https://img.shields.io/cocoapods/v/FirebaseHelper.svg?style=flat)](http://cocoapods.org/pods/FirebaseHelper)\n[![License](https://img.shields.io/cocoapods/l/FirebaseHelper.svg?style=flat)](http://cocoapods.org/pods/FirebaseHelper)\n[![Platform](https://img.shields.io/cocoapods/p/FirebaseHelper.svg?style=flat)](http://cocoapods.org/pods/FirebaseHelper)\n\nFirebaseHelper is a small wrapper over Firebase's realtime database, providing streamlined methods for get, set, delete, and increment values.\n\n## Features\n- [x] Setup Firebase Realtime Database Ref\n- [x] Read values (get)\n- [x] Write/Update values (set)\n- [x] Remove values (delete)\n- [x] Increment values (increment)\n\n## Requirements\n\nSwift 4\n\n## Installation\n\nFirebaseHelper is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'FirebaseHelper'\n```\n\n## Usage\n\nInitialize an instance of `FirebaseHelper`:\n\n```swift\nimport Firebase\nimport FirebaseHelper\n\nlet firebaseHelper = FirebaseHelper(FirebaseDatabase.Database.database().reference())\n```\n\n`FirebaseHelper(_ ref: DatabaseReference)` takes in a `DatabaseReference`. Generally you'd want this to be the root of your database.\n\nFor convenience, you can add something like this to your project:\n\n```swift\nextension FirebaseHelper {\n    static let main: FirebaseHelper = {\n        FirebaseHelper(FirebaseDatabase.Database.database().reference())\n    }()\n}\n```\n\nAnd now you can simply call `FirebaseHelper.main` to access this instance of `FirebaseHelper` from anywhere in your project.\n\n### Common Database Operations\n\n#### Get\n\nExample:\n\n```swift\nFirebaseHelper.main.get(\"users\", \"john123\", \"favoriteFood\") { result in\n    switch result {\n      case .failure(let error):\n        // handle error\n      case .success(let data):\n        // get string from data\n    }\n}\n```\n\nAPI:\n\n```swift\npublic func get(_ first: String, _ rest: String..., completion: @escaping (Result\u003cDataSnapshot, Error\u003e) -\u003e Void)\n```\n\n`get()` takes in a variadic parameter of child nodes that will be built on the `DatabaseReference` you initialized your instance of `FirebaseHelper` on.\n\nThe callback returns a `Result`:\n\n```swift\npublic enum Result\u003cT, Error\u003e {\n    case success(T)\n    case failure(Error)\n}\n```\n\nIn this case, `T` is `DataSnapshot`. An error case will either be because an invalid child was passed in or some other error in your database.\n\n#### Set, Delete, Increment\n\n`set()`, `delete()`, and `increment()` work similarly, but instead of returning a `Result`, they simply return an `Error` if one occurred, or `nil` otherwise.\n\nExamples:\n\n```swift\n// The first parameter is an `Any` that gets set at the specified path.\nFirebaseHelper.main.set(\"pizza\", at: \"users\", \"john123\", \"favoriteFood\") { error in\n    if let error = error {\n      // handle error\n  }\n}\n\nFirebaseHelper.main.delete(\"users\", \"john123\", \"favoriteFood\") { error in\n    if let error = error {\n      // handle error\n  }\n}\n\nFirebaseHelper.main.increment(by: 5, \"users\", \"john123\", \"favoriteFoodEatenThisMonth\") {\n    if let error = error {\n      // handle error\n  }\n}\n```\n\nAPIs:\n\n```swift\npublic func set(_ value: Any, at first: String, _ rest: String..., completion: @escaping (Error?) -\u003e Void)\n\npublic func delete(_ first: String, _ rest: String..., completion: @escaping (Error?) -\u003e Void)\n\npublic func increment(by amount: Int, at first: String, _ rest: String..., completion: @escaping (Error?) -\u003e Void)\n```\n\n\u003e Note: You should only `set()` accepted value types. See [Firebase docs](https://firebase.google.com/docs/database/ios/read-and-write#basic_write).\n\n#### Safely Make A DatabaseReference\n\nYou will often need to call more complex `FirebaseDatabase` functions, such as building a query and calling `observe(_ eventType: with block:)` on it. `FirebaseHelper` can still help with that:\n\n```swift\nlet ref = try? FirebaseHelper.main.makeReference(\"users\", \"john123\", \"eatingHistory\")\nlet handle = ref?.queryOrdered(byChild: \"timestamp\").queryLimited(toLast: 50).observe(.value) { data in\n    // handle data\n}\n```\n\nAPI:\n\n```swift\npublic func makeReference(_ first: String, _ rest: String...) throws -\u003e DatabaseReference\n```\n\n`makeReference` will throw an error if passed an invalid child.\n\n## Collaborators\n\n- [Quan Vo](https://github.com/quanvo87)\n- [Wilson Ding](https://github.com/dingwilson)\n\n## License\n\nFirebaseHelper is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquanvo87%2FFirebaseHelper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquanvo87%2FFirebaseHelper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquanvo87%2FFirebaseHelper/lists"}