Essential theory and context

According to the official site (SQLite.org), SQLite is a "small, fast, self-contained, high-reliability, full-featured, SQL database engine".

Let's see what that means to us, as Flutter mobile developers: first of all, SQLite is an SQL database engine. That means that you can use the SQL language to build queries, so if you are already familiar with SQL, you can leverage your knowledge. If you are totally new to databases, I suggest you have a look at the excellent W3Schools SQL tutorial at https://www.w3schools.com/sql/default.asp: you'll find it much easier to follow along with the project in this chapter.

The main features of SQLite are as follows:

  • Small and fast: Developers have extensively tested SQLite speed and file size, and it outperformed several other technologies, both as space on disk and for its speed of retrieval of data. More information is available at: https://sqlite.org/fasterthanfs.html and https://sqlite.org/footprint.html.
  • Self-contained means that SQLite requires very few external libraries, making it the perfect choice for any lightweight, platform-independent app. SQLite reads and writes directly from the database files on disk, so you don't have to set up any client-server connection in order to use it.
  • High reliability: SQLite has been used without problems in several billions of mobile, Internet of Things (IoT), and desktop devices for over a decade, proving itself extremely reliable.
  • Full-featured: SQLite has a full-featured SQL implementation, including tables, views, indexes, triggers, foreign key constraints, and several standard SQL functions.

SQLite is a very good choice for persisting data in Android and iOS because it's easy to implement, and is secure, in the public domain, cross-platform, and compact.

There are two schools of thought about how to pronounce SQLite: "Ess-Cue-El-Ight" or "See-Quel-Light". The creator of SQLite, Richard Hipp, generally uses the first one, but he also says that you can pronounce it however you want, and adds that there's no "official" pronunciation.

In order to add the SQLite features in Flutter, we will use the sqflite plugin, which is the SQLite plugin for Flutter that currently supports both iOS and Android, and contains asynchronous helper methods for SELECT, INSERT, UPDATE, AND DELETE queries. We'll see the steps required to use the sqflite plugin library throughout this chapter.

The database that we will create has two tables: lists and items. This can be seen in the following screenshot:

The lists table has three fields: id (integer), name (text), and priority (integer). 

The items table has an id (integer), a name (text), a quantity (text), a note (text), and an idList (integer) that will be a foreign key constraint that points to the id of the list. As you can see, the schema is very simple, but it will allow us to experiment with many of the features that are needed in order to build a database app.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.197.10