How to exclude/include some columns for query?
Closed this issue · 5 comments
How to exclude/include some columns for query?
For example, I have table with column FULL_TEXT that can contains a heavy value with detail text.
But in RecyclerView I use SHORT_TEXT value (less than 100 symbols)
How I can exclude FULL_TEXT column value from query using Orma relation builder?
If multiple columns pluck are supported in Orma?
Person.pluck(:id)
SELECT people.id FROM people
=> [1, 2, 3]
Person.pluck(:id, :name)
SELECT people.id, people.name FROM people
=> [[1, 'David'], [2, 'Jeremy'], [3, 'Jose']]
Currently, there's no convenience method for it. You have to use a low-level Selector#executeWithColumns(): Cursor
.
However, your idea seems reasonable and I'll add a convenience way to do so.
Considering for a while, I have concluded that it is difficult in type-safe way.
I think using #executeWithColumns()
is the best way to select specific columns.
Yes, best way in current version of Orma is use Selector#executeWithColumns().
My solution is based on your answer:
Cursor cursor = getUserFolders()
.isInTrashEq(false)
.parentIdEq(parentId)
.orderBy(sortType)
.selector()
.executeWithColumns(
FolderObj_Schema.INSTANCE.globalId.name,
FolderObj_Schema.INSTANCE.parentId.name,
FolderObj_Schema.INSTANCE.title.name,
FolderObj_Schema.INSTANCE.dateAdded.name);
List<FolderObj> childFolders = getFolderObjListFromCursor(cursor); //manual get values by cursor index in loop
Thanks! Issue resolved
👍