Skip to content

plooney81/nectar-sql

Repository files navigation

nectar-sql

Clojars

nectar: A sugary liquid secreted by plants, primarily in their flowers, to attract pollinators like bees, butterflies, and hummingbirds. It serves as the raw material for honey.

nectar-sql: Converts raw sql strings into honey sql. nectar-sql takes a raw sql string, parses it (using JSqlParser) and converts it into honeysql

nectar-sql is currently a work in progress and, at present, can be expected to handle a wide variety of SELECT queries.

Try It from Your REPL

The Clojure REPL includes functions for downloading and adding libraries at runtime, making it super easy to try it out. From your REPL...

user> (add-lib 'com.github.plooney81/nectar-sql {:mvn/version "1.0.22"})
;;==> [com.github.jsqlparser/jsqlparser
;;==>  com.github.plooney81/nectar-sql
;;==>  com.github.seancorfield/honeysql]

You may now import nectar-sql and convert a SQL string to HoneySQL. This might be handy if you have some SQL on hand and you're not sure what the HoneySQL would look like. Instead of trial and error, let nectar-sql convert it for you.

user> (require '[plooney81.nectar.sql :as nsql])
;;==> nil

user> (nsql/ripen "select count(distinct id) from sales 
                     where year = 2025 and quarter = 'Q4'")

;;==> {:select [[[:count [:distinct :id]]]]
;;==>  :from   [:sales]
;;==>  :where  [:and [:= :year 2025] [:= :quarter "Q4"]]

Adding nectar-sql to your project works much the same way. Add the dependency and then require the library where needed.

user> (require '[plooney81.nectar.sql :as nsql])
;;==> nil

;; convert a query...
user> (nsql/ripen
  "SELECT *
     FROM people
    WHERE age > 25
 ORDER BY age DESC")

;; ...to HoneySQL!
;;==> {:select   [:*]
;;==>  :from     [:people]
;;==>  :where    [:> :age 25]
;;==>  :order-by [[:age :desc]]}

Running Tests

Run the project's tests:

$ clj -T:build test

Run the project's CI pipeline and build a JAR (this will fail until you edit the tests to pass):

$ clj -T:build ci

This will produce an updated pom.xml file with synchronized dependencies inside the META-INF directory inside target/classes and the JAR in target. You can update the version (and SCM tag) information in generated pom.xml by updating build.clj.

Install it locally (requires the ci task be run first):

$ clj -T:build install

Deploy it to Clojars -- needs CLOJARS_USERNAME and CLOJARS_PASSWORD environment variables (requires the ci task be run first):

$ clj -T:build deploy

Your library will be deployed to net.clojars.plooney81/nectar-sql on clojars.org by default.

Support

  • Scope:

    • We currently only support SELECT functionality
    • We hope to support INSERT, UPDATE, DELETE in the future
  • nectar-sql relies heavily on JSQLParser

    • JSQLParser doesn't currently support a few pieces of functionality, like Implicit Casting in Postgres

Credit

This project is proudly sponsored by Luminare! 😎


License

Copyright © 2024 Plooney

Distributed under the Eclipse Public License version 1.0.

About

Converts raw sql strings into honey sql.

Resources

License

Stars

Watchers

Forks

Packages

No packages published