Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get query's tables and columns #3

Merged
merged 15 commits into from
Feb 20, 2024
Merged
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
restore-keys: |
v1-${{ hashFiles('./deps.edn') }}-
v1-
- run: clojure -T:build compile
name: Compile Java files
- run: clojure -X:dev:test
name: Run tests
env:
Expand Down Expand Up @@ -102,6 +104,8 @@ jobs:
restore-keys: |
v1-${{ hashFiles('./deps.edn') }}-
v1-
- run: clojure -T:build compile
name: Compile Java files
- run: clojure -M:check
name: Check namespaces

Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,29 @@ Macaw is a limited Clojure wrapper for
[JSqlParser](https://github.com/JSQLParser/JSqlParser). Similar to its parrot
namesake, it's intelligent, can be taught to speak SQL, and has many colors
(supports many dialects).


## Building

To build a local JAR, use

```
./bin/build-jar
```

This will create a JAR in the `target` directory.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be expanded once I set up Clojars.


## Working with the Java files

To compile the Java files, use

```
./bin/compile-java
```

If you're working on Macaw and make changes to a Java file, you must:

1. Recompile
2. Restart your Clojure REPL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no way to improve this workflow in 2024? 😢 (outside scope of this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly with the right ns refresh, but I haven't worked it out :(


for the changes to take effect.
25 changes: 25 additions & 0 deletions bin/build-jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
if [[ -n "${TRACE-}" ]]; then
set -o xtrace
fi

if [ $# -ge 1 ] && [[ "$1" =~ ^-*h(elp)?$ ]]; then
echo 'Usage: ./bin/build-jar

Build a JAR

'
exit
fi

# Ensure we're in the project root
cd "$(dirname "$0")"/..

main() {
clj -T:build jar
}

main "$@"
25 changes: 25 additions & 0 deletions bin/java-compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
if [[ -n "${TRACE-}" ]]; then
set -o xtrace
fi

if [ $# -ge 1 ] && [[ "$1" =~ ^-*h(elp)?$ ]]; then
echo 'Usage: ./bin/java-compile

Compiles all the Java files used in the project so that they can be used in local Clojure development. To build a JAR, use ./build-jar instead.

'
exit
fi

# Ensure we're in the project root
cd "$(dirname "$0")"/..

main() {
clj -T:build compile
}

main "$@"
47 changes: 47 additions & 0 deletions build.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
;; Further info: https://clojure.org/guides/tools_build#_mixed_java_clojure_build

(ns build
(:require
[clojure.java.shell :as sh]
[clojure.string :as str]
[clojure.tools.build.api :as b]))

(def lib 'metabase/macaw)

(def major-minor-version "0.1")

(defn commit-number []
(or (-> (sh/sh "git" "rev-list" "HEAD" "--count")
:out
str/trim
parse-long)
"9999-SNAPSHOT"))
tsmacdonald marked this conversation as resolved.
Show resolved Hide resolved

(def version (str major-minor-version \. (commit-number)))
(def target "target")
(def class-dir (format "%s/classes" target))

(def jar-file (format "target/%s-%s.jar" (name lib) version))

(def basis (delay (b/create-basis {:project "deps.edn"})))

(defn clean [_]
(b/delete {:path target}))

(defn compile [_]
(b/javac {:src-dirs ["java"]
:class-dir class-dir
:basis @basis
:javac-opts ["--release" "11"]}))

(defn jar [_]
(compile nil)
(b/write-pom {:class-dir class-dir
:lib lib
:version version
:basis @basis
:src-dirs ["src"]})
(b/copy-dir {:src-dirs ["src" "resources"]
:target-dir class-dir})
(b/jar {:class-dir class-dir
:jar-file jar-file}))
6 changes: 3 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{:paths
["src" "resources"]
["src" "java" "resources" "target/classes"]

:deps
{com.github.jsqlparser/jsqlparser {:mvn/version "4.8"}} ; The actual SQL Parser to wrap!
Expand Down Expand Up @@ -41,8 +41,8 @@
{:deps {com.github.camsaul/whitespace-linter {:sha "e35bc252ccf5cc74f7d543ef95ad8a3e5131f25b"}}
:ns-default whitespace-linter
:exec-fn whitespace-linter/lint
:exec-args {:paths ["deps.edn" "src" "test" ".github"]
:include-patterns ["\\.clj[cs]?$" "\\.edn$" "\\.yaml$" "\\.md$"]}}
:exec-args {:paths ["deps.edn" "src" "java" "test" ".github"]
:include-patterns ["\\.clj[cs]?$" "\\.edn$" "\\.java$" "\\.yaml$" "\\.md$"]}}

;; Run tests
;;
Expand Down
Loading
Loading