Code Monkey home page Code Monkey logo

suricatta's Introduction

suricatta

Travis Badge

High level sql toolkit for clojure (backed by jooq library)

Latest Version

Clojars Project

Quick Start

Put suricatta on your dependency list:

[funcool/suricatta "2.0.0"]
[com.h2database/h2 "1.4.191"] ;; For this example only

Connect to the database and execute a query:

(require '[suricatta.core :as sc])

(with-open [ctx (sc/context "h2:mem:")]
  (sc/fetch ctx "select x from system_range(1, 2);"))
;; => [{:x 1} {:x 2}]

Documentation

http://funcool.github.io/suricatta/latest/

suricatta's People

Contributors

christoph-frick avatar dmitrykorolev avatar estsauver avatar jespino avatar lukaseder avatar niwinz avatar skammer avatar smaant avatar solatis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

suricatta's Issues

Upsert?

jOOQ 3.9.0 seems to have added support for PostgreSQL's INSERT INTO ... ON CONFLICT (AKA upsert) feature. Will this be added to Suricatta?

Not a bug

Had a problem exists between chair and keyboard moment.

Though dsl/join was referred into namespace clojure string join was accidentally used in code.

PSQLException The column index is out of range

Hi. I was trying to use extended types and stumbled upon this problem.
In documentation you gives an example of extending types to support json. And it works perfectly if one inserts with raw sql (insert into t1...). However if one uses insert-values:

(with-open [ctx (connection)]
  (sc/execute ctx (-> (dsl/insert-into :table)
                      (dsl/insert-values {:data {:a 1}}))))

It fails with exception:

2. Unhandled org.jooq.exception.DataAccessException
   SQL [insert into shipments (data) values ('{"a":1}'::jsonb)]; The
   column index is out of range: 1, number of columns: 0.

1. Caused by org.postgresql.util.PSQLException
   The column index is out of range: 1, number of columns: 0.

If I add (fmt/get-sql) after insert-values it'll work.

Confusion over document and async support

Hi,
Really enjoying using suricatta in my project but I have the follow question.
I am trying to add support for async queries to my project The docs suggest to do the following,

(defn execute
  ([ctx q] (execute ctx q {}))
  ([ctx q opts]
   (let [act (.-act ctx)
         fun #(% (exc/try-on (sc/execute ctx q)))]
     (p/promise
      (fn [deliver]
        (send-off act (fn [_] (fun deliver))))))))

(defn fetch
  ([ctx q]
   (fetch ctx q {}))
  ([ctx q opts]
   (let [act (.-act ctx)
         fun #(% (exc/try-on (sc/fetch ctx q opts)))]
     (p/promise
      (fn [deliver]
        (send-off act (fn [_] (fun deliver))))))))

However I get the following error

java.lang.IllegalArgumentException: No matching field found: act for class suricatta.types.Context

So it seems like I don't have access to the actor for that type. I am assuming that -act is the actor we we use send-off later on.

I can see that the actor was refactor out in this commit,
d599e22
What is the correct way to support aysnc queries? Was this removal on purpose?

Thanks

fetch for insert query is failing without requiring suricatta.format

In a clean repl without requiring suricatta.format this:

(db/fetch-one conn (-> (dsl/insert-into :table)
                       (dsl/insert-values {:xxx "yyy"})))

will fail with an error:

IllegalArgumentException No implementation of method: :-sql of protocol:
#'suricatta.proto/IRenderer found for class: org.jooq.impl.InsertImpl  clojure.core/-cache-protocol-fn (core_deftype.clj:568)

after requiring suricatta.format everything works fine.

NULL values incorrectly being cast to varchar for pgsql dialect

user=> (fmt/sqlvec (-> (dsl/update :foo) (dsl/set :foo nil)))
["update foo set foo = ?" nil]
user=> (fmt/sqlvec (-> (dsl/update :foo) (dsl/set :foo nil)) {:dialect :postgresql})
["update foo set foo = cast(? as varchar)" nil]

Most likely an issue with jOOQ.

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.