Convert Figma logo to code with AI

tekartik logosqflite

SQLite flutter plugin

2,855
524
2,855
193

Top Related Projects

3,545

Extremely fast, easy to use, and fully async NoSQL database for Flutter

4,011

Lightweight and blazing fast key-value database written in pure Dart.

Flutter database for super-fast Dart object persistence

Quick Overview

Sqflite is a Flutter plugin for SQLite, providing a powerful and efficient way to work with local databases in Flutter applications. It offers a straightforward API for performing CRUD operations, executing raw SQL queries, and managing database transactions.

Pros

  • Easy integration with Flutter projects
  • Supports both Android and iOS platforms
  • Provides a simple and intuitive API for database operations
  • Offers transaction support for maintaining data integrity

Cons

  • Limited to SQLite databases only
  • May require additional setup for more complex database schemas
  • Performance can be affected when dealing with large datasets
  • Lacks some advanced features found in more comprehensive database solutions

Code Examples

  1. Opening a database:
import 'package:sqflite/sqflite.dart';

Future<Database> openDb() async {
  return await openDatabase('my_db.db', version: 1,
      onCreate: (Database db, int version) async {
    await db.execute(
        'CREATE TABLE Test (id INTEGER PRIMARY KEY, name TEXT, value INTEGER)');
  });
}
  1. Inserting data:
Future<void> insertData(Database db) async {
  await db.insert('Test', {'name': 'example', 'value': 42});
}
  1. Querying data:
Future<List<Map<String, dynamic>>> getData(Database db) async {
  return await db.query('Test', where: 'name = ?', whereArgs: ['example']);
}
  1. Updating data:
Future<void> updateData(Database db) async {
  await db.update('Test', {'value': 100},
      where: 'name = ?', whereArgs: ['example']);
}

Getting Started

To use Sqflite in your Flutter project, add it to your pubspec.yaml:

dependencies:
  sqflite: ^2.2.8+4

Then, import and use it in your Dart code:

import 'package:sqflite/sqflite.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  final database = await openDatabase('my_database.db');
  // Use the database for CRUD operations
}

Competitor Comparisons

3,545

Extremely fast, easy to use, and fully async NoSQL database for Flutter

Pros of Isar

  • Faster performance, especially for large datasets
  • Native support for complex queries and indexing
  • Built-in encryption and ACID compliance

Cons of Isar

  • Steeper learning curve due to more complex API
  • Limited platform support (primarily Flutter/Dart)
  • Smaller community and ecosystem compared to SQLite

Code Comparison

Isar:

final isar = await Isar.open([ContactSchema]);
final newContact = Contact()..name = 'John Doe'..age = 30;
await isar.writeTxn(() async {
  await isar.contacts.put(newContact);
});

Sqflite:

final db = await openDatabase('my_db.db');
await db.insert('contacts', {
  'name': 'John Doe',
  'age': 30,
});

Isar offers a more object-oriented approach with schema definitions and type-safe queries, while Sqflite provides a more traditional SQL-like interface. Isar's syntax is more verbose but offers stronger type safety and query capabilities. Sqflite's approach is simpler and more familiar to developers with SQL experience.

Both libraries serve different needs: Isar is optimized for high-performance, complex data operations in Flutter apps, while Sqflite provides a lightweight SQLite wrapper for broader use cases and platform compatibility.

4,011

Lightweight and blazing fast key-value database written in pure Dart.

Pros of Hive

  • Faster performance for read/write operations
  • No native dependencies, pure Dart implementation
  • Supports complex data types and nested objects out of the box

Cons of Hive

  • Limited querying capabilities compared to SQL databases
  • No built-in support for relations between objects
  • Potential for larger database sizes due to NoSQL nature

Code Comparison

Hive:

var box = await Hive.openBox('myBox');
await box.put('key', 'value');
var value = box.get('key');

Sqflite:

final db = await openDatabase('my_db.db');
await db.insert('table', {'column': 'value'});
var value = await db.query('table', where: 'column = ?', whereArgs: ['value']);

Key Differences

  • Hive uses a key-value store model, while Sqflite is a SQL database
  • Hive operations are synchronous by default, Sqflite is asynchronous
  • Sqflite provides more advanced querying capabilities
  • Hive offers better performance for simple data storage and retrieval
  • Sqflite is more suitable for complex data relationships and joins

Flutter database for super-fast Dart object persistence

Pros of ObjectBox

  • Higher performance, especially for large datasets
  • Object-oriented API with type-safe queries
  • Supports relations and eager loading

Cons of ObjectBox

  • Larger binary size due to native libraries
  • Less flexible for complex SQL operations
  • Steeper learning curve for developers familiar with SQL

Code Comparison

ObjectBox:

@Entity()
class Person {
  int id;
  String name;
  int age;
}

final box = store.box<Person>();
box.put(Person(name: 'John', age: 30));
final people = box.query(Person_.age.greaterThan(25)).build().find();

Sqflite:

await db.insert('Person', {'name': 'John', 'age': 30});
final people = await db.query('Person', where: 'age > ?', whereArgs: [25]);

ObjectBox offers a more object-oriented approach with type-safe queries, while Sqflite provides a more traditional SQL-like interface. ObjectBox generally requires less boilerplate code for simple operations, but Sqflite offers more flexibility for complex queries. The choice between the two depends on the specific needs of the project, with ObjectBox excelling in performance and ease of use for object-oriented programming, while Sqflite provides a familiar SQL-based approach with greater query flexibility.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

sqflite

pub package

SQLite plugin for Flutter. Supports iOS, Android and MacOS.

  • Support transactions and batches
  • Automatic version management during open
  • Helpers for insert/query/update/delete queries
  • DB operation executed in a background thread on iOS and Android
  • Linux/Windows/DartVM support using sqflite_common_ffi

Documentation