My SQLite plugin of choice is react-native-sqlite-storage, built by GitHub user Andrzej Porebski. It’s only been tested on iOS at this time, but the native plugins and JS code should both work on Android as well. It can be found here:Ĭheck out React Native SQLite Demo on GitHub. I created a basic List app using the approach outlined below so I could share a working example of these concepts (and code) in action. For example, if data must be shared with other users of the app, an approach involving a centralized database service is likely more appropriate. It’s worth noting that this approach will not work for every app. Looking for steps to bootstrap an app like this? Take 10 minutes and work through the official docs on the subject first: Using TypeScript with React Native. Let’s begin by adding the native SQLite bits to an existing React Native app (RN going forward) that’s built with the excellent combo of TypeScript and CocoaPods. It’s fast, rock solid, and has been battle tested for years across a huge array of platforms and devices. When it comes to storing relational data on-device with minimal overhead, SQLite is the natural choice. If your users’ wish to sync their data with another device, the app can be integrated with a service like Dropbox (a pattern I’ve seen work well in other apps, such as pre-version 7 1Password).The app will work offline without any extra effort, since the entire datastore will be contained in the app’s sandbox directory.No server-side code to develop, debug, load test, and monitor.There’s no server for you to manage, patch, keep online, and serve as a single point of failure for your app.Why might you pursue building an offline first app with an integrated database? This article walks through how I built an offline first React Native app using a device-local SQLite database, and details the patterns that I would recommend following when building your own. The text has been condensed too because man did I ever ramble on back then □. The code and content has been given a complete overhaul for 2020 to feature Hooks, Context, and updated to use React Native 0.61.5. What follows is a refresh of my most-read post, originally published in 2018. Building an offline first app with React Native and SQLite: 2020 refresh May 3, 2020, by Bruce Lefebvre The github page for cordova-sqlite-storage plugin have examples on how to do different operations on the database, below is a simple factory that can make these operations clean and readable. So that 'db' is accessible through our the scope the app.ĭb = $cordovaSQLite.openDB() ĭb = window.openDatabase("myapp.db", "1.0", "My app", -1) Install SQLite Cordova Plugin cordova plugin add Inject as an Angular dependency angular.module('myApp', ) Include in your index.html file before cordova.js and after your AngularJS / Ionic file (since ngCordova depends on AngularJS). SQLite can be accessed natively only, so you need to install the cordova plugin for SQLite.ĭownload ngCordova dependancies bower install ngCordova In this post we discuss how to efficiently work with SQLite using a simple factory that can be used for doing simple operations on your SQLite Database. SQLite works fine for both the platforms (Android & iOS). One of the pain points in hybrid app development is data persistence & data storage. Though LocalStorage can be used for storing less critical data like cache, devs usually look at SQLite for consistent data storage backend.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |