neo4j-contrib / sql2cypher

Experimental SQL to Cypher Transpiler using jooq and cypher-dsl
Apache License 2.0
26 stars 1 forks source link
cypher cypher-dsl jooq sql

WARNING: This repository is achieved as of January 2024. We are very grateful towards https://www.datageekery.com and Lukas Eder for getting this up and running! The content of this experimental work now lives on as part of the official https://github.com/neo4j/neo4j-jdbc[Neo4j JDBC Driver], see the https://github.com/neo4j/neo4j-jdbc/tree/main/neo4j-jdbc-translator[translator module].

= Sql2Cypher Experimental Transpiler from SQL to Cypher

This library is an experiment for converting SQL statements (first only read statements) to the appropriate Cypher equivalent.

It is currently in a pre-alpha stage.

== Example

For example:

[source,sql]

SELECT t.a, t.b FROM my_table AS t WHERE t.a = 1

can be translated into

[source,cypher]

MATCH (T:MY_TABLE) WHERE T.A = 1 RETURN T.A, T.B

More examples can be found in the link:src/test/resources[TCK].

== Download

Please go to https://github.com/neo4j-contrib/sql2cypher/releases/tag/early-access[the early access download] where we offer a bunch of binaries for various operating systems and architectures. These binaries come with a dedicated and prepackaged JVM, no need to install Java separately.

Here's an example for macOS on Apple silicon, please adapt as necessary for your system and architecture:

[source,bash]

curl -LO https://github.com/neo4j-contrib/sql2cypher/releases/download/early-access/sql2cypher-1.0-SNAPSHOT-osx-aarch_64.zip mkdir -p sql2cypher bsdtar xvf sql2cypher-1.0-SNAPSHOT-osx-aarch_64.zip --strip-components=1 -C sql2cypher ./sql2cypher/bin/sql2cypher -V

== Usage

[source,console]

Usage: sql2cypher [-hV] [--disable-pretty-printing] [--parse-name-case=] [--sql-dialect=] [--table-to-label-mapping=]... [COMMAND] Translates SQL statements to Cypher queries.

Any valid SQL statement that should be translated to Cypher --parse-name-case= How to parse names; valid values are: AS_IS, LOWER, LOWER_IF_UNQUOTED, UPPER, UPPER_IF_UNQUOTED, DEFAULT and the default is LOWER_IF_UNQUOTED --table-to-label-mapping= A table name that should be mapped to a specific label, repeat for multiple mappings --sql-dialect= The SQL dialect to use for parsing; valid values are: DEFAULT, CUBRID, DERBY, FIREBIRD, H2, HSQLDB, IGNITE, MARIADB, MYSQL, POSTGRES, SQLITE, YUGABYTEDB and the default is DEFAULT --disable-pretty-printing Disables pretty printing -h, --help Show this help message and exit. -V, --version Print version information and exit. Commands: help Display help information about the specified command. ---- == Build Please head over to our link:CONTRIBUTING.adoc[contributing instruction] to learn about build requirements, how to build this project and additional topics like native image with GraalVM. == Dependencies * https://github.com/jOOQ[jOOQ - SQL DSL] * https://github.com/neo4j-contrib/cypher-dsl[Neo4j Cypher-DSL] * https://github.com/remkop/picocli[PicoCli]