{"id":13395734,"url":"https://github.com/ustims/DartORM","last_synced_at":"2025-03-13T22:30:48.936Z","repository":{"id":24462462,"uuid":"27865637","full_name":"ustims/DartORM","owner":"ustims","description":"Database ORM for dart language","archived":false,"fork":false,"pushed_at":"2018-07-07T21:14:45.000Z","size":161,"stargazers_count":54,"open_issues_count":2,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-11T10:59:40.857Z","etag":null,"topics":["dart","database","database-orm","orm"],"latest_commit_sha":null,"homepage":"https://pub.dartlang.org/packages/dart_orm","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ustims.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":"2014-12-11T10:18:57.000Z","updated_at":"2024-12-18T22:06:19.000Z","dependencies_parsed_at":"2022-07-27T04:46:24.320Z","dependency_job_id":null,"html_url":"https://github.com/ustims/DartORM","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/ustims%2FDartORM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustims%2FDartORM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustims%2FDartORM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ustims%2FDartORM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ustims","download_url":"https://codeload.github.com/ustims/DartORM/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243493179,"owners_count":20299607,"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","database","database-orm","orm"],"created_at":"2024-07-30T18:00:29.818Z","updated_at":"2025-03-13T22:30:48.611Z","avatar_url":"https://github.com/ustims.png","language":"Dart","readme":"[![Build Status](https://travis-ci.org/ustims/DartORM.svg?branch=master)](https://travis-ci.org/ustims/DartORM)\n[![Coverage Status](https://coveralls.io/repos/ustims/DartORM/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/ustims/DartORM?branch=master)\n[![Gitter](https://badges.gitter.im/ustims/DartORM.svg)](https://gitter.im/ustims/DartORM?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n\nDart ORM\n========\n\nEasy-to-use and easy-to-setup database ORM for dart.\n\nIt is in the very beginning stage of development and not ready for production use.\n\nAny feedback is greatly appreciated.\n\nFeel free to contribute!\n\nFeatures\n========\n\nAnnotations\n-----------\n\nAnnotations could be used in-place:\n\n```dart\nimport 'package:dart_orm/orm.dart' as ORM;\n\n@ORM.DBTable('users')\nclass User extends ORM.Model {\n  // Every field that needs to be stored in database should be annotated with @DBField\n  @ORM.DBField()\n  @ORM.DBFieldPrimaryKey()\n  int id;\n\n  @ORM.DBField()\n  String givenName;\n\n  // column name can be overridden\n  @ORM.DBField('family_name')\n  String familyName;\n}\n```\n\nOr one can provide a target class for DBTable annotation. \nIn such way one can store third-party classes in database without changing the original class definition.\n\n```dart\n\n// somelibrary.dart\nclass User {\n  int id;\n  String name;\n}\n\n// your code\nimport 'somelibrary.dart' as lib;\n\n@ORM.Table('users', lib.User)\nclass DBUser {\n  @ORM.DBField()\n  int id;\n  \n  @ORM.DBField()\n  String name;\n}\n\n// now User instances could be used like this:\nlib.User u = new lib.User();\nu.name = 'Name';\nawait ORM.insert(u);\n\n// Note that DBUser is used only for annotation purposes and should not be used directly.\n```\n\nTypes support\n-------------\n\nAny simple Dart type could be used: int/double/String/bool/DateTime.\n\nLists are supported and could be used as any other type just by annotating a property:\n\n```dart\n@ORM.DBTable('users')\nclass User {\n  @ORM.DBField()\n  List\u003cString\u003e emails;\n}\n```\n\nReferences to other tables are not supported, but are in progress. Stay tuned!\n\nInserts and updates\n-------------------\n\nEvery ORM.Model has .save() method which will update/insert a new row.\n\nIf class instance has 'id' field with not-null value,\n.save() will execute 'UPDATE' statement with 'WHERE id = $id'.\n\nIf class instance has null 'id' field, 'INSERT' statement will be executed.\n\n```dart\nUser u = new User();\nu.givenName = 'Sergey';\nu.familyName = 'Ustimenko';\n\nvar saveResult = await u.save();\n```\n\nThis statement will be executed on save():\n\n```sql\nINSERT INTO users (\n    given_name,\n    family_name)\nVALUES (\n    'Sergey',\n    'Ustimenko'\n);\n```\n\nQueries\n-------\n\nORM has two classes for finding records: Find and FindOne.\n\nConstructors receive a class that extend ORM.Model.\n\n```dart\n\nORM.Find f = new ORM.Find(User)\n  ..where(new ORM.LowerThan('id', 3)\n    .and(new ORM.Equals('givenName', 'Sergey')\n      .or(new ORM.Equals('familyName', 'Ustimenko'))\n    )\n  )\n  ..orderBy('id', 'DESC')\n  ..setLimit(10);\n\nList foundUsers = await f.execute();\n\nfor(User u in foundUsers){\n  print('Found user:');\n  print(u);\n}\n```\n\nThis will result such statement executed on the database:\n\n```sql\nSELECT *\nFROM users\nWHERE id \u003c 3 AND (given_name = 'Sergey' OR family_name = 'Ustimenko')\nORDER BY id DESC LIMIT 10\n```\n\nMultiple database adapters support\n----------------------------------\n\nServer-side adapters:\n\nhttps://github.com/ustims/DartORM-PostgreSQL\n\nhttps://github.com/ustims/DartORM-MySQL\n\nhttps://github.com/ustims/DartORM-MongoDB\n\nTo use an adapter install it with pub and do this:\n\n```dart\nimport 'package:dart_orm_adapter_postgresql/dart_orm_adapter_postgresql.dart';\nimport 'package:dart_orm/dart_orm.dart' as orm;\n\nmain() {\n  orm.AnnotationsParser.initialize();\n\n  String connectionString =\n      'postgres://\u003cusername\u003e:\u003cpassword\u003e@localhost:5432/\u003cdbname\u003e';\n      \n  orm.DBAdapter postgresAdapter = new PostgresqlDBAdapter(connectionString);\n  await postgresAdapter.connect();\n  \n  orm.addAdapter('postgres', postgresAdapter);\n  orm.setDefaultAdapter('postgres');\n  \n  await orm.Migrator.migrate();\n}\n```      \n\n\nDartORM could also be used on client side with indexedDB:\n\nhttps://github.com/ustims/DartORM-IndexedDB\n\nRoadmap\n=======\n\n- model relations (in progress)\n- migration system\n","funding_links":[],"categories":["Libraries"],"sub_categories":["ORM"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fustims%2FDartORM","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fustims%2FDartORM","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fustims%2FDartORM/lists"}