Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.

handtwerk/sugar

 
 

Repository files navigation

Please note

This fork of sugar will not be developed any further, since greenDAO is a much, much better object-relational mapping framework for Android.

About

This is a fork of Satyan's Sugar, a wrapper for Android's DB interface for SQLite, fixing some problems with the original library and adding support for Enum-type fields.

Without Sugar

Table Creation

final String CREATE_TABLE_COUNTRIES =  "CREATE TABLE tbl_countries ("  + "id INTEGER PRIMARY KEY AUTOINCREMENT,"  + "country_name TEXT);";

final String CREATE_TABLE_STATES =  "CREATE TABLE tbl_states ("  + "id INTEGER PRIMARY KEY AUTOINCREMENT,"  + "state_name TEXT);";

db.execSQL(CREATE_TABLE_COUNTRIES);
db.execSQL(CREATE_TABLE_STATES);

Inserting Values

ContentValues values = new ContentValues();
values.put("country_name", "India");
db.insert("tbl_countries", null, values);

With Sugar

Table Creation

public class Country extends SugarRecord<Country> {
  
    String countryName;
    
    public Country(Context context, String countryName) {
      
        super(context);
        this.countryName = countryName;
    }
}

Inserting Values

Country country = new Country(context, "India");
country.save();

Query

Country.findById(context, Country.class, 1);
Country.find(context, Country.class, "country_name=?", new String[]{"India"});

Delete

Country country = Country.findById(context, Country.class, 1);
country.delete();

Few More

Country.listAll(context, Country.class);
Country.deleteAll(context, Country.class);

Example project: Note Manager https://github.com/satyan/SugarExample

More documentation to follow - for now please visit the Wiki section of the original Sugar project for more details.

About

Android db wrapper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%