-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 15.01.2015 12:57, gvim wrote: > Here is a Clojurescript database connection in NodeJS and below it > the JS I ported it from. 2 questions: > > 1. I believe core.async is the way instead of replicating NodeJS > nested callbacks. What is the equivalent using core.async? 2. I > couldn't get ((.rows result) 0) to work for result.rows[0]. > result.rows worked as-is in cljs but I don't understand why. > > gvim
I am not sure whether I understand your problem correctly, but if the js callback API guarantees transactional safety around your queries, then you cannot use core.async internally, but only expose channels to the outside. I have done the same thing for IndexedDB, core.async didn't work, because the callbacks are basically transformed to the heap and the actual transaction is over when the channel operations continue (because it is closed with the stack in case of IndexedDB). https://github.com/ghubber/konserve/blob/master/src/cljs/konserve/indexeddb.cljs Btw. if the konserve kv-protocol fits your needs feel free to implement it ;-). Cheers, Christian > > > > (ns ndpg.core (:require [cljs.nodejs :as n])) > > (n/enable-util-print!) > > (def pg (n/require "pg")) (def con > "postgres://admin:p@localhost:5432/astro") (def client (pg.Client. > con)) > > (.connect client (fn [err] (if err (.error js/console "Couldn't > connect" err) (.query client "select * from births" (fn [err > result] (if err (.error js/console "Query error" err) (do (.log > js/console result.rows) (.end client)))))))) > > (defn -main [] (println (range 1 100))) > > (set! *main-cli-fn* -main) > > ;;;;;;;;;;;;;;;;;;;;;;; JS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > > var con = "postgres://admin:p@localhost:5432/db"; > > var client = new pg.Client(con); client.connect(function(err) { > if(err) { return console.error("Couldn't connect", err); } > client.query('SELECT * FROM births', function(err, result) { > if(err) { return console.error('Query error', err); } > console.log(result.rows[0]); client.end(); }); }); > -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJUt7R+AAoJEKel+aujRZMkc7AH/jHOIyBZpmQewU7kwtA7yrYh SGXajVI5TAtdICRsxE75Dea8UaGPc85sxIy4P7uSz73YyzgqJN5ZDRa1wcUOBdkQ eYTmjdjhGqhEwtYi2EtRuxsXBkrQCk6bF4bEMEkiL3g9T/yoskTKwutqE4BvATO8 s5SCG17fBnqsDkwJnOTMy+FscMJkG0t4LOyAFONGbMovGhmhBEkYnGHrrNMEIzhs 92tEeV36GW7O9C72iXQtDqA/BmXBGgpCuF3cCTykuXpQn9JX5u0m3KCntvFBbbuB NLEOG+j2TvXFstH0NVhBUwQ0LdM2cWhwE8txvsimp38W1PW5n2booaQPRYGwPLA= =98DC -----END PGP SIGNATURE----- -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/clojurescript.
