{"id":21835228,"url":"https://github.com/dhi13man/moor2csv","last_synced_at":"2026-02-16T06:02:35.246Z","repository":{"id":56834914,"uuid":"310916777","full_name":"Dhi13man/moor2csv","owner":"Dhi13man","description":"A Dart/Flutter package working with Moor, that allows exporting SQL-based Moor databases to a CSV form, for external storage or sharing. Works on all platforms except Web.","archived":false,"fork":false,"pushed_at":"2025-02-08T19:42:57.000Z","size":133,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T20:04:07.795Z","etag":null,"topics":["dart","dart-package","flutter","flutter-package","moor","open-source","pub","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dhi13man.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-07T19:26:55.000Z","updated_at":"2025-02-08T19:42:17.000Z","dependencies_parsed_at":"2023-01-22T00:45:36.158Z","dependency_job_id":null,"html_url":"https://github.com/Dhi13man/moor2csv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dhi13man%2Fmoor2csv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dhi13man%2Fmoor2csv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dhi13man%2Fmoor2csv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dhi13man%2Fmoor2csv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dhi13man","download_url":"https://codeload.github.com/Dhi13man/moor2csv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244811380,"owners_count":20514276,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","dart-package","flutter","flutter-package","moor","open-source","pub","sqlite"],"created_at":"2024-11-27T20:18:45.618Z","updated_at":"2026-02-16T06:02:35.219Z","avatar_url":"https://github.com/Dhi13man.png","language":"Dart","funding_links":["https://img.buymeacoffee.com/button-api/?text=Buy%20me%20an%20Ego%20boost\u0026emoji=%F0%9F%98%B3\u0026slug=dhi13man\u0026button_colour=FF5F5F\u0026font_colour=ffffff\u0026font_family=Lato\u0026outline_colour=000000\u0026coffee_colour=FFDD00****","https://www.buymeacoffee.com/dhi13man"],"categories":[],"sub_categories":[],"readme":"# drift2csv / moor2csv\n\n[![License](https://img.shields.io/github/license/dhi13man/moor2csv)](https://github.com/Dhi13man/moor2csv/blob/main/LICENSE)\n[![Language](https://img.shields.io/badge/language-Dart-blue.svg)](https://dart.dev)\n[![Language](https://img.shields.io/badge/language-Flutter-blue.svg)](https://flutter.dev)\n[![Contributors](https://img.shields.io/github/contributors-anon/dhi13man/moor2csv?style=flat)](https://github.com/Dhi13man/moor2csv/graphs/contributors)\n[![GitHub forks](https://img.shields.io/github/forks/dhi13man/moor2csv?style=social)](https://github.com/Dhi13man/moor2csv/network/members)\n[![GitHub Repo stars](https://img.shields.io/github/stars/dhi13man/moor2csv?style=social)](https://github.com/Dhi13man/moor2csv/stargazers)\n[![Last Commit](https://img.shields.io/github/last-commit/dhi13man/moor2csv)](https://github.com/Dhi13man/moor2csv/commits/main)\n[![Flutter Format, Analyse](https://github.com/Dhi13man/moor2csv/actions/workflows/flutter.yml/badge.svg)](https://github.com/Dhi13man/moor2csv/actions)\n[![moor2csv version](https://img.shields.io/pub/v/moor2csv.svg)](https://pub.dev/packages/moor2csv)\n\n[![\"Buy Me A Coffee\"](https://img.buymeacoffee.com/button-api/?text=Buy%20me%20an%20Ego%20boost\u0026emoji=%F0%9F%98%B3\u0026slug=dhi13man\u0026button_colour=FF5F5F\u0026font_colour=ffffff\u0026font_family=Lato\u0026outline_colour=000000\u0026coffee_colour=FFDD00****)](https://www.buymeacoffee.com/dhi13man)\n\nSupporting package for SQL/Drift/Moor, that allows easily **exporting SQL-based Moor database to a CSV form**, for external storage or sharing. Works on all platforms except Web.\n\n**Find Package on Official Dart Pub:**\n\n[![drift2csv version](https://img.shields.io/pub/v/moor2csv.svg)](https://pub.dev/packages/moor2csv)\n\n## Usage Steps\n\nFirst, perform necessary steps to provide Storage capability in the device you are developing for.\nExample: Editing `android\\app\\src\\main\\AndroidManifest.xml` and [providing permissions](https://developer.android.com/about/versions/11/privacy/permissions) for Android.\n\n1. Set up a Moor/Drift Database in your flutter project and create necessary Data Structures and tables. Example:\n\n    ```dart\n    class Employees extends Table {\n      TextColumn get employeeID =\u003e text()();\n      TextColumn get name =\u003e text().withLength(max: 100).nullable()();\n      IntColumn get phoneNo =\u003e integer().nullable()();\n      TextColumn get deviceID =\u003e text().nullable()();\n\n      @override\n      Set\u003cColumn\u003e get primaryKey =\u003e {employeeID};\n    }\n\n    @DriftDatabase(tables: [Employees])\n    class Database extends _$Database {\n      Database(QueryExecutor e) : super(e);\n\n      @override\n      int get schemaVersion =\u003e 1;\n\n      // DATABASE OPERATIONS\n      //EMPLOYEES\n      Future\u003cList\u003cEmployee\u003e\u003e getAllEmployees({\n        String orderBy = 'asce',\n        String mode = 'name',\n      }) =\u003e\n          (select(employees)\n                ..orderBy(\n                  [\n                    (u) {\n                      GeneratedColumn\u003cString?\u003e criteria = employees.employeeID;\n                      final OrderingMode order =\n                          (mode == 'desc') ? OrderingMode.desc : OrderingMode.asc;\n                      if (orderBy == 'id') {\n                        criteria = employees.employeeID;\n                      } else if (orderBy == 'name') {\n                        criteria = employees.name;\n                      } else if (orderBy == 'device') {\n                        criteria = employees.deviceID;\n                      }\n                      return OrderingTerm(expression: criteria, mode: order);\n                    }\n                  ],\n                ))\n              .get();\n    }\n    ```\n\n2. Run a query to get your `List\u003cDataClass\u003e` item from the Database.  \nExample: `List\u003cEmployee\u003e _employees = await db.getAllEmployees();` in an `async` function gets us our `List\u003cDataClass\u003e` item from database `db`.\n\n3. Simply Create a `DriftSQLToCSV` object and then use the `writeToCSV()` method by passing in the the `List\u003cDataClass\u003e` object as parameter to it (and optionally the CSV file name to save it as):\n\n    ```dart\n    // Assuming Employee is a DataClass\n    final List\u003cEmployee\u003e employees = [\n        Employee(employeeID: '1', name: 'testA'),\n        Employee(employeeID: '2', name: 'tenstB', phoneNo: 1203123112),\n        Employee(employeeID: '3', name: 'temstC', deviceID: 'testDevice'),\n        Employee(\n            employeeID: '4', name: 'test,D', phoneNo: 132123124, deviceID: 's'),\n      ]; // Replaced with values from database in actual implementation using select query get()\n\n    // Using DriftSQLToCSV\n    final DriftSQLToCSV DriftSQLToCSV = DriftSQLToCSV();\n    await DriftSQLToCSV.writeToCSV(_employees, csvFileName: 'employees');\n    ```\n\n    It will do all the necessary work to export your Database to a CSV file. Example to store `_employees` object of type `Employee table` in `employees.csv`\n\n4. The method also returns a `Future\u003cFile\u003e` object that can be used to perform further operations on the saved CSV.\n\n5. If the Database was successfully created, you will find it in:\n\n    a. **Android and IoS:** Your Flutter App's internal Storage directory (eg. `Android\\Data\\com.*.*\\appName` for Android), provided the permissions were given and the CSV was succesfully generated.\n\n    b. **Desktop Systems:** Downloads Directory.\n\n## Dependencies\n\n1. [Moor/Drift](https://drift.simonbinder.eu/) (with Tables and DataClasses ready). (Moor requires dependencies like `moor_generator` and `build_runner` for full functioning. Make sure you are familiar before using this package)\n2. [Path Provider](https://pub.dev/packages/path_provider): To provide paths to Download folder (in desktop) and App Internal Storage Directory (in Mobile platforms) which are the only places storage of files is allowed\n3. [Permission Handler](https://pub.dev/packages/permission_handler): To provide Storage read/write permission on Mobile devices. Moor itself requires it too.\n4. Also uses `dart:io` library for file handling.\n\n## Available Methods\n\n**1. DriftSQLToCSV (Class constuctor):** To create a DriftSQLToCSV object.\n\n**2. writeToCSV (Method):** To write the CSV file to the device's storage. Returns a `Future\u003cFile\u003e` object of the CSV file created.\n\n**3. permissionStatus / hasFileWritePermission (Getter):** To get the current permission status of the app to write to storage.\n\n## Potential Contribution Ideas\n\n1. Implement a way to view the generated CSVs that works across platforms. Right now I can't think of any. Tested out Open package and url_launcher with failure in one or more platforms. The only way to browse the generated CSVs is to manually browse to the storage folder.\n\n2. Better documentation.\n\n## Getting Started\n\nThis project is a starting point for a Dart\n[package](https://flutter.dev/developing-packages/),\na library module containing code that can be shared easily across\nmultiple Flutter or Dart projects.\n\nFor help getting started with Flutter, view our\n[online documentation](https://flutter.dev/docs), which offers tutorials,\nsamples, guidance on mobile development, and a full API reference.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhi13man%2Fmoor2csv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhi13man%2Fmoor2csv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhi13man%2Fmoor2csv/lists"}