我正在迁移我的Room数据库。我要添加新表。因此,我创建了Entry类,如下所示:
@Entity(foreignKeys = {@ForeignKey(entity = Project.class,
parentColumns = "projectId",
childColumns = "projectId",
onDelete = ForeignKey.CASCADE)},
indices = {
@Index(name = "projectId_index", value = {"projectId"})
})
public class ProjectDimension {
@PrimaryKey(autoGenerate = true)
private long dimensionId;
@ColumnInfo
private long projectId;
@ColumnInfo
private String name;
@ColumnInfo
private String value;
// getters and setters here...
}
Run Code Online (Sandbox Code Playgroud)
然后我的道看起来像这样:
@Dao
public interface ProjectDimensionDao {
@Query("SELECT * FROM ProjectDimension")
Single<List<ProjectDimension>> getAll();
@Query("SELECT * FROM ProjectDimension WHERE projectId = :projectId")
Single<List<ProjectDimension>> getByProject(long projectId);
@Insert(onConflict = OnConflictStrategy.REPLACE)
long …Run Code Online (Sandbox Code Playgroud)