{"id":15376259,"url":"https://github.com/nolanlawson/pouchdb-ionic","last_synced_at":"2025-04-14T08:43:06.213Z","repository":{"id":26824022,"uuid":"30282796","full_name":"nolanlawson/pouchdb-ionic","owner":"nolanlawson","description":"PouchDB for Ionic Framework","archived":false,"fork":false,"pushed_at":"2017-03-27T05:57:59.000Z","size":8,"stargazers_count":27,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T22:16:34.184Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nolanlawson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-04T05:17:49.000Z","updated_at":"2024-02-25T21:12:04.000Z","dependencies_parsed_at":"2022-07-24T12:31:50.590Z","dependency_job_id":null,"html_url":"https://github.com/nolanlawson/pouchdb-ionic","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolanlawson%2Fpouchdb-ionic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolanlawson%2Fpouchdb-ionic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolanlawson%2Fpouchdb-ionic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nolanlawson%2Fpouchdb-ionic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nolanlawson","download_url":"https://codeload.github.com/nolanlawson/pouchdb-ionic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248849832,"owners_count":21171651,"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":[],"created_at":"2024-10-01T14:06:33.355Z","updated_at":"2025-04-14T08:43:06.182Z","avatar_url":"https://github.com/nolanlawson.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"pouchdb-ionic\n========\n\nPouchDB runs great in the Ionic Framework. Here's how to get started.\n\n_Note: these instructions were written for Ionic 1. For Ionic 2, you might try [this tutorial](https://gonehybrid.com/how-to-use-pouchdb-sqlite-for-local-storage-in-ionic-2/)._\n\n## Sample app\n\n* [PouchDB Ionic 1 \"hello world\" app](https://github.com/nolanlawson/pouchdb-ionic-hello-world)\n* [PouchDB Ionic 2 \"hello world\" app with TypeScript](https://github.com/nolanlawson/pouchdb-ionic-2-hello-world)\n* [PouchDB Ionic 2 \"hello world\" app with TypeScript, plus native SQLite](https://github.com/nolanlawson/pouchdb-ionic-2-hello-world-with-sqlite)\n\n## Installing PouchDB\n\nInstall with Bower:\n\n    bower install --save pouchdb\n    \nThen add `pouchdb.js` to `index.html` (after `cordova.js`):\n\n```html\n\u003cscript src=\"cordova.js\"\u003e\u003c/script\u003e\n\n\u003cscript src=\"lib/pouchdb/dist/pouchdb.min.js\"\u003e\u003c/script\u003e\n```\n\n## Using PouchDB\n\nPouchDB is already ready to be used within your controllers and services. Just call:\n\n```js\nvar db = new PouchDB('my_database');\n```\n\nThat's it!\n\n### Service pattern\n\nSince Angular services are singletons, and since we only need a single instance of a PouchDB database, a good practice is to create a service called `PouchService` that handles your PouchDB:\n\n```js\n\nfunction PouchService() {\n  this.db = new PouchDB('my_database');\n}\n\nangular.module('myModule').service('pouchService', PouchService)\n```\n\nNow you can access your database from `pouchService.db`.\n\n### $q.when()\n\nPouchDB promises are compliant with the [A+ spec](https://promisesaplus.com/). So if you want to turn them into Angular `$q` promises, you just wrap them in `$q.when()`:\n\n```js\n$q.when(pouchdb.post({})).then(function () {\n  /* ... */\n}).catch(function () {\n  /* ... */\n});\n```\n\n### $rootScope.$apply()\n\nSince PouchDB is asynchronous, you will often need to call `$scope.$apply()` or `$rootScope.$apply()` in order for the changes to be reflected in your UI. For instance, you might want to do:\n\n```js\nfunction PouchService($scope, $rootScope) {\n  $scope.listOfStuff = [];\n\n  $scope.db = new PouchDB('my_database');\n  \n  $scope.db.allDocs({include_docs: true}).then(function (result) {\n    var docs = result.rows.map(function (row) { return row.doc; });\n    \n    $scope.listOfStuff = docs;\n    \n    $rootScope.$apply(); // \u003c--- better call this!\n    \n  }).catch(function (error) {\n    // got an error somehow\n  });\n}\n```\n\nIf you get tired of calling `$rootScope.$apply()` all the time, you may want to look into a wrapper like [angular-pouchdb](https://github.com/angular-pouchdb/angular-pouchdb). But it's not required.\n\n### NPM Browser\n\nThere is an open-source Angular project called [NPM Browser](http://www.npm-browser.com) that you can check out for a more detailed example of using PouchDB with Angular.\n\nFor instance, here is the [pouch-service.js](https://github.com/pouchdb/npm-browser/blob/master/scripts/services/pouch-service.js) in that project.\n\n## See also\n\nThe [pouchdb-phonegap-cordova](https://github.com/nolanlawson/pouchdb-phonegap-cordova) guide, which has more general information about using PouchDB with Cordova/PhoneGap.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnolanlawson%2Fpouchdb-ionic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnolanlawson%2Fpouchdb-ionic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnolanlawson%2Fpouchdb-ionic/lists"}