Skip to content

ZZGit/redsql

Repository files navigation

redsql Clojure Test CI codecov

Clojars Project

redsql是honeysql + next-jdbc 的数据库操作的工具。

简介

honeysql只负责将clojure的map结构(称为sqlmap),格式化成sql.比如:

(require '[honey.sql :as sql])

(def sqlmap {:select [:a :b :c]
             :from   [:foo]
             :where  [:= :foo.a "baz"]})

(sql/format sqlmap)

=> ["SELECT a, b, c FROM foo WHERE foo.a = ?" "baz"]

而redsql借助next-jdbc,对外提供CURD接口,负责执行sqlmap.

(require '[redsql.core :as redsql])

;; 数据源配置
(def db-spec
  {:jdbcUrl "jdbc:h2:./demo"})

;; 连接
(redsql/connect! db-spec)

;; 查询
(def sqlmap {:select [:id :name]
             :from   [:user]
             :where  [:= :name "tom"]})
(redsql/get-one sqlmap)

;; 关闭连接
(redsql/disconnect! db-spec)

返回结果

{:id "1" :name "tom"}

除此之外,还提供了多数据源,逻辑删除,字段自动填充等功能.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published