1

I'm going through a tutorial below

https://developer.apple.com/library/iad/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/UsingtheJavascriptDatabase/UsingtheJavascriptDatabase.html

and am having trouble converting js to cljs in the dataHandler function

function dataHandler(transaction, results)
{
// Handle the results
var string = "Green shirt list contains the following people:\n\n";
for (var i=0; i<results.rows.length; i++) {
    // Each row is a standard JavaScript array indexed by
    // column names.
    var row = results.rows.item(i);
    string = string + row['name'] + " (ID "+row['id']+")\n";
}
alert(string);
}

Here is my cljs code

 (defn success-handler [tx, results]
   (println "success handler")
   (println results)

   ;;the below doesn't work, I get an error here  
   ;;:Uncaught Error: [object SQLResultSet] is not ISeqable

  (doseq [result results]
  (prn result)))

So my question is how would I convert the js dataHandler to my cljs success-handler?

2 Answers2

2

Try turning the rows of the result into a sequence, rather than the whole result.

(defn success-handler [tx, results]
   (println "success handler")
   (println results)

  (doseq [result (.-rows results)]
    (prn result)))

And if rows does not implement Iterable then do it the old fashioned way

(defn success-handler [tx, results]
   (println "success handler")
   (println results)

  (let [rows (.-rows results)]
   (doall
    (for [i (range (.-length rows))]
      (let [row (nth rows i)]
        (prn result))))))
Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284
0

Here is the solution:

(defn success-handler [tx, results]
  (let [rows (.-rows results)]
    (doseq [i (range (.-length rows))]
      (prn (.item rows i)))))