Sugar ORM |
您所在的位置:网站首页 › sugarapp官网 › Sugar ORM |
1. Download
Gradle: compile 'com.github.satyan:sugar:1.3' 2. Configuration.It requires minimal configuration. All you need to do is, specify SugarApp as your application class in AndroidManifest.xml. You do that by changing the android:name attribute of the application tag. AndroidManifest.xml . . . .The meta-data tags are all optional and serve the following purpose: Metadata Description DATABASE Name of the generated sqlite database file. eg: app_name.db VERSION Version of your database schema. QUERY_LOG Logs the generated Select queries. DOMAIN_PACKAGE_NAME Specify a package name where your domain/entity classes are present. This helps in smoother table creation. 3. EntitiesExtend SugarRecord for all the classes that you need persisted. That's it. Sugar takes care of table creation for you. Note: Please retain the default constructor. public class Book extends SugarRecord { String title; String edition; public Book(){ } public Book(String title, String edition){ this.title = title; this.edition = edition; } } 4. Basic UsagePerforming CRUD operations are very simple. Functions like save(), delete() and findById(..) are provided to make the work easy. Note: Record indexes start at index 1. Save Entity: Book book = new Book(ctx, "Title here", "2nd edition") book.save(); Load Entity: Book book = Book.findById(Book.class, 1); Update Entity: Book book = Book.findById(Book.class, 1); book.title = "updated title here"; // modify the values book.edition = "3rd edition"; book.save(); // updates the previous entry with new values. Delete Entity: Book book = Book.findById(Book.class, 1); book.delete(); Bulk Operations: List books = Book.listAll(Book.class); Book.deleteAll(Book.class); |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |