Sugar introduction

6
Sugar simple db wrapper for android @snarayan for

Transcript of Sugar introduction

Page 1: Sugar introduction

Sugar simple db wrapper for

android

@snarayan for #in50hrs

Page 2: Sugar introduction

Current State//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);

Page 3: Sugar introduction

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();

Page 4: Sugar introduction

Extra Sugar //query

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

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

// few more..

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

Page 5: Sugar introduction

Source : github.com/satyan/sugar

Example project:Note Managerhttps://github.com/satyan/SugarExample

Page 6: Sugar introduction

Team:Satya Narayan

Ranjith

Inspired By:GORM(Grails)

ActiveRecord(Rails)

Queries/Support/[email protected]

@sugarin50