Coder Social home page Coder Social logo

jmayaalv / honeyeql Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tamizhvendan/honeyeql

0.0 1.0 0.0 280 KB

HoneyEQL is a Clojure library enables you to query database using the EDN Query Language.

Home Page: https://www.graphqlize.org

License: Eclipse Public License 2.0

Clojure 100.00%

honeyeql's Introduction

HoneyEQL

HoneyEQL is a Clojure library enables you to query the database declaratively using the EDN Query Language(EQL). It aims to simplify the effort required to work with the relational databases in Clojure.

HoneyEQL powers GraphQLize.

Clojars Project

CAUTION: HoneyEQL is at its early stages now. It is not production-ready yet!. It currently supports Postgres (9.4 & above) and MySQL (8.0 & above) only.

Rationale

When a query involves more than one table, the declarative nature of SQL depreciates. Depends on the type of relationship, we have to put appropriate join conditions.

Let's assume that we have the following schema.

To get all the films of an actor with the id 148 along with his/her first name & last name, we have to query it as

(jdbc/execute! ds ["SELECT actor.first_name, actor.last_name, film.title
                    FROM actor
                    LEFT OUTER JOIN film_actor ON film_actor.actor_id = actor.actor_id
                    LEFT OUTER JOIN film ON film_actor.film_id = film.film_id
                    WHERE actor.actor_id = ?" 148])

The query result would look like

[{:actor/first_name "EMILY", :actor/last_name "DEE", :film/title "ANONYMOUS HUMAN"}
 {:actor/first_name "EMILY", :actor/last_name "DEE", :film/title "BASIC EASY"}
 {:actor/first_name "EMILY", :actor/last_name "DEE", :film/title "CHAMBER ITALIAN"}
 ...]

Then we need to group by first_name & last_name to get the exact result result that we want!

How about making these steps truly declarative?

With HoneyEQL, we can do it as

(heql/query-single 
  db-adapter  
  {[:actor/actor-id 148] 
   [:actor/first-name 
    :actor/last-name 
    {:actor/films 
     [:film/title]}]})

The above query yields the results in the exact-shape that we wanted and without any explicit data transformations.

{:actor/first-name "EMILY"
 :actor/last-name "DEE"
 :actor/films [{:film/title "ANONYMOUS HUMAN"}
               {:film/title "BASIC EASY"}
               {:film/title "CHAMBER ITALIAN"}
               ...]}

As the query syntax is made up of Clojure's data structures, we can construct it dynamically at runtime.

HoneyEQL transforms the EQL into single efficient SQL and query the database using next.jdbc.

Documentation

cljdoc badge

Acknowledgements

Walkable is the inspiration behind HoneyEQL.

HoneyEQL is not possible without the following excellent Clojure libraries.

The samples in the documentation of HoneyEQL uses the Sakila database from JOOQ extensively.

License

The use and distribution terms for this software are covered by the Eclipse Public License - v 2.0. By using this software in any fashion, you are agreeing to be bound by the terms of this license.

honeyeql's People

Contributors

demystifyfp avatar tamizhvendan avatar

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.