How to insert data coming from JSON using Sqlite


#1

IONIC 3: Can anyone help me with a working example for Sqlite. I want to insert the data from a JSON file and fetch the data where ever i require. There is no proper documentation for using Sqlite. So i would request to help me with understanding the concept. Thanks in advance.


#2

Do you have a sample of what the JSON looks like?


#3

This is my sample data.
“medcicines”: [
{
“id”: 1,
“manufacturer_id”: “M01303”,
“manufacturer_entity_name”: “KONTEST”,
“manufacturer_name”: “KONTEST”,
“category_id”: “CT0001”,
“category_name”: “SWALLOW”,
“subcategory_id”: “IG0107”,
“subcategory_name”: “TABLET”,
“item_id”: “”,
“item_name”: “EKLOT”,
“product_id”: “21203”,
“product_name”: “EKLOT 250MG TAB”,
“product_qty_absolute”: “10”,
“measurement_unit”: “No.s”,
“pack_quantity”: “10S", "item_strength": "250MG", "product_packform": "STRIPS", "content_name": "ETHAMSYLATE", "content_id": "E037", "product_schedule": "H", "product_banned_flag": "FALSE", "product_undeliverable_flag": "FALSE", "product_H1_flag": "FALSE", "product_requires_refrigeration": "FALSE", "chronic_flag": "", "created_at": "2017-05-18T09:45:17.000Z", "updated_at": "2017-05-18T09:45:35.000Z" }, { "id": 2, "manufacturer_id": "M00636", "manufacturer_entity_name": "COXSWAIN HEALTHCARE", "manufacturer_name": "COXSWAIN HEALTHCARE", "category_id": "CT0001", "category_name": "SWALLOW", "subcategory_id": "IG0107", "subcategory_name": "TABLET", "item_id": "", "item_name": "OGIT OZ", "product_id": "22413", "product_name": "OGIT OZ TAB", "product_qty_absolute": "10", "measurement_unit": "No.s", "pack_quantity": "10S”,
“item_strength”: “”,
“product_packform”: “STRIPS”,
“content_name”: “OFLOXACIN+ORNIDAZOLE”,
“content_id”: “O063”,
“product_schedule”: “H”,
“product_banned_flag”: “TRUE”,
“product_undeliverable_flag”: “FALSE”,
“product_H1_flag”: “FALSE”,
“product_requires_refrigeration”: “FALSE”,
“chronic_flag”: “”,
“created_at”: “2017-05-18T09:45:17.000Z”,
“updated_at”: “2017-05-18T09:45:35.000Z”
}
]


#4

Are you going to need to be querying across many different fields in order to find matching records, or can you always get away with just retrieving them by their id field? I’m trying to discern whether you really need to be directly interacting with SQLite or can get away with just key/value storage. If you can avoid direct SQLite interaction, it really makes things easier, because ionic-storage works in browsers as well.


#5

Okay, so my question is how to save JSON data using Storage. Because i am having close to 25 keys with values which needs to be stored. Is it possible to store 25 key-value pairs at once???


#6

Yes, it is possible.


#7

Can you please share the sample code to store the key-value pairs. It would of great help.