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

Contributors

ghadishayban avatar mpenet avatar

Stargazers

 avatar Tommi Reiman avatar Sundar Joshi avatar Jeremy Heiler avatar Derek Slager avatar Priyatam Mudi avatar Angus H. avatar Josh Teneycke avatar Ivan Fedorov avatar Christoffer Sawicki avatar Matt Gauger avatar Devin Walters avatar Davide D'Agostino avatar Anders Nilsson avatar Val Packett avatar Jonathan Henry avatar Johannes Staffans avatar Carin Meier avatar Eric Bailey avatar  avatar Peter Taoussanis avatar  avatar Colin Taylor avatar Christophe Mees avatar Shaun Mahood avatar Ben Lovell avatar Stephen Caudill avatar Waldemar avatar Neil Mock avatar Andy Chambers avatar Alan Dipert avatar Eduard Cespedes Borras avatar Roberto Guerra avatar Jonas Enlund avatar Ruslan Prakapchuk avatar

Watchers

Jonas Enlund avatar  avatar James Cloos avatar Chris Truter avatar  avatar

squee's Issues

add/implement protocol to transform the "sql" parameter into a statement

Right now we can customize the way statements are created via create-statement! or just defer to the default which will generate a statement from a string internally.

We could imagine having a proto that allows to control/open this and get rid of the create-statement! altogether:
That protocol would do what the current code does for strings, for IFn just run parameter passed and potentially other things for proto runtime extensions: compile a honeysql like dsl on the fly, etc.

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.