dao_wrapped 0.2.0 copy "dao_wrapped: ^0.2.0" to clipboard
dao_wrapped: ^0.2.0 copied to clipboard

discontinued
outdated

Implementation of a dao interface for communicating with sql.

dao_wrapped #

dao_wrapped.

mixin sql wrapper with dao implementation for model.

implements methods

get, getAll, getByField,

set,setAll,

update,updateAll,

delete,deleteAll,

clear

all you need to do is describe table creation and model mapping(it can json_serializable).

example #

I recommend using the interface to communicate with the implementation.

for sample:

interface

abstract class SampleGateway {
  Future<List<SampleModel>> getAll();

  Future<SampleModel> get(int id);

  Future set(SampleModel model);

  Future delete(int id);
}

and its implementation.

class SampleGatewayImpl with DaoMixin<SampleModel> implements SampleGateway {
  @override
  final SampleGatewayTable databaseGateway;

  SampleGatewayImpl(Database database)
      : databaseGateway = SampleGatewayTable(database);
}

implements interface methods DaoMixin, so you don’t have to do anything with them.

part with model mapping and description of the table made in DatabaseGateway.

class SampleGatewayTable implements DatabaseGateway<SampleModel> {
  @override
  final Database db;

  SampleGatewayTable(this.db);

  @override
  String get primaryId => "id";

  @override
  String get table => "SampleModel";

  Future createTable() async {
    var createTableRequest = "CREATE TABLE IF NOT EXISTS $table("
        "$primaryId INTEGER PRIMARY KEY,"
        "message TEXT)";
    await db.execute(createTableRequest);
    print(createTableRequest);
  }


  @override
  SampleModel fromMap(Map<String, dynamic> map) {
    return SampleModel.fromMap(map);
  }

  @override
  Map<String, dynamic> toMap(SampleModel model) {
    return model.toMap();
  }

}

future #

in the future, the creation of the table will be in other module with code generation and without sql dependencies

0
likes
20
pub points
0%
popularity

Publisher

unverified uploader

Implementation of a dao interface for communicating with sql.

Repository (GitLab)
View/report issues

License

unknown (LICENSE)

Dependencies

dao_wrapped_annotation, flutter, sqflite

More

Packages that depend on dao_wrapped