sqlite-analyzer

Additional

Language
Java
Version
0.3.2 (Jul 14, 2015)
Created
Jan 17, 2014
Updated
Feb 11, 2022 (Retired)
Owner
Novoda (novoda)
Contributors
Tobias Preuss (johnjohndoe)
Daniele Bonaldo (danybony)
Paul Blundell (blundell)
Friedger (friedger)
Adam Brown (ouchadam)
Ryan Feline (Mecharyry)
Volker Leck (devisnik)
Stefan Hoth (stefanhoth)
Xavi Rigau (xrigau)
Said Tahsin Dane (tasomaniac)
Francesco Pontillo (frapontillo)
Andrei Catinean (Electryc)
Daniele Conti (fourlastor)
Juanky Soriano (juankysoriano)
Rui Teixeira (takecare)
15
Activity
Badge
Generate
Download
Source code

🛑 THIS REPOSITORY IS OFFICIALLY NO LONGER UNDER MAINTENANCE since 10/02/2022 🛑

sqlite-analyzer

Code generation for Java/Android database access.

Description

Generates java/android database access code by analysing sqlite migration files or sqlite databases, keeping full control of what code is generated.

sqlite-analyzer creates an in-memory sqlite database, either from a given database file or by reading sql migrations, and analyzes its tables to construct a DatabaseModel. This model is then used to generate database access code.

This project uses sqlite-jdbc to create and analyze the database. Groovy is used to generate code, Gradle to hook the functionality into the android build system.

Adding to your project

To integrate sqlite-analyzer into your project, add the following at the beginning of the build.gradle of your project:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.novoda:sqlite-analyzer:0.3.2'
    }
}

To use the library with sqlite-provider, add these lines to the build.gradle of your project:

apply plugin: 'com.novoda.sqlite-analyzer'

sqliteAccess {
    migrationsDir 'src/main/assets/migrations'
    packageName 'com.novoda.sqliteprovider.demo.simple'
}

See the sample projects for setup with android-sqlite-asset-helper.

Simple usage

Try ./gradlew clean assembleDebug and observe the generated code under build/generated/source/sqlite/debug/.

By default, it contains one single class DB that defines constants for the names of the tables and columns and introduces static accessor methods as well as model classes for all tables data.

The project comes with 2 demo applications that create and use database access code, one uses sqlite-provider, the other uses android-sqlite-asset-helper.

Use column names

queryBuilder.appendWhere(DB.Columns.Shop.Name + " like 'A%'")

Simplified use with static import

projection = new String[] {Employees.Firstname, Employees.Lastname};

Use model classes

public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
    DB.Shop shop = DB.Shop.fromCursor(cursor);
}

Use helpers for ContentValues

ContentValues values = new ContentValues(1);
DB.Shop.setName("New Shop", values);

Links

Here are a list of useful links:

  • We always welcome people to contribute new features or bug fixes, here is how
  • If you have a problem check the Issues Page first to see if we are working on it
  • For further usage or to delve more deeply checkout the Project Wiki
  • Looking for community help, browse the already asked Stack Overflow Questions or use the tag: support-sqlite-analyzer when posting a new question