Return types of search
I'm calling
xata.search.all
on my backend, and I'm trying to figure out what types that I should use to represent the record result. I'm currently searching two tables.
Doing RouterOutput['search']['records'][0]
gives me one of the two possible types I think? RouterOutput is the return type of the function using TRPC.1 Reply
Hi, with
xata.search.all
which searches across multiple tables, search results can originate from any table (or subset of tables, if a tables array is specified). So the type of each record can be any of the target table types.
The "table" field included in each result in the search response (response.records[0].table) specifies the table name from which the result originated. The actual result is nested within response.records[0].record
.
Alternatively, there is the xata.db.tablename.search
method which searches a specific table so a single return type is expected https://xata.io/docs/sdk/search#search-a-single-table-only