{"id":13670577,"url":"https://github.com/pinchbv/floor","last_synced_at":"2026-02-24T14:37:16.294Z","repository":{"id":37205329,"uuid":"166677704","full_name":"pinchbv/floor","owner":"pinchbv","description":"The typesafe, reactive, and lightweight SQLite abstraction for your Flutter applications","archived":false,"fork":false,"pushed_at":"2024-08-16T07:32:11.000Z","size":1961,"stargazers_count":1028,"open_issues_count":150,"forks_count":215,"subscribers_count":15,"default_branch":"develop","last_synced_at":"2026-02-16T07:19:09.388Z","etag":null,"topics":["dart","flutter","sqlite"],"latest_commit_sha":null,"homepage":"https://pinchbv.github.io/floor/","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pinchbv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-20T15:37:10.000Z","updated_at":"2026-02-08T21:32:52.000Z","dependencies_parsed_at":"2024-05-21T14:55:37.298Z","dependency_job_id":"2ce06484-c934-4ab6-82e3-73c1cf04a0e8","html_url":"https://github.com/pinchbv/floor","commit_stats":null,"previous_names":["vitusortner/floor"],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/pinchbv/floor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinchbv%2Ffloor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinchbv%2Ffloor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinchbv%2Ffloor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinchbv%2Ffloor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pinchbv","download_url":"https://codeload.github.com/pinchbv/floor/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pinchbv%2Ffloor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29601695,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T02:50:40.506Z","status":"ssl_error","status_checked_at":"2026-02-19T02:50:26.316Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","flutter","sqlite"],"created_at":"2024-08-02T09:00:45.657Z","updated_at":"2026-02-24T14:37:16.278Z","avatar_url":"https://github.com/pinchbv.png","language":"Dart","readme":"![Floor](https://raw.githubusercontent.com/pinchbv/floor/develop/img/floor.png)\n\n**See the [project's website](https://pinchbv.github.io/floor/) for the full documentation.**\n\nFloor provides a neat SQLite abstraction for your Flutter applications inspired by the [Room persistence library](https://developer.android.com/topic/libraries/architecture/room).\nIt comes with automatic mapping between in-memory objects and database rows while still offering full control of the database with the use of SQL.\nAs a consequence, it's necessary to have an understanding of SQL and SQLite in order to harvest Floor's full potential.\n\n- null-safe\n- typesafe\n- reactive\n- lightweight\n- SQL centric\n- no hidden magic\n- no hidden costs\n- iOS, Android, Linux, macOS, Windows\n\n⚠️ The library is open to contributions!\nRefer to [GitHub Discussions](https://github.com/pinchbv/floor/discussions) for questions, ideas, and discussions.\n\n[![pub package](https://img.shields.io/pub/v/floor.svg)](https://pub.dartlang.org/packages/floor)\n[![build status](https://github.com/pinchbv/floor/workflows/CI/badge.svg)](https://github.com/pinchbv/floor/actions)\n[![codecov](https://codecov.io/gh/pinchbv/floor/branch/develop/graph/badge.svg)](https://codecov.io/gh/pinchbv/floor)\n\n## Getting Started\n\n### 1. Setup Dependencies\n\nAdd the runtime dependency `floor` as well as the generator `floor_generator` to your `pubspec.yaml`.\nThe third dependency is `build_runner` which has to be included as a dev dependency just like the generator.\n\n- `floor` holds all the code you are going to use in your application.\n- `floor_generator` includes the code for generating the database classes.\n- `build_runner` enables a concrete way of generating source code files.\n\n```yaml\ndependencies:\n  flutter:\n    sdk: flutter\n  floor: ^1.4.2\n\ndev_dependencies:\n  floor_generator: ^1.4.2\n  build_runner: ^2.1.2\n```\n\n### 2. Create an Entity\n\nIt will represent a database table as well as the scaffold of your business object.\n`@entity` marks the class as a persistent class.\nIt's required to add a primary key to your table.\nYou can do so by adding the `@primaryKey` annotation to an `int` property.\nThere is no restriction on where you put the file containing the entity.\n\n```dart\n// entity/person.dart\n\nimport 'package:floor/floor.dart';\n\n@entity\nclass Person {\n  @primaryKey\n  final int id;\n\n  final String name;\n\n  Person(this.id, this.name);\n}\n```\n\n### 3. Create a DAO (Data Access Object)\n\nThis component is responsible for managing access to the underlying SQLite database.\nThe abstract class contains the method signatures for querying the database which have to return a `Future` or `Stream`.\n\n- You can define queries by adding the `@Query` annotation to a method.\n  The SQL statement has to get added in parenthesis.\n  The method must return a `Future` or `Stream` of the `Entity` you're querying for.\n- `@insert` marks a method as an insertion method.\n\n```dart\n// dao/person_dao.dart\n\nimport 'package:floor/floor.dart';\n\n@dao\nabstract class PersonDao {\n  @Query('SELECT * FROM Person')\n  Future\u003cList\u003cPerson\u003e\u003e findAllPeople();\n\n  @Query('SELECT name FROM Person')\n  Stream\u003cList\u003cString\u003e\u003e findAllPeopleName();\n\n  @Query('SELECT * FROM Person WHERE id = :id')\n  Stream\u003cPerson?\u003e findPersonById(int id);\n\n  @insert\n  Future\u003cvoid\u003e insertPerson(Person person);\n}\n```\n\n### 4. Create the Database\n\nIt has to be an abstract class which extends `FloorDatabase`.\nFurthermore, it's required to add `@Database()` to the signature of the class.\nMake sure to add the created entity to the `entities` attribute of the `@Database` annotation.\nIn order to make the generated code work, it's required to also add the listed imports.\n\nMake sure to add `part 'database.g.dart';` beneath the imports of this file.\nIt's important to note that 'database' has to get exchanged with the filename of the database definition.\nIn this case, the file is named `database.dart`.\n\n```dart\n// database.dart\n\n// required package imports\nimport 'dart:async';\nimport 'package:floor/floor.dart';\nimport 'package:sqflite/sqflite.dart' as sqflite;\n\nimport 'dao/person_dao.dart';\nimport 'entity/person.dart';\n\npart 'database.g.dart'; // the generated code will be there\n\n@Database(version: 1, entities: [Person])\nabstract class AppDatabase extends FloorDatabase {\n  PersonDao get personDao;\n}\n```\n\n### 5. Run the Code Generator\n\nRun the generator with `flutter packages pub run build_runner build`.\nTo automatically run it, whenever a file changes, use `flutter packages pub run build_runner watch`.\n\n### 6. Use the Generated Code\n\nFor obtaining an instance of the database, use the generated `$FloorAppDatabase` class, which allows access to a database builder.\nThe name is being composed by `$Floor` and the database class name.\nThe string passed to `databaseBuilder()` will be the database file name.\nFor initializing the database, call `build()` and make sure to `await` the result.\n\nIn order to retrieve the `PersonDao` instance, invoking the `persoDao` getter on the database instance is enough.\nIts functions can be used as shown in the following snippet.\n\n```dart\nfinal database = await $FloorAppDatabase.databaseBuilder('app_database.db').build();\n\nfinal personDao = database.personDao;\nfinal person = Person(1, 'Frank');\n\nawait personDao.insertPerson(person);\nfinal result = await personDao.findPersonById(1);\n```\n\nFor further examples take a look at the [example](https://github.com/pinchbv/floor/tree/develop/example) and [test](https://github.com/pinchbv/floor/tree/develop/floor/test/integration) directories.\n\n## Naming\nThe library's name derives from the following.\n*Floor* as the *bottom layer* of a [Room](https://developer.android.com/topic/libraries/architecture/room) which points to the analogy of the database layer being the bottom and foundation layer of most applications.\nWhere *fl* also gives a pointer that the library is used in the Flutter context.\n\n## Bugs, Ideas, and Feedback\nFor bugs please use [GitHub Issues](https://github.com/pinchbv/floor/issues).\nFor questions, ideas, and discussions use [GitHub Discussions](https://github.com/pinchbv/floor/discussions).\n\n## License\n    Copyright 2023 The Floor Project Authors\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":[],"categories":["Dart","sqlite","DB\u0026ORM库"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinchbv%2Ffloor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpinchbv%2Ffloor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpinchbv%2Ffloor/lists"}