We have a blank SQLite database, but we need a place to insert some records. For debugging in simulator fallback to native SQL LiteĪpp.db = window.openDatabase("My Database", "1.0", "Cordova Demo", 200000) Īt this point we have a SQLite database that is ready for us to use! Creating a Database Table To do this we are going to add an event listener that will execute a JavaScript function when Cordova has told us that the device is ready: document.addEventListener("deviceready", init, false) Īpp.db = ("My Database") When your mobile app initializes, you're going to want to create your SQLite database. That's it! Your project is now configured to use the SQLite plugin. In your project properties, navigate to the Plugins pane, check the box next to SQLite, and then hit the save button. Navigate to your project properties by double-clicking on the Properties option in the Project Navigator. The first thing I'm going to do is include the SQLite plugin in my app. I am going to assume you have a certain familiarity with one of the two Icenium IDEs, but if you don't, no problem! Take a look at the multi-part Deep Dive into Icenium Graphite series. Go ahead and create a new project from the Graphite or Mist Dashboard. There is separate documentation for the iOS and Android versions.Īt this point we know what SQLite is, so lets walk through what we'll need to do to set up the plugin in our Icenium project and show some simple examples to interface with the SQLite database. While not a mandatory step, you may be curious to read more about the Cordova SQLite plugin. Even better is the fact that Icenium includes built-in support for the Cordova SQLite plugin! This means that the initial configuration for your app is about as difficult as checking a box. Luckily for us, a group of kind-hearted individuals created a plugin for Apache Cordova that makes setting up and interfacing with a SQLite database relatively painless. In no time you can have a database running that stores anything from plain text to binary data (images, documents, etc). The database is created within your app and runs within the context of your app. This means that we have at our disposal a powerful relational database that is easy to set up and doesn't require a server to run. a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. So what exactly is SQLite? As explained on the SQLite web site, SQLite is: There are certainly alternatives (like cloud storage), but you can't deny the raw speed of dealing with data locally (not to mention the offline experience). If you are writing a hybrid mobile app and want to store, manage, and retrieve data in an efficient and reliable manner, SQLite is for you. And while you can certainly write an amazing app without knowing any SQL, I'm here to show you how you can simply and easily set up and manage a lightweight, but very powerful, database within your own hybrid mobile app using the Cordova SQLite plugin. Databases are the foundation of every data-driven app out there. If the words "database" or "SQL" strike fear into your heart, or even if you are somewhat comfortable in this realm, this is the blog post for you. However, in a short amount of time I'm going to show you how you can leverage the power of a relational database inside your hybrid mobile app. Often times frontend developers are more concerned with the UI or UX of their web site or app and leave the heavy data lifting to the backend developers. I'll admit it, backend development can occasionally be intimidating.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |