Skip to content

HealthSamurai/sql2dsql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sql2dsq

Library for converting sql queiries to dsql structures.

Overview

This library provides a simple way to parse PostgreSQL queries in Clojure applications. It uses the libpg_query library under the hood to parse queries into a JSON representation of the PostgreSQL parse tree. To use this library in Java, JNA is utilized. You can find the JNA wrapper code in the java folder.

Installation

At the moment, the resources include a prebuilt libpq_query library for macOS to facilitate a quick start for developers.

Go to java folder and run:

mvn clean package

After that you can start REPL :)

Development

All code is located in src/sql2dsql/core. The parse-sql function returns an AST in EDN format. The multimethod stmt->dsql takes this AST and transforms it into dsql structure. You can find a list of all AST node types here. For each node, there is a corresponding stmt->dsql method implementation; however, not all AST nodes are currently supported.

You can play with core functions in user namespace:

(ns user
  (:require [sql2dsql.core :refer [->dsql parse-sql]]))

(parse-sql "select * from patient where id = '1'")
(->dsql "select * from patient where id = '1'")

To run tests:

clojure -X:test

Requirements

  • JDK 11 or later
  • Clojure 1.11 or later
  • libpg_query native library must be available in your system's library path

License

Distributed under the Eclipse Public License version 1.0.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published