雅虎開源用于 Android 的 SQLite 數據庫框架:SquiDB
SquiDB是一個用于Android的SQLite數據庫層。它的目的是讓盡可能容易地使用SQLite數據庫,同時還能利用原生SQL的強大和靈活性。SquiDB采用面向對象的方式來構建SQL語句,使其易于閱讀和沒有一堆凌亂的SQL字符串。
// This is a table schema
@TableModelSpec(className = "Person", tableName = "people")
public class PersonSpec {
// A text column named "firstName"
public String firstName;
// A text column named "lastName"
public String lastName;
// A long column named "creationDate", but referred to as "birthday"
// when working with the model
@ColumnSpec(name = "creationDate")
public long birthday;
}
// This is how you'd set up a database instance
public class MyDatabase extends AbstractDatabase {
private static final int VERSION = 1;
public MyDatabase(Context context) {
super(context);
}
@Override
protected String getName() {
return "my-database.db";
}
@Override
protected Table[] getTables() {
return new Table[]{
// List all tables here
Person.TABLE,
};
}
@Override
protected int getVersion() {
return VERSION;
}
// Other overridable methods exist for migrations and initialization;
// omitted for brevity
}
DatabaseDao dao = new DatabaseDao(new MyDatabase(context));
// This is how you'd work with the generated model
Person newPerson = new Person()
.setFirstName("Sam")
.setLastName("Bosley")
.setBirthday(System.currentTimeMillis());
dao.persist(newPerson);
...
String firstName = newPerson.getFirstName();
String lastName = newPerson.getLastName();
long birthday = newPerson.getBirthday(); 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!