Sugar introduction
-
Upload
satya-narayan -
Category
Technology
-
view
1.064 -
download
2
Transcript of Sugar introduction
Sugar simple db wrapper for
android
@snarayan for #in50hrs
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);
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();
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);
Source : github.com/satyan/sugar
Example project:Note Managerhttps://github.com/satyan/SugarExample
Team:Satya Narayan
Ranjith
Inspired By:GORM(Grails)
ActiveRecord(Rails)
Queries/Support/[email protected]
@sugarin50