小编Gem*_*ker的帖子

带有索引的房间创建表

我正在迁移我的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)

java android android-room

5
推荐指数
1
解决办法
4056
查看次数

标签 统计

android ×1

android-room ×1

java ×1