sqlite_flutter_pcl 0.0.23 copy "sqlite_flutter_pcl: ^0.0.23" to clipboard
sqlite_flutter_pcl: ^0.0.23 copied to clipboard

is a Flutter library that simplifies SQLite database management in your applications. It provides a clean and intuitive API for creating, reading, updating, and deleting database records, making it ea [...]

Create table class implements ISQLiteItem #

class SqlModel implements ISQLiteItem {
  static const String tableName = 'sql_model';
  static const String tableId = 'id';
  static const String tableTitle = 'title';
  static const String tableValue = 'value';


  int? id;
  String? title;
  String? value;

  SqlModel({this.id, this.title, this.value});

  @override
  String getTableName() {
    return tableName;
  }

  @override
  int getPrimaryKey() {
    return id ?? 0;
  }

  @override
  Map<String, dynamic> toMap() {
    return {
      tableId: id,
      tableTitle: title,
      tableValue: value,
    };
  }

  @override
  String getPrimaryKeyName() {
    return tableId;
  }

  @override
  ISQLiteItem fromMap(Map<String, dynamic> map) {
    return SqlModel(
      id: map[tableId],
      title: map[tableTitle],
      value: map[tableValue],
    );
  }
}

Create instance of SQLiteConnection #

   //Init if SQLiteConnection not initialize when new instance created
    SQLiteConnection.initDatabaseLib();
    //Sqlite filepath
    final databasePath = await getTemporaryDatabasePath();
    final connection = SQLiteConnection(path: databasePath);
    //create table
    connection.createTable(SqlModel());
    //insert new item;
    var newItem = SqlModel(title: 'Title 1', value: 'Value 1');
    await connection.insert(newItem);
    //retrieve items
    var isqliteItems = await connection.toList(SqlModel());
    //convert to type list
    var items = isqliteItems.whereType<SqlModel>().toList();
    //update items
    for (var item in items) {
      item.value = 'Updated';
      await connection.update(item);
    }
    //OR
    await connection.updateAll(items);
    //delete items
    await connection.deleteAll(items);
    //query single value
    var queryItems = await connection.whereSingle(SqlModel(), 'title', 'Title 1');
    //query items by value
    var queryItems = await connection.where(SqlModel(), 'title', 'Title 1');
    //search items
    var searchItems = await connection.search(SqlModel(), 'title', 'title 1');
    //search by multiple columns with single query
    var results = await connection.whereSearchOr(SqlModel(), ['title', 'value'], query);

    //Delete all table records
    connection.deleteRecords(SqlModel());
    //Delete table
    connection.deleteTable(SqlModel());

pub.dev

4
likes
0
points
170
downloads

Publisher

unverified uploader

Weekly Downloads

is a Flutter library that simplifies SQLite database management in your applications. It provides a clean and intuitive API for creating, reading, updating, and deleting database records, making it easy to work with structured data. With support for data modeling, pagination, and backup functionality, this library enhances your app's data persistence capabilities, allowing developers to focus on building rich user experiences without worrying about underlying database complexities.

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

flutter, path, path_provider, sqflite, sqflite_common_ffi

More

Packages that depend on sqlite_flutter_pcl