标签: sqlkorma

使用Korma在Clojure中清理数据库输入

我在RESTful API后面使用Korma,我发现我将用户提交的值传递给我的(insert)调用.在Clojure中有一种很好的方法可以防止SQL注入攻击吗?Korma以非常简单的方式生成SQL,所以如果有人告诉我他们的名字是小Bobby Tables,我担心它会受到伤害.

sql clojure korma sqlkorma

4
推荐指数
1
解决办法
617
查看次数

具有过滤功能的clojure first-thread

我遇到一个问题,将一些表格串联在一起,从korma函数对结果集进行一些ETL.

我从korma sql回来了:

({:id 1 :some_field "asd" :children [{:a 1 :b 2 :c 3} {:a 1 :b 3 :c 4} {:a 2 :b 2 :c 3}] :another_field "qwe"})

我想通过获取:a关键字为1 的"children"来过滤此结果集.

我的尝试:

;mock of korma result
(def data '({:id 1 :some_field "asd" :children [{:a 1 :b 2 :c 3} {:a 1 :b 3 :c 4} {:a 2 :b 2 :c 3}] :another_field "qwe"}))

(-> data 
    first 
    :children 
    (filter #(= (% :a) 1)))
Run Code Online (Sandbox Code Playgroud)

我在这里期待的是一个哈希图矢量:a设置为1,即:

[{:a 1 :b 2 :c 3} …
Run Code Online (Sandbox Code Playgroud)

clojure filter sqlkorma

4
推荐指数
1
解决办法
254
查看次数

MySQL和clj-time的时区问题

我有一个MySQL表.

create table demo ( theDate datetime );

我插入两个日期,一个在夏令时,一个不在.

(require '[clj-time.core :as t])
(require '[clj-time.coerce :as coerce])
(require '[korma.core :as k])

(k/insert :demo (values {:theDate (coerce/to-sql-date (t/date-time 2014 01 01))}))
(k/insert :demo (values {:theDate (coerce/to-sql-date (t/date-time 2014 06 01))}))
Run Code Online (Sandbox Code Playgroud)

从我的MySQL客户端看起来正确的值已经进入:

mysql> select * from demo;
+---------------------+
| theDate             |
+---------------------+
| 2014-01-01 00:00:00 |
| 2014-06-01 00:00:00 |
+---------------------+
Run Code Online (Sandbox Code Playgroud)

当我选择Korma(我不认为Korma在JDBC之上做任何相关的事情)时,我在非夏令时日期得到时区差异.

=> (k/select :demo)
[{:theDate #inst "2014-01-01T00:00:00.000000000-00:00"}
 {:theDate #inst "2014-05-31T23:00:00.000000000-00:00"}]
Run Code Online (Sandbox Code Playgroud)

当我选择日期时:

(map #(-> % :theDate coerce/from-sql-date t/month) (k/select :demo))
(1 5) …
Run Code Online (Sandbox Code Playgroud)

mysql timezone jdbc clojure sqlkorma

3
推荐指数
1
解决办法
910
查看次数

标签 统计

clojure ×3

sqlkorma ×3

filter ×1

jdbc ×1

korma ×1

mysql ×1

sql ×1

timezone ×1