GithubHelp home page GithubHelp logo

squee's Introduction

squee

A refreshed JDBC wrapper, made for Clojure 1.7

Rationale

tl;dr:

  • Ergonomics: consistent argument shapes
  • Modernized implementation with cheap reducible result-sets
  • Less seq and stack frame allocation compared to clojure.java.jdbc
  • Smaller methods, modularized. (e.g. RowGenerator protocol)

Guide

Arguments

Arguments all have the same shape [conn sql params opts], and the first two are required.

  1. conn: a connection or transaction
  2. sql: a SQL string
  3. params: a function that manipulates the sql statement, usually filling in templated values. There are two such built-ins, params and many. See below
  4. opts: a map of options

Examples

Full API docs

Query

(query conn "select * from bar")

(query conn "select * from bar where x = ?" (params 4))

Inserts

(let [sql "insert into foo (x,y) values (?,?)"]
  (execute! conn sql (params 42 40) {:return-keys? true}))

(let [sql "insert into foo (x,y) values (?,?)"]
  (execute! conn sql (many [[20 30] [40 50]])))

Transactions

(transactionally conn
  (execute conn ...)
  (query conn...)
  (execute conn...))

You can set the isolation level like so:

(transactionally conn {:isolation-level :serializable}
  ...body)

Param Helpers

Statement params come in two flavors, one or many, dependending on how many times the entire sql statement is used

(params ...)
(many [ [...] [...] [...] ...])    ;; this can be an lazy or an eduction too

Reducible Result sets

While clojure.java.jdbc uses lazy-seqs and a naive strategy to extract data from a ResultSet, results from query in this library implement clojure.lang.IReduceInit, and are very efficient to realize.

Extension points

...

License

Copyright © Ghadi Shayban

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

squee's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.