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

discontinued

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.

You can use dao_wrapped_gen for generate sql table:

@DaoTable(SampleModel)
class SampleGatewayTable extends DatabaseGateway<SampleModel> with WithTable {
  @override
  final Database db;
  @override
  final ModelTable modelTable = _Table();

  SampleGatewayTable(this.db);

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

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

or you can not use it

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();
  }

}
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