I am creating a react native app to load phone book contacts to my app using this library. I loaded contact correctly in my app. Now I wanted to save contact details into the SQL database. How can I insert array data into the SQL database?
Asked
Active
Viewed 1,296 times
1 Answers
0
If you want to save data into your device storage, first you have to decide what storage or library you want to use. There are 2 common types of storage that you can look into:
Async storage: asynchronous, unencrypted, persistent, key-value storage
SQL or other storage engines: you can choose what library fits your needs (SQLite, realm, .etc). You can find them here. I highly recommend WatermelonDB which is good for scaling and can connect to your react components to re-render when there are changes in the database.
If you only need to store a small number of simple records. Async storage can work just fine. In case you need a relational database or a larger number of records, you can use the latter options.
-
Actually I am using an API to process my data. I created an API with .NET CORE. And I used the SQL server management studio as my database. Now I want to store contact details in my database. I used a library to load contacts into my app and it contain an array with contact detail. I want to insert that array data into my database. – Sidath Apr 03 '20 at 04:12
-
@Sidath in that case, you can make a request to your API and store your data. This document describes how to make a request to an API https://reactnative.dev/docs/network. You should use POST method and post your array of contact details in the body of the request (you can see the example in the document). – Khang Le Apr 03 '20 at 05:25
-
Ok, I'll try with these steps. And I have no idea about my database structure. In order to this library (https://github.com/logisticinfotech/react-native-contact-multi-select) that array contains a full-name, number, and avatar. I need to store the name and contact number only. How should I make my database structure? Please Give me an idea. – Sidath Apr 03 '20 at 07:01
-
@Sidath you should separate the front-end and the back-end, and communicate using RESTful API (json). So in the front-end you can use any library that you like, and in the back-end you can parse the json to your .NET object and store it using SQL. You can look into Relational Database Design to find a good way to design your database. – Khang Le Apr 03 '20 at 08:09