房间数据库 - 插入后如何 return 整行?

Room Database - How to return entire row after insert?

我有插入一行的查询

@Dao
public interface NoteDao {
    @Insert
    Long insert(Note note);

}

我正在使用 RxJava 在后台线程上执行查询:

 public void insert(Note note) {
        Single.fromCallable(() -> noteDao.insert(note))
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SingleObserver<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onSuccess(@NonNull Long aLong) {
                        Log.d(TAG, "onSuccess: New row Id: " + aLong);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }
                });

    }

目前已成功 returns,为插入的 DAO 新创建的主键。我如何 return 整个插入的行,而不使用新的行 ID 执行第二个查询?

在 postgresql 中我会做这样的事情:

`INSERT INTO note_table(note_title, note_description) VALUES (, ) RETURNING *`

不确定如何使用 Room 库

Transcation 的文档所述,如果您想一次执行两个查询,则必须使用事务,据我所知,对于标准数据库操作没有其他选择

检查下面我们正在做的事情你应该做类似的事情

 @Dao
 public interface NoteDao {
    @Insert
    Long insert(Note note);

    @@Query(“SELECT * FROM Note WHERE noteId = :id)
    Long getNote(id Long);

    @Transaction
    public void insertAndRetrieve(Note note):Note {
         // Anything inside this method runs in a single transaction.

         val id =  insert(note);
        return getNote(id);
     }
 }