All Projects → metosin → Porsas

metosin / Porsas

Licence: epl-1.0
Experimental stuff for going fast with Clojure + JDBC & Async SQL

Programming Languages

clojure
4091 projects

Projects that are alternatives of or similar to Porsas

Jasync Sql
Java & Kotlin Async DataBase Driver for MySQL and PostgreSQL written in Kotlin
Stars: ✭ 1,092 (+1300%)
Mutual labels:  reactive, sql, jdbc
Kyuubi
Kyuubi is a unified multi-tenant JDBC interface for large-scale data processing and analytics, built on top of Apache Spark
Stars: ✭ 363 (+365.38%)
Mutual labels:  sql, jdbc
Rxjava2 Jdbc
RxJava2 integration with JDBC including Non-blocking Connection Pools
Stars: ✭ 360 (+361.54%)
Mutual labels:  reactive, jdbc
Jailer
Database Subsetting and Relational Data Browsing Tool.
Stars: ✭ 576 (+638.46%)
Mutual labels:  sql, jdbc
Vertx Jooq
A jOOQ-CodeGenerator to create vertx-ified DAOs and POJOs.
Stars: ✭ 299 (+283.33%)
Mutual labels:  reactive, jdbc
Micronaut Data
Ahead of Time Data Repositories
Stars: ✭ 352 (+351.28%)
Mutual labels:  sql, jdbc
Ragtime
Database-independent migration library
Stars: ✭ 519 (+565.38%)
Mutual labels:  sql, jdbc
Doma
DAO oriented database mapping framework for Java 8+
Stars: ✭ 257 (+229.49%)
Mutual labels:  sql, jdbc
Mycat2
MySQL Proxy using Java NIO based on Sharding SQL,Calcite ,simple and fast
Stars: ✭ 750 (+861.54%)
Mutual labels:  sql, jdbc
Spark
Apache Spark - A unified analytics engine for large-scale data processing
Stars: ✭ 31,618 (+40435.9%)
Mutual labels:  sql, jdbc
Examples
Demo applications and code examples for Confluent Platform and Apache Kafka
Stars: ✭ 571 (+632.05%)
Mutual labels:  sql, jdbc
Requery
requery - modern SQL based query & persistence for Java / Kotlin / Android
Stars: ✭ 3,071 (+3837.18%)
Mutual labels:  sql, jdbc
Clojureql
ClojureQL is superior SQL integration for Clojure
Stars: ✭ 281 (+260.26%)
Mutual labels:  sql, jdbc
Ebean
Ebean ORM
Stars: ✭ 1,172 (+1402.56%)
Mutual labels:  sql, jdbc
Trino
Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
Stars: ✭ 4,581 (+5773.08%)
Mutual labels:  sql, jdbc
Jooq
jOOQ is the best way to write SQL in Java
Stars: ✭ 4,695 (+5919.23%)
Mutual labels:  sql, jdbc
delta
DDD-centric event-sourcing library for the JVM
Stars: ✭ 15 (-80.77%)
Mutual labels:  reactive, jdbc
H2database
H2 is an embeddable RDBMS written in Java.
Stars: ✭ 3,078 (+3846.15%)
Mutual labels:  sql, jdbc
Hibernate Springboot
Collection of best practices for Java persistence performance in Spring Boot applications
Stars: ✭ 589 (+655.13%)
Mutual labels:  sql, jdbc
Scala Db Codegen
Scala code/boilerplate generator from a db schema
Stars: ✭ 49 (-37.18%)
Mutual labels:  sql, jdbc

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

Basics

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

SQL queries are executed against a Context, which caches compiled row transformation functions based on database metadata.

There are different Context implementations:

Currently, only eager query-one and query functions are supported.

Performance

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

Usage

JDBC

With defaults:

(require '[porsas.jdbc])

(def ctx (jdbc/context))

(jdbc/query-one ctx connection ["select * from fruit where appearance = ?" "red"])
; {:ID 1, :NAME "Apple", :APPEARANCE "red", :COST 59, :GRADE 87.0}

Returning maps with qualified keys:

(def ctx
  (jdbc/context
    {:key (jdbc/qualified-key)}))

(jdbc/query-one ctx connection ["select * from fruit where appearance = ?" "red"])
; #:FRUIT{:ID 1, :NAME "Apple", :APPEARANCE "red", :COST 59, :GRADE 87.0}

Generate Records for each unique Resultset, with lowercased keys. NOTE: this feature uses runtime code generation, so it doesn't work under GraalVM:

(def ctx
  (jdbc/context
    {:row (jdbc/rs->compiled-record)
     :key (jdbc/unqualified-key str/lower-case)}))

(jdbc/query-one ctx connection ["select * from fruit where appearance = ?" "red"])
; ; => #user.DBResult6208{:id 1, :name "Apple", :appearance "red", :cost 59, :grade 87.0}

Context can be omitted, bypassing all caching. Can be used when performance doesn't matter, e.g. when exploring in REPL:

(jdbc/query-one connection ["select * from fruit where appearance = ?" "red"])
; {:ID 1, :NAME "Apple", :APPEARANCE "red", :COST 59, :GRADE 87.0}

Async SQL

Uses non-blocking vertx-sql-client and can be used with libraries like Promesa and Manifold.

(require '[porsas.async :as async])

(def ctx (async/context))

;; define a pool
(def pool
  (async/pool
    {:uri "postgresql://localhost:5432/hello_world"
     :user "benchmarkdbuser"
     :password "benchmarkdbpass"
     :size 16}))

(-> (async/query-one ctx pool ["SELECT randomnumber from WORLD where id=$1" 1])
    (async/then :randomnumber)
    (async/then println))
; prints 504

A blocking call:

(-> (async/query-one ctx pool ["SELECT randomnumber from WORLD where id=$1" 1])
    (async/then :randomnumber)
    (deref))

With Promesa

(require '[promesa.core :as p])

(-> (pa/query-one ctx pool ["SELECT randomnumber from WORLD where id=$1" 1])
    (p/chain :randomnumber println))
; #<Promise[~]>
; printls 504

With Manifold

(require '[manifold.deferred :as d])

(-> (pa/query-one ctx pool ["SELECT randomnumber from WORLD where id=$1" 1])
    (d/chain :randomnumber println))
; << … >>
; printls 504

next.jdbc

Using porsas with :builder-fn option of next.jdbc:

(require '[porsas.next])
(require '[next.jdbc])

(def builder-fn (porsas.next/caching-row-builder))

(next.jdbc/execute-one! connection ["select * from fruit where appearance = ?" "red"] {:builder-fn builder-fn})
; #:FRUIT{:ID 1, :NAME "Apple", :APPEARANCE "red", :COST 59, :GRADE 87.0}

More info

There is #sql in Clojurians Slack for discussion & help.

Roadmap as issues.

License

Copyright © 2019 Metosin Oy

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].