Skip to content
Space Cowboy edited this page Sep 18, 2013 · 3 revisions

Introduction

Goals

The aim of this project is to make it easy for myself (and others) to create a database structure for Android apps. Doing it by hand once or twice is fine, but when I started working on my third app and realized that I was copy-pasting the entire database-package from my last app, I knew something needed to be done.

Hence, this project aims to generate all required files for your apps. In addition, the generated SQL is actually tested by creating an SQLite database and creating all tables, triggers etc.

The project is written in Python and generates SQL and Java code. If you are unfamiliar with Python, you can probably use one of the many samples that I provide to create your own script.

Why a Python script and not annotations in code for example?

If you want a very simple database, the various projects around the web based on annotations might be good for you. I do not believe however that they are very maintainable over time if your database schema needs to change, nor is it very easy to create triggers and other SQL-goodness.

The advantage of generating all the classes is that if you need to change the schema in the future, you can either

  • change the script, re-generate all the classes, and only add the necessary ALTER TABLE statements in the database's onUpgrade() method.
  • or you edit the schema files by hand

So I claim that the code generated by this project is maintainable and extendable. The only thing you need to do is think your Schema through!

Features

The project is still under development, so this list is subject to change. Goal is to support most of what is supported in SQLite.

Tables

  • Foreign keys
  • Constraints like Unique, Not Null
  • Default values
  • Automatic timestamps
  • Cascade actions

Triggers

  • Before or After
  • On Insert/Upgrade/Upgrade Of(cols)/Delete
  • Temporary or Permanent

Testing

  • Possible to test the DB Schema in an actual SQLite database before generating java files

####Generation Generates all files necessary in Android including:

  • DatabaseHandler
  • Convenience classes for each table for easy access
  • ContentProvider for super fast access in ListViews and other places

Samples

All classes have several doctests (code examples in comments) so have a look there if you are uncertain about specific syntax.

Creating your schema

Testing your schema

Generate the java files for your Android project

Clone this wiki locally