Skip to content

Commit

Permalink
For readability use column names, not column numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
julianladisch committed Jan 8, 2025
1 parent 9b80f9e commit 759bb30
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/main/java/org/folio/persist/HoldingsRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public HoldingsRepository(Context context, Map<String, String> okapiHeaders) {
}

/**
* Row where the first value is an array with all holdings records; the second value is
* the exact totalRecords count.
* Produce a single row where the {@code holdings} column is a text field
* containing a JSON array with all holdings records; the
* {@code total_records} column is the exact totalRecords count.
*/
public Future<Row> getByInstanceId(String instanceId, String[] sortBys, int offset, int limit) {
var orderBy = new StringBuilder();
Expand Down Expand Up @@ -59,8 +60,8 @@ public Future<Row> getByInstanceId(String instanceId, String[] sortBys, int offs
+ " ORDER BY " + orderBy
+ " OFFSET $2"
+ " LIMIT $3"
+ " )::text, ("
+ " SELECT COUNT(*)"
+ " )::text AS holdings, ("
+ " SELECT COUNT(*) AS total_records"
+ " FROM " + HOLDINGS_RECORD_TABLE
+ " WHERE instanceId=$1"
+ ")";
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/folio/services/holding/HoldingsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ public Future<Response> getByInstanceId(int offset, int limit, String query) {
var sortBy = matcher.group(2).split(" +");
return holdingsRepository.getByInstanceId(instanceId, sortBy, offset, limit)
.map(row -> {
var json = "{ \"holdingsRecords\": " + row.getString(0) + ",\n"
+ " \"totalRecords\": " + row.getLong(1) + ",\n"
var json = "{ \"holdingsRecords\": " + row.getString("holdings") + ",\n"
+ " \"totalRecords\": " + row.getLong("total_records") + ",\n"
+ " \"resultInfo\": { \n"
+ " \"totalRecords\": " + row.getLong(1) + ",\n"
+ " \"totalRecords\": " + row.getLong("total_records") + ",\n"
+ " \"totalRecordsEstimated\": false\n"
+ " }\n"
+ "}";
Expand Down

0 comments on commit 759bb30

Please sign in to comment.