2

I'm using GRDB in Swift 4 to access two columns ('col1', 'col2') of values of type Double.

For example:

let value = Double.fetchAll(db,"SELECT col1, col2 FROM table1")

This should return a table with two columns of double values. I am wondering if there is a way to extract the results by column without iterating over it row by row? Using the above I can get an array of col1 but not both.

Kazunori Takaishi
  • 2,268
  • 1
  • 15
  • 27
J. Wadia
  • 37
  • 1

1 Answers1

3

If you need rows, then you must iterate row by row. There's no escape to basic logic.

What about something like below:

// [(Double, Double)]
let pairs = try Row
    .fetchAll(db, "SELECT ...")
    .map { row in
        (row[0] as Double,
         row[1] as Double)
    }
Gwendal Roué
  • 3,949
  • 15
  • 34