Simple ORM for Android SQLite
Use the issue tracker to report bugs or request enhancements, and StackOverflow with tag storm-gen for assistance. Join the storm-gen G+ community for project news and feature discussion.
- Download storm-api.jar from the latest release and add to your Android project's libs folder so it will be on the project's build path.
- Download storm-apt.jar from the latest release and add to your annotation factory classpath (in Eclipse, project properties | Java Compiler > Annotation Processing > Factory Path). Also check the box to enable annotation processing.
- Create a new class that extends com.turbomanage.storm.DatabaseHelper (it's in the storm-api jar).
- Add @Database and supply a database name and version example
- Override getUpgradeStrategy() to choose one of the available strategies (DROP_CREATE for new projects)
- Create a POJO class you want to persist to the database
- Make sure it has a field of type long named "id" or annotated with @Id
- Add the @Entity annotation to the class example
You'll see 3 generated classes under .apt_generated (you might need to unfilter hidden resources in your IDE to see it):
- a DbFactory class
- a Dao class
- a Table class
You can use the DAO like this:
PersonDao dao = new PersonDao(getContext());
long id = dao.insert(new Person());
Person person = dao.get(id);
For more info, see the unit tests and the resources on the project home page.