Shantanu Kumar avatar Shantanu Kumar committed 4238213

add static var `default-dbspec` and additional key `:show-sql-fn`

Comments (0)

Files changed (1)

src/main/clj/org/bituf/clj_dbspec.clj

 ;; ----- The Db-Spec definition (data structure) -----
 
 
+(def ^{:doc "Default dbspec; see also: *dbspec*"} default-dbspec
+  (array-map
+   :datasource  nil
+   :connection  nil
+   :dbmetadata  (array-map)
+   :catalog     nil
+   :schema      nil
+   :show-sql    true
+   :show-sql-fn (fn [^String sql] (println sql))
+   :clj-to-db   (fn [iden]
+                  (if (string? iden) iden
+                    (apply str (replace {\- \_}
+                                 (in/as-string iden)))))
+   :db-to-clj   (fn [^String iden]
+                  (keyword (apply str (replace {\_ \-}
+                                        (sr/lower-case iden)))))))
+
+
 (def ^{:doc "Database configuration specification - map of values with the following
   Well-known keys:
     :datasource  (javax.sql.DataSource, default: nil)
                      works with most databases. Override as necessary.
 
   Libraries MAY expose their own API to re-bind this var to new values - they
-  MUST NOT alter the type/semantics of the well-defined keys. They MAY
-  introduce custom keys with unique prefixes e.g. :com.foo.xlib.conn-pool-name
-  (in order to prevent name collision), which may be useful to interoperate
-  with other libraries."
+  MUST NOT alter the type/semantics of the well-defined keys. They MAY introduce
+  custom keys with unique prefixes e.g. :com.foo.xlib.conn-pool-name or
+  :com.foo.xlib/conn-pool-name (in order to prevent name collision), which may
+  be useful to interoperate with other libraries."
        :dynamic true}
-      *dbspec* (array-map
-                 :datasource nil
-                 :connection nil
-                 :dbmetadata (array-map)
-                 :catalog    nil
-                 :schema     nil
-                 :show-sql   true
-                 :clj-to-db  (fn [iden]
-                               (if (string? iden) iden
-                                 (apply str (replace {\- \_}
-                                              (in/as-string iden)))))
-                 :db-to-clj  (fn [^String iden]
-                               (keyword (apply str (replace {\_ \-}
-                                                     (sr/lower-case iden)))))))
+      *dbspec* default-dbspec)
 
 
 ;; ----- Convenience macros/functions for binding values into DB-Spec -----
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.