React Native를 사용할 때 데이터를 저장하는 옵션은 무엇입니까? (iOS 및 Android) [닫힘]
나는 여전히 React Native 세계에서, 그리고 일반적으로 모바일 / 네이티브 세계에서도 처음이며, 데이터 지속성에 관한 문서가 약간 부족하다는 것을 알았습니다.
React Native에 데이터를 저장하는 옵션과 각 유형의 의미는 무엇입니까? 예를 들어, 로컬 스토리지와 비동기 스토리지가 있지만 Realm과 같은 것을 보았습니다.이 모든 것이 외부 데이터베이스와 어떻게 작동하는지 혼란 스럽습니다.
나는 구체적으로 알고 싶다 :
- 데이터 지속성을위한 다른 옵션은 무엇입니까?
- 각각에 대해 해당 지속성의 한계는 무엇입니까 (즉, 데이터를 더 이상 사용할 수없는시기)? 예를 들어 : 응용 프로그램을 닫거나 전화를 다시 시작할 때 등
- 각각에 대해 iOS와 Android에서 구현하는 데 차이가 있습니까 (일반 설정 제외)?
- 오프라인으로 데이터에 액세스하는 것과 옵션을 어떻게 비교합니까? (또는 오프라인 액세스는 일반적으로 어떻게 처리됩니까?)
- 명심해야 할 다른 사항이 있습니까?
당신의 도움을 주셔서 감사합니다!
몇 가지 현재 앱 프로젝트를 진행하는 가장 좋은 방법을 결정하면서 배운 내용은 다음과 같습니다.
비동기 저장소 (기본 제공)
프로덕션 앱에 AsyncStorage를 사용합니다. 스토리지는 기기에 로컬로 유지되고 암호화되지 않으며 (다른 답변에서 언급 한 바와 같이) 앱을 삭제하면 사라지지만 기기 백업의 일부로 저장되어 업그레이드 중에 유지되어야합니다 (기본 업그레이드는 TestFlight 및 CodePush를 통한 코드 업그레이드) ).
결론 : 로컬 스토리지; 자체 동기화 / 백업 솔루션을 제공합니다.
SQLite
내가 작업 한 다른 프로젝트는 앱 저장을 위해 sqlite3을 사용했습니다. 이는 압축 가능한 데이터베이스를 통해 SQL과 유사한 환경을 제공하며 장치와도주고받을 수 있습니다. 백엔드에 동기화 한 경험이 없지만 다양한 라이브러리가 있다고 생각합니다. SQLite에 연결하기위한 RN 라이브러리가 있습니다.
데이터는 데이터베이스, 테이블, 키, 인덱스 등이 모두 이진 형식으로 디스크에 저장된 기존 데이터베이스 형식으로 저장됩니다. SQLite 드라이버가있는 명령 줄 또는 앱을 통해 데이터에 직접 액세스 할 수 있습니다.
결론 : 로컬 스토리지; 동기화 및 백업을 제공합니다.
중포 기지
Firebase는 특히 실시간 noSQL 데이터베이스와 MongoDB와 같은 JSON 문서 저장소를 제공하여 1에서 n까지의 클라이언트 동기화를 유지합니다. 문서는 오프라인 지속성에 대해 이야기하지만 기본 코드 (Swift / Obj-C, Java)에 대해서만 이야기합니다. React Native에서 사용하는 Google 고유의 JavaScript 옵션 ( "웹")은 캐시 된 저장 옵션을 제공하지 않습니다 (아래 2/18 업데이트 참조). 라이브러리는 웹 브라우저가 연결될 것이라는 가정하에 작성되었으며 따라서 반영구적 연결이있을 것입니다. Firebase 저장소 호출을 보완하기 위해 로컬 캐싱 메커니즘을 작성하거나 기본 라이브러리와 React Native 사이의 브리지를 작성할 수 있습니다.
[2018 년 2 월 업데이트] 이후 네이티브 iOS 및 Android 라이브러리에 호환되는 JavaScript 인터페이스를 제공하는 React Native Firebase 를 찾았습니다 (Google에서 수행 할 수 있거나 수행했을 수있는 작업 수행). React Native 지원. Google이 실시간 데이터베이스 옆에 JSON 문서 저장소를 도입하면서 Firebase는 내가 구축하려는 일부 실시간 앱을 다시 한 번 살펴볼 것입니다.
실시간 데이터베이스는 JSON과 같은 트리로 저장되어 웹 사이트에서 편집하고 간단하게 가져 오기 / 내보내기 할 수 있습니다.
결론 : Reactive-native-firebase를 사용하면 RN은 Swift 및 Java와 동일한 이점을 얻습니다. [/ update] 네트워크 연결 장치에 맞게 확장 할 수 있습니다. 낮은 활용도를위한 저렴한 비용. 다른 Google 클라우드 제품과 잘 어울립니다. 인터페이스에서 데이터를 쉽게보고 편집 할 수 있습니다.
왕국
또한 자동 네트워크 동기화 기능을 갖춘 실시간 객체 저장소입니다. 그들은 "장치 우선"으로 선전하고 데모 비디오는 장치가 산발적이거나 손실 된 네트워크 연결을 처리하는 방법을 보여줍니다.
자체 서버 또는 AWS 또는 Azure와 같은 클라우드 솔루션에서 호스팅하는 무료 버전의 객체 저장소를 제공합니다. 장치와 함께 유지되지 않는 메모리 내 저장소, 서버와 동기화되지 않는 장치 전용 저장소, 읽기 전용 서버 저장소 및 하나 이상의 장치에서 동기화하기위한 전체 읽기 / 쓰기 옵션을 만들 수도 있습니다. Firebase보다 월별 비용이 높은 전문 및 엔터프라이즈 옵션이 있습니다.
Firebase와 달리 모든 Realm 기능은 Swift / ObjC / Java (네이티브) 앱에서와 마찬가지로 React Native 및 Xamarin에서 지원됩니다.
데이터는 코드의 객체와 연결되어 있습니다. 그것들은 정의 된 객체이기 때문에 스키마가 있으며 코드 관리를 위해서는 버전 관리가 필수적입니다. Realm이 제공하는 GUI 도구를 통해 직접 액세스 할 수 있습니다. 온 디바이스 데이터 파일은 플랫폼 간 호환 가능합니다.
결론 : 장치 우선, 무료 및 유료 요금제와의 선택적 동기화. React Native에서 지원되는 모든 기능. Firebase보다 수평 확장이 더 비쌉니다.
iCloud
나는 솔직히이 게임을 많이하지 않았지만 가까운 장래에 그렇게 할 것입니다.
CloudKit을 사용하는 기본 앱이있는 경우 CloudKit JS를 사용하여 웹 앱 (또는이 경우 React Native)에서 앱 컨테이너에 연결할 수 있습니다. 이 시나리오에서는 기본 iOS 앱과 React 기본 Android 앱이있을 것입니다.
Realm과 마찬가지로 데이터를 로컬에 저장하고 가능한 경우 iCloud와 동기화합니다. 앱을위한 공개 상점과 각 고객을위한 개인 상점이 있습니다. 고객은 매장이나 물건 중 일부를 다른 사용자와 공유하도록 선택할 수도 있습니다.
원시 데이터에 액세스하는 것이 얼마나 쉬운 지 모르겠습니다. 스키마는 Apple 사이트에서 설정할 수 있습니다.
결론 : Apple 대상 앱에 적합합니다.
소파베이스
큰 이름, 그 뒤에 큰 회사가 많이 있습니다. 표준 지원 비용이 포함 된 Community Edition 및 Enterprise Edition이 있습니다.
그들은 사이트에 React Native에 연결하는 튜토리얼을 가지고 있습니다. 나는 또한 이것에 많은 시간을 소비하지는 않았지만, 기능면에서 Realm의 실용적인 대안으로 보입니다. 앱 외부의 데이터 또는 빌드하는 API가 얼마나 쉬운 지 잘 모르겠습니다.
[편집 : Couchbase와 CouchDB에 대해 이야기하는 오래된 링크를 찾았으며 CouchDB는 아직 고려해야 할 또 다른 옵션입니다. 이 두 제품은 역사적으로 관련되어 있지만 현재 완전히 다른 제품입니다. 참조 이 비교를 .]
결론 : Realm과 비슷한 기능을 가지고 있습니다. 장치 전용 또는 동기화 가능 나는 그것을 시도해야합니다.
몽고 DB
I'm using this server side for a piece of the app that uses AsyncStorage locally. I like that everything is stored as JSON objects, making transmission to the client devices very straightforward. In my use case, it's used as a cache between an upstream provider of TV guide data and my client devices.
There is no hard structure to the data, like a schema, so every object is stored as a "document" that is easily searchable, filterable, etc. Similar JSON objects could have additional (but different) attributes or child objects, allowing for a lot of flexibility in how you structure your objects/data.
I have not tried any client to server synchronization features, nor have I used it embedded. React Native code for MongoDB does exist.
Conclusion: Local only NoSQL solution, no obvious sync option like Realm or Firebase.
[Update 2/2019]
MongoDB has a "product" (or service) called Stitch. Since clients (in the sense of web browsers and phones) shouldn't be talking to MongoDB directly (that's done by code on your server), they created a serverless front-end that your apps can interface with, should you choose to use their hosted solution (Atlas). Their documentation makes it appear that there is a possible sync option.
This writeup from Dec 2018 discusses using React Native, Stitch, and MongoDB in a sample app, with other samples linked in the document (https://www.mongodb.com/blog/post/building-ios-and-android-apps-with-the-mongodb-stitch-react-native-sdk).
Twilio Sync
Another NoSQL option for synchronization is Twilio's Sync. From their site: "Sync lets you manage state across any number of devices in real time at scale without having to handle any backend infrastructure."
I looked at this as an alternative to Firebase for one of the aforementioned projects, especially after talking to both teams. I also like their other communications tools, and have used them for texting updates from a simple web app.
[/Update]
[Edit] I've spent some time with Realm since I originally wrote this. I like how I don't have to write an API to sync the data between the app and the server, similar to Firebase. Serverless functions also look to be really helpful with these two, limiting the amount of backend code I have to write.
I love the flexibility of the MongoDB data store, so that is becoming my choice for the server side of web-based and other connection-required apps.
I found RESTHeart, which creates a very simple, scalable RESTful API to MongoDB. It shouldn't be too hard to build a React (Native) component that reads and writes JSON objects to RESTHeart, which in turn passes them to/from MongoDB.
[Edit] I added info about how the data is stored. Sometimes it's important to know how much work you might be in for during development and testing if you've got to tweak and test the data.
[Update 2/2019] I experimented with several of these options when designing a high-concurrency project this past year (2018). Some of them mention hard and soft concurrency limits in their documentation (Firebase had a hard one at 10,000 connections, I believe, while Twilio's was a soft limit that could be bumped, according to discussions with both teams at AltConf).
If you are designing an app for tens to hundreds of thousands of users, be prepared to scale the data backend accordingly.
Quick and dirty: just use Redux + react-redux + redux-persist + AsyncStorage for react-native.
It fits almost perfectly the react native world and works like a charm for both android and ios. Also, there is a solid community around it, and plenty of information.
For a working example, see the F8App from Facebook.
What are the different options for data persistence?
With react native, you probably want to use redux and redux-persist. It can use multiple storage engines. AsyncStorage and redux-persist-filesystem-storage are the options for RN.
There are other options like Firebase or Realm, but I never used those on a RN project.
For each, what are the limits of that persistence (i.e., when is the data no longer available)? For example: when closing the application, restarting the phone, etc.
Using redux + redux-persist you can define what is persisted and what is not. When not persisted, data exists while the app is running. When persisted, the data persists between app executions (close, open, restart phone, etc).
AsyncStorage has a default limit of 6MB on Android. It is possible to configure a larger limit (on Java code) or use redux-persist-filesystem-storage as storage engine for Android.
For each, are there differences (other than general setup) between implementing in iOS vs Android?
Using redux + redux-persist + AsyncStorage the setup is exactly the same on android and iOS.
How do the options compare for accessing data offline? (or how is offline access typically handled?)
Using redux, offiline access is almost automatic thanks to its design parts (action creators and reducers).
All data you fetched and stored are available, you can easily store extra data to indicate the state (fetching, success, error) and the time it was fetched. Normally, requesting a fetch does not invalidate older data and your components just update when new data is received.
The same apply in the other direction. You can store data you are sending to server and that are still pending and handle it accordingly.
Are there any other considerations I should keep in mind?
React promotes a reactive way of creating apps and Redux fits very well on it. You should try it before just using an option you would use in your regular Android or iOS app. Also, you will find much more docs and help for those.
Folks above hit the right notes for storage, though if you also need to consider any PII data that needs to be stored then you can also stash into the keychain using something like https://github.com/oblador/react-native-keychain since ASyncStorage is unencrypted. It can be applied as part of the persist configuration in something like redux-persist.
you can use sync storage that is easier to use than async storage. this library is great that uses async storage to save data asynchronously and uses memory to load and save data instantly synchronously, so we save data async to memory and use in app sync, so this is great.
import SyncStorage from 'sync-storage';
SyncStorage.set('foo', 'bar');
const result = SyncStorage.get('foo');
console.log(result); // 'bar'
you can use Realm or Sqlite if you want to manage complex data type.
Otherwise go with inbuilt react native asynstorage
We dont need redux-persist we can simply use redux for persistance.
react-redux + AsyncStorage = redux-persist
so inside createsotre file simply add these lines
store.subscribe(async()=> await AsyncStorage.setItem("store", JSON.stringify(store.getState())))
this will update the AsyncStorage whenever there are some changes in the redux store.
Then load the json converted store. when ever the app loads. and set the store again.
Because redux-persist creates issues when using wix react-native-navigation. If that's the case then I prefer to use simple redux with above subscriber function
'Programing' 카테고리의 다른 글
다른 ORDER BY로 PostgreSQL DISTINCT ON (0) | 2020.05.19 |
---|---|
명령 줄에서 .NET Core 콘솔 앱을 실행하는 방법 (0) | 2020.05.19 |
Chrome에서 자동 완성을 실행하는 방법은 무엇입니까? (0) | 2020.05.19 |
제목 속성에서 큰 따옴표를 이스케이프 처리하는 방법 (0) | 2020.05.19 |
“파일 끝에 줄 바꿈 없음”컴파일러 경고 (0) | 2020.05.19 |