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

outdated

Adding description next.

Create table class implements ISQLiteItem #

class SqlModel implements ISQLiteItem {
  int? id;
  String? title;
  String? value;

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

  @override
  String getTableName() {
    return 'sql_model';
  }

  @override
  int getPrimaryKey() {
    return id;
  }

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

  @override
  String getPrimaryKeyName() {
    return 'id';
  }

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

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 items = await connection.toList(SqlModel());
    //update items
    for (var item in items) {
      (item as SqlModel).value = 'Updated';
      await connection.update(item);
    }
    //Delete all table records
    connection.deleteAll(SqlModel());
    //Delete table
    connection.deleteTable(SqlModel());

pub.dev

4
likes
0
points
170
downloads

Publisher

unverified uploader

Weekly Downloads

Adding description next.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, path, path_provider, sqflite, sqflite_common_ffi

More

Packages that depend on sqlite_flutter_pcl