Common tasks snippets
- Create database
- Open database
- Close database
- Destroy database
- Insert primitive types
- Read primitive types
- Insert Serializable
- Read Serializable
- Insert Array
- Read Array
- Check key
- Delete key
DB snappydb = DBFactory.open(context);
DB snappydb = DBFactory.open(context, "books");
SnappyDB use the internal storage to create your database. It create a directory containing all the necessary files Ex:
/data/data/com.snappydb/files/mydatabse
DB snappydb = DBFactory.open(context);
DB snappydb = DBFactory.open(context, "books");
snappydb.close();
snappydb.destroy();
snappyDB.put("quote", "bazinga!");
snappyDB.putShort("myshort", (short)32768);
snappyDB.putInt("max_int", Integer.MAX_VALUE);
snappyDB.putLong("max_long", Long.MAX_VALUE);
snappyDB.putDouble("max_double", Double.MAX_VALUE);
snappyDB.putFloat("myfloat", 10.30f);
snappyDB.putBoolean("myboolean", true);
String quote = snappyDB.get("quote");
short myshort = snappyDB.getShort("myshort");
int maxInt = snappyDB.getInt("max_int");
long maxLong = snappyDB.getLong("max_long");
double maxDouble = snappyDB.getDouble("max_double");
float myFloat = snappyDB.getFloat("myfloat");
boolean myBoolean = snappyDB.getBoolean("myboolean");
AtomicInteger objAtomicInt = new AtomicInteger (42);
snappyDB.put("atomic integer", objAtomicInt);
AtomicInteger myObject = snappyDB.get("atomic integer", AtomicInteger.class);
Number[] array = {new AtomicInteger (42), new BigDecimal("10E8"), Double.valueOf(Math.PI)};
snappyDB.put("array", array);
Number [] numbers = snappyDB.getArray("array", Number.class);
boolean isKeyExists = snappyDB.exists("key");
snappyDB.del("key");