{"id":1674,"date":"2019-05-06T12:01:45","date_gmt":"2019-05-06T06:31:45","guid":{"rendered":"http:\/\/blog.openwebsolutions.in\/?p=1674"},"modified":"2019-05-06T12:01:45","modified_gmt":"2019-05-06T06:31:45","slug":"use-ionic-sqlite-instead-local-storage-build-app","status":"publish","type":"post","link":"https:\/\/openwebsolutions.in\/blog\/use-ionic-sqlite-instead-local-storage-build-app\/","title":{"rendered":"Why use Ionic SQLite instead of Local Storage to build an App?"},"content":{"rendered":"<p>First of all, SQLite is not an SQL database. It is an embedded SQL database engine. SQLite does not have any separate server process like the other SQL databases have. SQL database which includes tables, views and other things are contained in a single disk file whereas SQLite operates by directly reading and writing to ordinary files on the disk.<\/p>\n<p>SQLite implements serverless, self-contained, transactional, zero-configuration SQL database engine which is an in-process library. SQLite is free and is in public domain also, so it can be used for any private and commercial purpose.<\/p>\n<p>Ionic Local Storage uses the local storage system of browser for key\/value pairs storing. The limit of Local Storage is only 5MB. It is heard that an issue with local storage is that if iOS is out of memory, it can delete local storage data to gain memory space. Local Storage should be used only for temporary data storing where data loss can be affordable. Local Storage must be cleaned up by the operating system(iOS) to manage the storing of data under 5MB. If more space is needed for storing data, then SQLite is more preferable which uses SqlStorage engine.<\/p>\n<p>SQLite is a widely used file-based database and one of the most stable storage system for Ionic App.<\/p>\n<p>&nbsp;<\/p>\n<p>For using the SOLite, first we need to install the cordova-sqlite-storage plugin:<\/p>\n<p><strong>ionic cordova plugin add cordova-sqlite-storage<\/strong><\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p>After that, we need to install the package<\/p>\n<p><strong>npm install &#8211;save @ionic\/storage<\/strong><\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p>Then, import it in the <strong>app.module.ts<\/strong> and add it to the <strong>imports<\/strong><\/p>\n<p><strong>import { IonicStorageModule } from &#8216;@ionic\/storage&#8217;;<\/strong><\/p>\n<p><strong>@NgModule({<\/strong><\/p>\n<p><strong>\u00a0 declarations: [<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0 \/\/ &#8230;<\/strong><\/p>\n<p><strong>\u00a0 ],<\/strong><\/p>\n<p><strong>\u00a0 imports: [<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0 BrowserModule,<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0 IonicModule.forRoot(MyApp),<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0 IonicStorageModule.forRoot()<\/strong><\/p>\n<p><strong>\u00a0 ],<\/strong><\/p>\n<p><strong>\u00a0 bootstrap: [IonicApp],<\/strong><\/p>\n<p><strong>\u00a0 entryComponents: [<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0 \/\/ &#8230;<\/strong><\/p>\n<p><strong>\u00a0 ],<\/strong><\/p>\n<p><strong>\u00a0 providers: [<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0 \/\/ &#8230;<\/strong><\/p>\n<p><strong>\u00a0 ]<\/strong><\/p>\n<p><strong>})<\/strong><\/p>\n<p><strong>export class AppModule {}<\/strong><\/p>\n<p><strong>\u00a0<\/strong><\/p>\n<p>Finally, use it inside any component or page<\/p>\n<p><strong>import { Storage } from &#8216;@ionic\/storage&#8217;;<\/strong><\/p>\n<p><strong>export class MyApp {<\/strong><\/p>\n<p><strong>\u00a0 constructor(private storage: Storage) { }<\/strong><\/p>\n<p><strong>\u00a0 &#8230;<\/strong><\/p>\n<p><strong>\u00a0 \/\/ set a key\/value<\/strong><\/p>\n<p><strong>\u00a0 storage.set(&#8216;name&#8217;, &#8216;Max&#8217;);<\/strong><\/p>\n<p><strong>\u00a0 \/\/ Or to get a key\/value pair<\/strong><\/p>\n<p><strong>\u00a0 storage.get(&#8216;age&#8217;).then((val) =&gt; {<\/strong><\/p>\n<p><strong>\u00a0\u00a0\u00a0 console.log(&#8216;Your age is&#8217;, val);<\/strong><\/p>\n<p><strong>\u00a0 });<\/strong><\/p>\n<p><strong>}<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>First of all, SQLite is not an SQL database. It is an embedded SQL database engine. SQLite does not have any separate server process like the other SQL databases have. SQL database which includes tables, views and other things are contained in a single disk file whereas SQLite operates by directly reading and writing to [&hellip;]<\/p>\n","protected":false},"author":32,"featured_media":1688,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[92,102],"tags":[74,104],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Why use Ionic SQLite instead of Local Storage to build an App?<\/title>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/openwebsolutions.in\/blog\/use-ionic-sqlite-instead-local-storage-build-app\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Why use Ionic SQLite instead of Local Storage to build an App?\" \/>\n<meta property=\"og:description\" content=\"First of all, SQLite is not an SQL database. It is an embedded SQL database engine. SQLite does not have any separate server process like the other SQL databases have. SQL database which includes tables, views and other things are contained in a single disk file whereas SQLite operates by directly reading and writing to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/openwebsolutions.in\/blog\/use-ionic-sqlite-instead-local-storage-build-app\/\" \/>\n<meta property=\"og:site_name\" content=\"Openweb Solutions Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-06T06:31:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/openwebsolutions.in\/blog\/wp-content\/uploads\/2019\/05\/ionic.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"408\" \/>\n\t<meta property=\"og:image:height\" content=\"276\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#website\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/\",\"name\":\"Openweb Solutions Blog\",\"description\":\"Transforming ideas into reality\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/openwebsolutions.in\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/use-ionic-sqlite-instead-local-storage-build-app\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/wp-content\/uploads\/2019\/05\/ionic.jpg\",\"width\":408,\"height\":276},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/use-ionic-sqlite-instead-local-storage-build-app\/#webpage\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/use-ionic-sqlite-instead-local-storage-build-app\/\",\"name\":\"Why use Ionic SQLite instead of Local Storage to build an App?\",\"isPartOf\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/use-ionic-sqlite-instead-local-storage-build-app\/#primaryimage\"},\"datePublished\":\"2019-05-06T06:31:45+00:00\",\"dateModified\":\"2019-05-06T06:31:45+00:00\",\"author\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#\/schema\/person\/094fa2d34b71e8b2c73c005d1bd4c074\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/openwebsolutions.in\/blog\/use-ionic-sqlite-instead-local-storage-build-app\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#\/schema\/person\/094fa2d34b71e8b2c73c005d1bd4c074\",\"name\":\"Soumik Hens\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5028fba9f350d268e8a8845b54985006?s=96&r=g\",\"caption\":\"Soumik Hens\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1674"}],"collection":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/comments?post=1674"}],"version-history":[{"count":4,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1674\/revisions"}],"predecessor-version":[{"id":1689,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1674\/revisions\/1689"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/media\/1688"}],"wp:attachment":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/media?parent=1674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/categories?post=1674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/tags?post=1674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}