pushtorefresh / storio

Reactive API for SQLiteDatabase and ContentResolver.
Apache License 2.0
2.55k stars 182 forks source link

idea/feature request: UpdateQuery + ContentValues #532

Closed Rainer-Lang closed 9 years ago

Rainer-Lang commented 9 years ago

now:

final ContentValues contentValues = new ContentValues(1);
contentValues.put(MyTable.COL_VALUE, "value");

storIOSQLite
                .internal()
                .update(UpdateQuery.builder()
                                .table(MyTable.TABLE_NAME)
                                .where(MyTable.COL_X + "=?")
                                .whereArgs("whereArg")
                                .build(),
                        contentValues);

I have many different update-statements, so I want to move them (like the query-statements) into to the table-definition class.

What I want or better what will be helpful: I want to have the whole "update"-statement part (UpdateQuery AND ContentValues") encapsulate in the table-definition class. My aim is to move all sql-queries to separate files/classes, so my code will be clean and more robust.

artem-zinnatullin commented 9 years ago

You can do this like this:

class UsersTable {

  @NonNull
  public static UpdateQuery createUpdateQuery(@NonNull User user) {
    return UpdateQuery.builder()
      .table(TABLE_NAME)
      .where(COLUMN_ID + "=?")
      .whereArgs(user.id())
      .build();
  }
}

class User {
  @NonNull
  public ContentValues toContentValues() {
    ContentValue cv = new ContentValues();
    // fill values
    return cv;
}

And then use this methods where required :)

I don't think that we will do this for you in StorIO because it's pretty hard to satisfy requirements of all users of these feature, so we will leave it up to the user code :)

artem-zinnatullin commented 9 years ago

I'm closing it, feel free to comment!