ClojureScript中的WebSQL?

时间:2013-04-28 23:48:29

标签: web-sql clojurescript

我在为websql格式化ClojureScript包装时遇到了一些麻烦。主要问题是JavaScript使用了无法定义的websql的tx和err参数。当ClojureScript版本运行时,代码会抛出错误,因为tx未定义。下面是一些示例代码,以及我正在尝试的websql tutorial from PhoneGap

(defn populateDB [tx]
  (.executeSql tx ("CREATE TABLE IF NOT EXISTS foo (id unique, text)"))
  (.log js/console "table added"))

(defn errorCB [err]
  (.log js/console (str "There was an error" (.code err))))

(defn successCB []
  (.alert js/window "It worked!"))

;; Run the transactions
(def db
  (.openDatabase js/window "Database" "1.0" "Cordova Demo" 1024))

(.transaction db (populateDB) (errorCB) (successCB))

有没有办法让这个工作或者webql + ClojureScript已经存在的任何库?

1 个答案:

答案 0 :(得分:2)

我猜这个问题有点愚蠢。在发布之前我应该​​更多地看一下:p。作为参考,这是写这个的一种方法:

(def db
  (.openDatabase js/window "Database" "1.0" "Cordova Demo" 1024))

(.transaction db.
              (fn [tx]
                (.executeSql tx "CREATE TABLE IF NOT EXISTS DEMO (id unique, data)"))
              (fn [err]
                (.log js/console.
                  (str "There was an error " (.code err))))
              (fn []
                (.log js/console "It worked!")))