Skip to content

Commit 8b27208

Browse files
committed
style(core): fix cljfmt styling issues
1 parent d80f079 commit 8b27208

File tree

10 files changed

+91
-102
lines changed

10 files changed

+91
-102
lines changed

src/clj_postgresql/coerce.clj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@
1313

1414
(defmethod geojson->postgis :LineString
1515
[m]
16-
(st/line-string (:coordinates m)))
16+
(st/line-string (:coordinates m)))
1717

1818
(defmethod geojson->postgis :MultiLineString
1919
[m]
20-
(st/multi-line-string (:coordinates m)))
20+
(st/multi-line-string (:coordinates m)))
2121

2222
(defmethod geojson->postgis :Polygon
2323
[m]
24-
(st/polygon (:coordinates m)))
24+
(st/polygon (:coordinates m)))
2525

2626
(defmethod geojson->postgis :MultiPolygon
2727
[m]
28-
(st/multi-polygon (:coordinates m)))
28+
(st/multi-polygon (:coordinates m)))
2929

3030
(defprotocol PostgisToCoords
3131
(postgis->coords [o]))
@@ -54,7 +54,7 @@
5454
org.postgis.MultiPolygon
5555
(postgis->coords [o]
5656
(mapv postgis->coords (.getPolygons o))))
57-
57+
5858
(defprotocol PostgisToGeoJSON
5959
(postgis->geojson [o]))
6060

@@ -83,4 +83,3 @@
8383
(postgis->geojson [o]
8484
{:type :MultiPolygon
8585
:coordinates (postgis->coords o)}))
86-

src/clj_postgresql/core.clj

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns clj-postgresql.core
22
"Allow using PostgreSQL from Clojure as effortlessly as possible by reading connection parameter defaults from
3-
PostgreSQL environment variables PGDATABASE, PGHOST, PGPORT, PGUSER and by reading password from ~/.pgpass if available."
3+
PostgreSQL environment variables PGDATABASE, PGHOST, PGPORT, PGUSER and by reading password from ~/.pgpass if available."
44
(:require [clj-postgresql.types]
55
[cheshire.core :as json]
66
[clojure.xml :as xml]
@@ -21,19 +21,19 @@ PostgreSQL environment variables PGDATABASE, PGHOST, PGPORT, PGUSER and by readi
2121

2222
(defn getenv->map
2323
"Convert crazy non-map thingy which comes from (System/getenv) into a keywordized map.
24-
If no argument given, fetch env with (System/getenv)."
24+
If no argument given, fetch env with (System/getenv)."
2525
([x]
26-
{:pre [(= (type x) java.util.Collections$UnmodifiableMap)]
27-
:post [(map? %)]}
28-
(zipmap
29-
(map keyword (keys x))
30-
(vals x)))
26+
{:pre [(= (type x) java.util.Collections$UnmodifiableMap)]
27+
:post [(map? %)]}
28+
(zipmap
29+
(map keyword (keys x))
30+
(vals x)))
3131
([]
32-
(getenv->map (System/getenv))))
32+
(getenv->map (System/getenv))))
3333

3434
(defn default-spec
3535
"Reasonable defaults as with the psql command line tool.
36-
Use username for user and db. Don't use host."
36+
Use username for user and db. Don't use host."
3737
[]
3838
(let [username (java.lang.System/getProperty "user.name")]
3939
{:dbtype "postgresql"
@@ -46,15 +46,15 @@ PostgreSQL environment variables PGDATABASE, PGHOST, PGPORT, PGUSER and by readi
4646
{:pre [(map? env)]
4747
:post [(map? %)]}
4848
(cond-> {}
49-
PGDATABASE (assoc :dbname PGDATABASE)
50-
PGHOST (assoc :host PGHOST)
51-
PGPORT (assoc :port PGPORT)
52-
PGUSER (assoc :user PGUSER)))
49+
PGDATABASE (assoc :dbname PGDATABASE)
50+
PGHOST (assoc :host PGHOST)
51+
PGPORT (assoc :port PGPORT)
52+
PGUSER (assoc :user PGUSER)))
5353

5454
(defn spec
5555
"Create database spec for PostgreSQL. Uses PG* environment variables by default
56-
and acceps options in the form:
57-
(pg-spec :dbname ... :host ... :port ... :user ... :password ...)"
56+
and acceps options in the form:
57+
(pg-spec :dbname ... :host ... :port ... :user ... :password ...)"
5858
[& {:keys [password] :as opts}]
5959
{:post [(contains? % :dbname)
6060
(contains? % :user)]}
@@ -65,7 +65,7 @@ PostgreSQL environment variables PGDATABASE, PGHOST, PGPORT, PGUSER and by readi
6565
spec-opts)
6666
password (or password (pgpass/pgpass-lookup db-spec))]
6767
(cond-> (merge extra-opts db-spec)
68-
password (assoc :password password))))
68+
password (assoc :password password))))
6969

7070
(defn pool
7171
[& rest]
@@ -83,9 +83,9 @@ PostgreSQL environment variables PGDATABASE, PGHOST, PGPORT, PGUSER and by readi
8383
[db]
8484
(jdbc/with-db-metadata [md db]
8585
(->> (doall (jdbc/metadata-result (.getTables md nil nil nil (into-array ["TABLE"]))))
86-
(map :table_name)
87-
(map keyword)
88-
(set))))
86+
(map :table_name)
87+
(map keyword)
88+
(set))))
8989

9090
;;
9191
;; Types
@@ -121,70 +121,69 @@ PostgreSQL environment variables PGDATABASE, PGHOST, PGPORT, PGUSER and by readi
121121
(defn point
122122
"Create a PGpoint object"
123123
([x y]
124-
(PGpoint. x y))
124+
(PGpoint. x y))
125125
([obj]
126-
(cond
127-
(instance? PGpoint obj) obj
128-
(coll? obj) (point (first obj) (second obj))
129-
:else (PGpoint. (str obj)))))
126+
(cond
127+
(instance? PGpoint obj) obj
128+
(coll? obj) (point (first obj) (second obj))
129+
:else (PGpoint. (str obj)))))
130130

131131
(defn box
132132
"Create a PGbox object"
133133
([p1 p2]
134-
(PGbox. (point p1) (point p2)))
134+
(PGbox. (point p1) (point p2)))
135135
([x1 y1 x2 y2]
136-
(PGbox. x1 y1 x2 y2))
136+
(PGbox. x1 y1 x2 y2))
137137
([obj]
138-
(if (instance? PGbox obj)
139-
obj
140-
(PGbox. (str obj)))))
138+
(if (instance? PGbox obj)
139+
obj
140+
(PGbox. (str obj)))))
141141

142142
(defn circle
143143
"Create a PGcircle object"
144144
([x y r]
145-
(PGcircle. x y r))
145+
(PGcircle. x y r))
146146
([center-point r]
147-
(PGcircle. (point center-point) r))
147+
(PGcircle. (point center-point) r))
148148
([obj]
149-
(if (instance? PGcircle obj)
150-
obj
151-
(PGcircle. (str obj)))))
149+
(if (instance? PGcircle obj)
150+
obj
151+
(PGcircle. (str obj)))))
152152

153153
(defn line
154154
"Create a PGline object"
155155
([x1 y1 x2 y2]
156-
(PGline. x1 y1 x2 y2))
156+
(PGline. x1 y1 x2 y2))
157157
([p1 p2]
158-
(PGline. (point p1) (point p2)))
158+
(PGline. (point p1) (point p2)))
159159
([obj]
160-
(if (instance? PGline obj)
161-
obj
162-
(PGline. (str obj)))))
160+
(if (instance? PGline obj)
161+
obj
162+
(PGline. (str obj)))))
163163

164164
(defn lseg
165165
"Create a PGlseg object"
166166
([x1 y1 x2 y2]
167-
(PGlseg. x1 y1 x2 y2))
167+
(PGlseg. x1 y1 x2 y2))
168168
([p1 p2]
169-
(PGlseg. (point p1) (point p2)))
169+
(PGlseg. (point p1) (point p2)))
170170
([obj]
171-
(if (instance? PGlseg obj)
172-
obj
173-
(PGlseg. (str obj)))))
174-
171+
(if (instance? PGlseg obj)
172+
obj
173+
(PGlseg. (str obj)))))
174+
175175
(defn path
176176
"Create a PGpath object"
177177
([points open?]
178-
(PGpath. (into-array PGpoint (map point points)) open?))
178+
(PGpath. (into-array PGpoint (map point points)) open?))
179179
([obj]
180-
(if (instance? PGpath obj)
181-
obj
182-
(PGpath. (str obj)))))
180+
(if (instance? PGpath obj)
181+
obj
182+
(PGpath. (str obj)))))
183183

184184
(defn polygon
185185
"Create a PGpolygon object"
186186
[points-or-str]
187187
(if (coll? points-or-str)
188188
(PGpolygon. ^"[Lorg.postgresql.geometric.PGpoint;" (into-array PGpoint (map point points-or-str)))
189189
(PGpolygon. ^String (str points-or-str))))
190-

src/clj_postgresql/geojson.clj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@
102102
(defn schema-pred
103103
[schema m]
104104
(try (s/validate schema m)
105-
true
106-
(catch Exception e
107-
false)))
108-
105+
true
106+
(catch Exception e
107+
false)))
108+
109109
(defn point?
110110
[m]
111111
(schema-pred Point m))
@@ -122,5 +122,4 @@
122122
:post [(s/validate MultiPoint %)]}
123123
{:type :MultiPoint
124124
:coordinates nil})
125-
126-
125+

src/clj_postgresql/geometric/Point.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(ns clj-postgresql.geometric.Point
22
"Example implementation of a PGobject that also implements
3-
Clojure's ISeq and shows as a sequence of two numbers."
3+
Clojure's ISeq and shows as a sequence of two numbers."
44
(:gen-class
5-
:extends org.postgresql.geometric.PGpoint
6-
:implements [clojure.lang.Counted clojure.lang.ISeq]
7-
:main false))
5+
:extends org.postgresql.geometric.PGpoint
6+
:implements [clojure.lang.Counted clojure.lang.ISeq]
7+
:main false))
88

99
(defn to-list
1010
[^org.postgresql.geometric.PGpoint this]

src/clj_postgresql/pgpass.clj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
(defn pgpass-matches?
2727
"(filter (partial pgpass-matches? spec) pgpass-lines)"
2828
[{:keys [host port dbname user]} {:keys [pg-hostname pg-port pg-database pg-username pg-password]}]
29-
(when
30-
(and
31-
(or (= pg-hostname "*") (= pg-hostname host) (and (= pg-hostname "localhost") (nil? host)))
32-
(or (= pg-port "*") (= pg-port port) (and (= pg-port "5432") (nil? port)))
33-
(or (= pg-database "*") (= pg-database dbname))
34-
(or (= pg-username "*") (= pg-username user)))
29+
(when
30+
(and
31+
(or (= pg-hostname "*") (= pg-hostname host) (and (= pg-hostname "localhost") (nil? host)))
32+
(or (= pg-port "*") (= pg-port port) (and (= pg-port "5432") (nil? port)))
33+
(or (= pg-database "*") (= pg-database dbname))
34+
(or (= pg-username "*") (= pg-username user)))
3535
pg-password))
3636

3737
(defn pgpass-lookup

src/clj_postgresql/protocol.clj

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@
157157
(defn send!
158158
[^SocketChannel sc bufs]
159159
(as-> bufs x
160-
(map #(.rewind ^ByteBuffer %) x)
161-
(into-array ByteBuffer x)
162-
(.write sc ^"[Ljava.nio.ByteBuffer;" x)))
160+
(map #(.rewind ^ByteBuffer %) x)
161+
(into-array ByteBuffer x)
162+
(.write sc ^"[Ljava.nio.ByteBuffer;" x)))
163163

164164
(defn recv!
165165
[^SocketChannel sc]
@@ -172,7 +172,7 @@
172172
(.read sc ^ByteBuffer content-bb)
173173
(.rewind content-bb)
174174
(response type len content-bb))))
175-
175+
176176
(defn converse
177177
[]
178178
(with-open [sc (SocketChannel/open (InetSocketAddress. "127.0.0.1" 5432))]
@@ -192,7 +192,6 @@
192192
(pprint (recv! sc))
193193
(send! sc (terminate-message))))
194194

195-
196195
;; startup
197196
;; ReadyForQuery
198197
;; dostuff
@@ -264,7 +263,6 @@
264263
;;
265264

266265

267-
268266
;;
269267
;; pg-async ?
270268
;;

src/clj_postgresql/spatial.clj

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"Returns the set SRID of a geometry object"
77
[^Geometry geometry]
88
(.getSrid geometry))
9-
9+
1010
(defn with-srid!
1111
"Return the geometry object with SRID set. Alters the object."
1212
[^Geometry geometry srid]
@@ -20,21 +20,21 @@
2020
(>= (count x) 2)
2121
(<= (count x) 3)
2222
(every? number? (map number? x)))))
23-
23+
2424
(defn point
2525
"Make a 2D or 3D Point."
2626
([x y]
27-
(Point. x y))
27+
(Point. x y))
2828
([x y z]
29-
(Point. x y z))
29+
(Point. x y z))
3030
([coll-or-str]
31-
(cond (instance? Point coll-or-str) coll-or-str
32-
(coll? coll-or-str) (let [x (first coll-or-str)
33-
y (second coll-or-str)]
34-
(if-let [z (nth coll-or-str 2 nil)]
35-
(Point. x y z)
36-
(Point. x y)))
37-
:else (Point. (str coll-or-str)))))
31+
(cond (instance? Point coll-or-str) coll-or-str
32+
(coll? coll-or-str) (let [x (first coll-or-str)
33+
y (second coll-or-str)]
34+
(if-let [z (nth coll-or-str 2 nil)]
35+
(Point. x y z)
36+
(Point. x y)))
37+
:else (Point. (str coll-or-str)))))
3838

3939
(defn multi-point
4040
"Make a MultiPoint from collection of Points."

0 commit comments

Comments
 (0)