Skip to content
Experimental stuff for going fast with Clojure + JDBC & Async SQL
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Initial commit Apr 7, 2019
docs/images 0.0.1-alpha8 Jun 1, 2019
src/porsas porsas async, alpha12 Jul 7, 2019
test/porsas porsas.next, porsas.async + CompletableFuture Jun 4, 2019
.gitignore Initial commit Apr 7, 2019
.travis.yml Initial commit Apr 7, 2019
CHANGELOG.md
LICENSE Initial commit Apr 7, 2019
README.md Update README.md Jul 10, 2019
project.clj

README.md

porsas cljdoc badge

Nopea kuin sika pakkasella

Spike to see how fast we can go with both Clojure + JDBC & Async SQL. Highly Experimental.

Related dicsussion: https://clojureverse.org/t/next-jdbc-early-access/4091

Latest version

Clojars Project

Usage

porsas provides tools for precompiling the functions to convert ResultSet into Clojure values. This enables basically Java-fast JDBC queries while using idiomatic Clojure.

(defprotocol DataMapper
  (cache [this])
  (query-one [this ^Connection connection sqlvec])
  (query [this ^Connection connection sqlvec]))

porsas.core/compile returns a porsas.core/DataMapper instance. The following options are available for the compiler:

key description
:row Optional function of rs->value or a [[RowCompiler]] to convert rows into values
:key Optional function of rs-meta i->key to create key for map-results"

Note: some RowCompiler implementations (like p/rs->map) generate the code at runtime, which might not supported in all platforms like GraalVM.

Examples

A Java JDBC query

;; 630ns
(title "java")
(bench! (java-query connection "SELECT * FROM fruit"))

Compiled query functions

(def mapper (p/data-mapper {:row (p/rs->map)}))

;; 630ns
(title "porsas: compiled & cached query")
(bench! (p/query mapper connection "SELECT * FROM fruit")))

Cached query functions

With defaults, a bit slower (non-compiled) mapper is used. Works on all platforms.

;; 1300ns
(title "porsas: cached query")
(bench! (p/query p/default-mapper connection "SELECT * FROM fruit")))

Fully Dynamic queries

(def mapper (p/data-mapper {:cache nil)}))

;; 1500ns
(title "porsas: dynamic query")
(bench! (p/query mapper connection "SELECT * FROM fruit"))

Performance

At least an order of magnitude faster than clojure.java.jdbc, see the tests for more details.

TODO

  • more tests
  • batch-api
  • async-api for postgresql?

License

Copyright © 2019 Metosin Oy

Distributed under the Eclipse Public License, the same as Clojure.

You can’t perform that action at this time.