simolus3 / drift

Drift is an easy to use, reactive, typesafe persistence library for Dart & Flutter.
https://drift.simonbinder.eu/
MIT License
2.55k stars 365 forks source link

Coded out a small Class that can allow us to export data from database into CSV files (works on all platforms), because there is no existing method. Can I contribute it? If yes, how #907

Closed Dhi13man closed 3 years ago

Dhi13man commented 3 years ago

Not attaching the actual code. Just an usage example. Let me know if I can contribute it somehow. Might be useful.:

Future<bool> exportDatabase(
      {bool getEmployees = true,
      bool getAttendances = true,
      bool getEvents = true}) async {
    // INITIALIZE CSVGenerator object
    MoorSQLToCSV _csvGenerator;
    bool didSucceed = true;
    if (getEmployees) {
      List<Employee> _employees = await db.getAllEmployees(orderBy: 'id');
      if (_employees.isNotEmpty) {
        _csvGenerator = MoorSQLToCSV(_employees, csvFileName: 'employees');
        didSucceed = didSucceed && await _csvGenerator.wasCreated;
      }
    }
    if (getAttendances) {
      List<Attendance> _attendances = await db.getAllAttendances();
      if (_attendances.isNotEmpty) {
        _csvGenerator = MoorSQLToCSV(_attendances, csvFileName: 'attendances');
        didSucceed = didSucceed && await _csvGenerator.wasCreated;
      }
    }
    if (getEvents) {
      List<Event> _events = await db.getAllEvents();
      if (_events.isNotEmpty) {
        _csvGenerator = MoorSQLToCSV(_events, csvFileName: 'events');
        didSucceed = didSucceed && await _csvGenerator.wasCreated;
      }
    }
    return didSucceed;
  }
simolus3 commented 3 years ago

This looks like an interesting project, but I don't think exporting to CSV should be part of the core moor package. Feel free to publish your code on GitHub or in your own pub package though! I can link to your project in moor's documentation then.

Dhi13man commented 3 years ago

I have published it as a package. Would love it if you went through it once. Regardless, thank you.

https://github.com/Dhi13man/moor2csv https://pub.dev/packages/moor2csv