{"id":13756669,"url":"https://github.com/chennaione/sugar","last_synced_at":"2025-05-15T03:04:29.341Z","repository":{"id":43117559,"uuid":"2197202","full_name":"chennaione/sugar","owner":"chennaione","description":"Insanely easy way to work with Android Database.  ","archived":false,"fork":false,"pushed_at":"2021-09-02T12:51:46.000Z","size":9679,"stargazers_count":2619,"open_issues_count":302,"forks_count":578,"subscribers_count":102,"default_branch":"master","last_synced_at":"2025-04-14T00:59:56.777Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://satyan.github.com/sugar/","language":"Java","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/chennaione.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":"2011-08-12T13:44:41.000Z","updated_at":"2025-03-03T08:27:38.000Z","dependencies_parsed_at":"2022-09-07T05:30:27.038Z","dependency_job_id":null,"html_url":"https://github.com/chennaione/sugar","commit_stats":null,"previous_names":["satyan/sugar"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chennaione%2Fsugar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chennaione%2Fsugar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chennaione%2Fsugar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chennaione%2Fsugar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chennaione","download_url":"https://codeload.github.com/chennaione/sugar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248804790,"owners_count":21164132,"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":[],"created_at":"2024-08-03T11:00:50.876Z","updated_at":"2025-04-14T01:00:08.237Z","avatar_url":"https://github.com/chennaione.png","language":"Java","funding_links":[],"categories":["Libraries","数据库开发","etc"],"sub_categories":["ORM"],"readme":"# Sugar ORM [![Build Status](https://travis-ci.org/satyan/sugar.svg?branch=master)](https://travis-ci.org/satyan/sugar) [![Coverage Status](https://coveralls.io/repos/satyan/sugar/badge.svg?branch=master)](https://coveralls.io/r/satyan/sugar?branch=master) [![Code Triagers Badge](http://www.codetriage.com/satyan/sugar/badges/users.svg)](http://www.codetriage.com/satyan/sugar)\n\n[![Join the chat at https://gitter.im/satyan/sugar](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/satyan/sugar?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nInsanely easy way to work with Android databases.\n\nOfficial documentation can be found [here](http://satyan.github.io/sugar) - Check some examples below. The example application is provided in the **example** folder in the source.\n\n## Looking for contributors\nWe need contributors to help maintain this project, ask @satyan for repo permission\n\nOtherwise you can use another ORM, like https://github.com/requery/requery or https://realm.io/\n\n## Features\n\nSugar ORM was built in contrast to other ORM's to have:\n\n- A simple, concise, and clean integration process with minimal configuration.\n- Automatic table and column naming through reflection.\n- Support for migrations between different schema versions.\n\n## Installing\n\nThere are four ways to install Sugar:\n\n#### As a Gradle dependency\n\nThis is the preferred way. Simply add:\n\n```groovy\ncompile 'com.github.satyan:sugar:1.5'\n```\n\nto your project dependencies and run `gradle build` or `gradle assemble`.\n\n#### As a Maven dependency\n\nDeclare the dependency in Maven:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.satyan\u003c/groupId\u003e\n    \u003cartifactId\u003esugar\u003c/artifactId\u003e\n    \u003cversion\u003e1.5\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n#### As a library project\n\nDownload the source code and import it as a library project in Eclipse. The project is available in the folder **library**. For more information on how to do this, read [here](http://developer.android.com/tools/projects/index.html#LibraryProjects).\n\n#### As a jar\n\nVisit the [releases](https://github.com/satyan/sugar/releases) page to download jars directly. You can drop them into your `libs` folder and configure the Java build path to include the library. See this [tutorial](http://www.vogella.com/tutorials/AndroidLibraryProjects/article.html) for an excellent guide on how to do this.\n\n\n### How to use master version\nFirst, download sugar repository\n```\ngit clone git@github.com:satyan/sugar.git\n```\n\ninclude this in your **settings.gradle**\n```gradle\ninclude ':app' // your module app\ninclude ':sugar'\n\ndef getLocalProperty(prop) {\n\tProperties properties = new Properties()\n\tproperties.load(new File(rootDir.absolutePath + '/local.properties').newDataInputStream())\n\treturn properties.getProperty(prop, '')\n}\n\nproject(':sugar').projectDir = new File(getLocalProperty('sugar.dir'))\n\n```\n\ninclude this in your **local.properties**\n```\nsugar.dir=/path/to/sugar/library\n```\n\nadd sugar project to the dependencies of your main project (build.gradle)\n```gradle\ndependencies {\n    compile project(':sugar')\n}\n```\n\nYou should also comment this line just comment this line (library/build.gradle): https://github.com/satyan/sugar/blob/master/library%2Fbuild.gradle#L2\n\n```gradle\n// apply from: '../maven_push.gradle'\n```\n===================\n\nAfter installing, check out how to set up your first database and models [here](http://satyan.github.io/sugar/getting-started.html) **Outdated**. Check examples of 1.4 and master below: \n\n## Examples\n### SugarRecord\n```java\npublic class Book extends SugarRecord {\n  @Unique\n  String isbn;\n  String title;\n  String edition;\n\n  // Default constructor is necessary for SugarRecord\n  public Book() {\n\n  }\n\n  public Book(String isbn, String title, String edition) {\n    this.isbn = isbn;\n    this.title = title;\n    this.edition = edition;\n  }\n}\n```\nor\n```java\n@Table\npublic class Book { ... }\n```\n\n### Save Entity\n```java\nBook book = new Book(\"isbn123\", \"Title here\", \"2nd edition\")\nbook.save();\n```\n\nor\n```java\nSugarRecord.save(book); // if using the @Table annotation \n```\n\n### Load Entity\n```java\nBook book = Book.findById(Book.class, 1);\n```\n\n### Update Entity\n```java\nBook book = Book.findById(Book.class, 1);\nbook.title = \"updated title here\"; // modify the values\nbook.edition = \"3rd edition\";\nbook.save(); // updates the previous entry with new values.\n```\n\n\n### Delete Entity\n```java\nBook book = Book.findById(Book.class, 1);\nbook.delete();\n```\n\nor\n```java\nSugarRecord.delete(book); // if using the @Table annotation \n```\n\n### Update Entity based on Unique values\n```java\nBook book = new Book(\"isbn123\", \"Title here\", \"2nd edition\")\nbook.save();\n\n// Update book with isbn123\nBook sameBook = new Book(\"isbn123\", \"New Title\", \"5th edition\")\nsameBook.update();\n\nbook.getId() == sameBook.getId(); // true\n```\n\nor\n```java\nSugarRecord.update(sameBook); // if using the @Table annotation \n```\n\n### Bulk Insert\n```java\nList\u003cBook\u003e books = new ArrayList\u003c\u003e();\nbooks.add(new Book(\"isbn123\", \"Title here\", \"2nd edition\"))\nbooks.add(new Book(\"isbn456\", \"Title here 2\", \"3nd edition\"))\nbooks.add(new Book(\"isbn789\", \"Title here 3\", \"4nd edition\"))\nSugarRecord.saveInTx(books);\n```\n\n### When using ProGuard\n```java\n# Ensures entities remain un-obfuscated so table and columns are named correctly\n-keep class com.yourpackage.yourapp.domainclasspackage.** { *; }\n```\n\n### Known Issues. \n#### 1. Instant Run. \nInstant-Run seems to prevent Sugar ORM from finding the \"table\" classes, therefore it cannot create the DB tables if you run the app for the first time \n\nWhen running your app for the first time Turn off Instant run once to allow for the DB tables to be created\nYou can enable it after the tables have been created. \n\nTo disable Instant-Run in Android Studio: \n\n``(Preferences (Mac) or Settings (PC) -\u003e Build, Execution, Deployment -\u003e Instant Run -\u003e Untick \"Enable Instant Run...\" )``\n\n## [CHANGELOG](https://github.com/satyan/sugar/blob/master/CHANGELOG.md)\n\n## Contributing\n\nPlease fork this repository and contribute back using [pull requests](https://github.com/satyan/sugar/pulls). Features can be requested using [issues](https://github.com/satyan/sugar/issues). All code, comments, and critiques are greatly appreciated.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchennaione%2Fsugar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchennaione%2Fsugar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchennaione%2Fsugar/lists"}