yahoo / squidb

SquiDB is a SQLite database library for Android and iOS
https://github.com/yahoo/squidb/wiki
Apache License 2.0
1.31k stars 132 forks source link

Primary key enhancements #192

Closed sbosley closed 8 years ago

sbosley commented 8 years ago

This PR enhances our support for primary keys. It adds a lot of new features and configurability options to table models with regards to how we handle rowid bookkeeping and primary keys. For backwards compatibility reasons, a few known limitations remain, but these can be removed in the next major version of SquiDB.

These changes were inspired by the discussion in issue #188.


Background

Up until now, SquiDB has always generated an ID property by default for every table model. This property is declared as an INTEGER PRIMARY KEY, which in other words makes it an alias for the SQLite rowid column that all tables have (see this SQLite doc). This PR is a step towards decoupling the idea of rowid (which we need for SquiDB bookkeeping) from the idea of primary key.

Changes

@TableModelSpec(...)
class MyModel {
    // This replaces the legacy ID property that was generated by default 
    // with one that is semantically identical
    @PrimaryKey
    @ColumnSpec(name = "_id")
    long id;
}
jdkoren commented 8 years ago

LGTM