Skip to content

Commit 2235d12

Browse files
authored
Add pg2-core and add graal-build-time to Pedestal (#65)
* add pg2-core * add graal-build-time to pedestal to check incompatibility with --allow-incomplete-classpath * update readme * lint
1 parent 90eed57 commit 2235d12

File tree

8 files changed

+130
-1
lines changed

8 files changed

+130
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Here the list of libraries tested:
5959
| :white_check_mark: | [claypoole](./claypoole) | Claypoole: Threadpool tools for Clojure | |
6060
| :white_check_mark: | [upit](./upit) | Very very simple library to initialise your app stack. | |
6161
| :white_check_mark: | [zetasketch](./zetasketch) | Sketch data structures like HLL | requires reflect-config.json |
62+
| :white_check_mark: | [pg2-core](./pg2-core) | A Fast PostgreSQL Driver For Clojure | |
6263

6364

6465
More libraries to come (*PRs are welcome*).

pedestal/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ Test with:
1717

1818
## Results
1919

20+
Pedestal don't work without `--initialize-at-build-time` but it does not conflict with the usage of `graal-build-time`.
21+
2022
`[io.pedestal.http :as http]` :white_check_mark:
23+
2124
`[io.pedestal.jetty :as jetty]` :white_check_mark:
25+
2226
`[io.pedestal.http.body-params :as body-params]` :white_check_mark:
27+
2328
`[io.pedestal.interceptor :as pedestal.interceptor]` :white_check_mark:

pedestal/project.clj

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
:paths ["src"]
44
:dependencies [[org.clojure/clojure "1.12.0"]
55
[io.pedestal/pedestal.service "0.7.2"]
6-
[io.pedestal/pedestal.jetty "0.7.2"]]
6+
[io.pedestal/pedestal.jetty "0.7.2"]
7+
[com.github.clj-easy/graal-build-time "1.0.5"]]
78

89
:main simple.main
910

@@ -22,6 +23,7 @@
2223
"--allow-incomplete-classpath"
2324
"--initialize-at-build-time"
2425
"--enable-url-protocols=http,https"
26+
"--features=clj_easy.graal_build_time.InitClojureClasses"
2527
"-Dio.pedestal.log.defaultMetricsRecorder=nil"
2628
"-jar" "./target/${:uberjar-name:-${:name}-${:version}-standalone.jar}"
2729
"-H:ReflectionConfigurationFiles=reflect-config.json"

pg2-core/.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/target
2+
/classes
3+
/checkouts
4+
profiles.clj
5+
pom.xml
6+
pom.xml.asc
7+
*.jar
8+
*.class
9+
/.lein-*
10+
/.nrepl-port
11+
.hgignore
12+
.hg/
13+
/pg2.iml
14+
/.idea/
15+
/pg2-core.iml

pg2-core/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# PG2
2+
3+
Testing whether [pg2](https://github.com/igrishaev/pg2) library can be used in a native binary image with GraalVM(23).
4+
5+
## Usage
6+
7+
Currently testing:
8+
9+
[com.github.igrishaev/pg2-core "0.1.19"]
10+
11+
Test with (requires a local GraalVM installation):
12+
13+
- You need to start the PostgreSQL container before executing the bynary result: `docker compose up -d`
14+
15+
- Generating and executing the image: ```lein do clean, uberjar, native, run-native```
16+
17+
## Results
18+
19+
`[pg.core :as pg]` :white_check_mark:
20+
`[pg.pool :as pool]` :white_check_mark:

pg2-core/docker-compose.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
postgres:
3+
image: postgres
4+
container_name: postgres
5+
environment:
6+
POSTGRES_PASSWORD: password
7+
POSTGRES_USER: postgres
8+
POSTGRES_DB: postgres-db
9+
ports:
10+
- "5432:5432"

pg2-core/project.clj

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(defproject pg2-core "0.1.0-SNAPSHOT"
2+
3+
:dependencies [[org.clojure/clojure "1.12.0"]
4+
[com.github.igrishaev/pg2-core "0.1.19"]
5+
[com.github.clj-easy/graal-build-time "1.0.5"]]
6+
7+
:main pg2-core.main
8+
9+
:uberjar-name "pg2-core.jar"
10+
11+
:profiles {:uberjar {:aot :all}
12+
:dev {:plugins [[lein-shell "0.5.0"]]}}
13+
14+
:aliases
15+
{"native"
16+
["shell"
17+
"native-image"
18+
"--no-fallback"
19+
"--allow-incomplete-classpath"
20+
"--report-unsupported-elements-at-runtime"
21+
"--features=clj_easy.graal_build_time.InitClojureClasses"
22+
"-jar" "./target/${:uberjar-name:-${:name}-${:version}-standalone.jar}"
23+
"-H:Name=./target/${:name}"]
24+
25+
"run-native" ["shell" "./target/${:name}"]})

pg2-core/src/pg2_core/main.clj

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
(ns pg2-core.main
2+
(:gen-class)
3+
(:require [pg.core :as pg]
4+
[pg.pool :as pool]))
5+
6+
(def config
7+
{:host "localhost"
8+
:port 5432
9+
:user "postgres"
10+
:password "password"
11+
:database "postgres-db"})
12+
13+
(defn create-connection [config]
14+
(pg/connect config))
15+
16+
(defn create-table! [conn]
17+
(pg/execute conn "DROP TABLE IF EXISTS students")
18+
(pg/execute conn "CREATE TABLE IF NOT EXISTS students (name VARCHAR(100) NOT NULL)"))
19+
20+
(defn insert-student! [conn name]
21+
(pg/execute conn
22+
"INSERT INTO students (name) VALUES ($1)
23+
returning *"
24+
{:params [name]}))
25+
26+
(defn lookup [conn name]
27+
(pg/execute conn
28+
"SELECT * FROM students WHERE name = $1"
29+
{:params [name]}))
30+
31+
(defn using-conn []
32+
(println "----Using Connection----")
33+
(println "PG2 Connection:" (create-connection config))
34+
(let [conn (create-connection config)]
35+
(println "Table creation:" (create-table! conn))
36+
(println "Student 'Manuel Gomes' inserted:" (insert-student! conn "Manuel Gomes"))
37+
(println "Query 'Manuel Gomes's Student entity:" (lookup conn "Manuel Gomes"))
38+
(println "Connection closed:" (nil? (pg/close conn)))))
39+
40+
(defn using-conn-from-poll []
41+
(println "----Using Connection Poll----")
42+
(pool/with-pool [pool config]
43+
(pool/with-connection [conn pool]
44+
(println "Table creation:" (create-table! conn))
45+
(println "Student 'Manuel Gomes' inserted:" (insert-student! conn "Manuel Gomes"))
46+
(println "Query 'Manuel Gomes's Student entity:" (lookup conn "Manuel Gomes")))))
47+
48+
(defn -main []
49+
(println "Hello GraalVM.")
50+
(using-conn)
51+
(using-conn-from-poll))

0 commit comments

Comments
 (0)