雅虎开源用于 Android 的 SQLite 数据库框架:SquiDB
jopen
10年前
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();