sqliteHow do I use SQLite with Flutter?
Using SQLite with Flutter is a very simple process. Here is an example of how to use it:
import 'package:sqflite/sqflite.dart';
//get a database
var db = await openDatabase('my_db.db');
//create a table
await db.execute('CREATE TABLE IF NOT EXISTS my_table (id INTEGER PRIMARY KEY, name TEXT, value INTEGER, num REAL)');
//insert some data
int id1 = await db.rawInsert('INSERT INTO my_table(name, value, num) VALUES("some name", 1234, 456.789)');
//query the database
List<Map> list = await db.rawQuery('SELECT * FROM my_table');
//update some data
int count = await db.rawUpdate('UPDATE my_table SET name = ?, VALUE = ? WHERE name = ?', ['new name', '9876', 'some name']);
//delete data
int count = await db.rawDelete('DELETE FROM my_table WHERE name = ?', ['some name']);
//close database
db.close();
Above code will:
- Open a database connection with
openDatabase
- Create a table with
execute
- Insert data with
rawInsert
- Query the database with
rawQuery
- Update data with
rawUpdate
- Delete data with
rawDelete
- Close the database connection with
close
Helpful links
More of Sqlite
- How do I use the SQLite ZIP VFS to compress a database?
- How do I use SQLite with Zephyr?
- How to configure SQLite with XAMPP on Windows?
- How can I use SQLite with WebAssembly?
- How do I use regular expressions to query a SQLite database?
- How do I extract the year from a datetime value in SQLite?
- How can I use SQLite to query for records between two specific dates?
- How can SQLite and ZFS be used together for software development?
- How do I import data from a SQLite zip file?
- How can I query a SQLite database for records from yesterday's date?
See more codes...