SqfLiteService class

A service class for managing SQLite database operations using the sqflite package.

This class provides a singleton interface to initialize, query, insert, update, and delete data from a SQLite database. It requires a DbHelper instance for database configuration such as table name, version, and SQL statements.

Usage:

  1. Call init with a DbHelper instance before using any other methods.
  2. Use get, add, update, and delete for CRUD operations.

Example:

await SqfLiteService.instance.init(myDbHelper);
await SqfLiteService.instance.add({'column': 'value'});
final data = await SqfLiteService.instance.get();

Throws:

  • Throws an Exception if database is not initialized before use.
  • Returns a Future.error with a descriptive message on operation failures.

Properties

database Future<Database>
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(Map<String, Object?> data) Future<void>
Inserts a new record into the database table.
delete({String? where, List<Object?>? whereArgs}) Future<void>
Deletes records from the database table.
get({String? where, List<Object?>? whereArgs, String? groupBy, String? orderBy, int? limit}) Future<List<Map<String, dynamic>>>
Retrieves a list of records from the database table.
init(DbHelper helper) Future<void>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
update(Map<String, Object?> data, String? where, List<Object?>? whereArgs) Future<void>
Updates existing records in the database table.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

instance SqfLiteService
final