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.

Constructors

SqfLiteService({required DbHelper helper})

Properties

database Database
no setter
hashCode int
The hash code for this object.
no setterinherited
helper DbHelper
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

add({required 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.
executeQuery({required String query}) Future<void>
Execute SQL query whenever required
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() 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({required 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