Skip to content
This repository was archived by the owner on Nov 11, 2022. It is now read-only.

Commit 47c5488

Browse files
author
Elliot
committed
First somewhat working version. mssql + oracle + postgresql
1 parent c2a34a8 commit 47c5488

File tree

444 files changed

+173056
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

444 files changed

+173056
-140
lines changed

.circleci/config.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
version: 2.1
2+
3+
commands:
4+
build_driver:
5+
description: "package up a jdbc driver as a go sql driver"
6+
parameters:
7+
driver_name:
8+
type: string
9+
artifacts:
10+
type: string
11+
default: ""
12+
steps:
13+
- run: wrapper/scripts/wrap-<< parameters.driver_name >>.sh
14+
- persist_to_workspace:
15+
root: .
16+
paths:
17+
- << parameters.driver_name >>/<< parameters.artifacts >>
18+
19+
jobs:
20+
linux:
21+
working_directory: ~/work
22+
docker:
23+
- image: raonigabriel/graalvm-playground:19.0.0
24+
environment:
25+
_JAVA_OPTIONS: "-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -Xms1000m -Xmx1436m -XX:MaxMetaspaceSize=1436m -XX:ParallelGCThreads=1 -XX:ConcGCThreads=1 -Djava.util.concurrent.ForkJoinPool.common.parallelism=2"
26+
steps:
27+
- checkout
28+
- restore_cache:
29+
key: gdbc-linux-{{ checksum "wrapper/pom.xml" }}
30+
- build_driver:
31+
driver_name: postgresql
32+
- build_driver:
33+
driver_name: mssql
34+
- build_driver:
35+
driver_name: oracle
36+
- save_cache:
37+
paths:
38+
- ~/.m2
39+
key: gdbc-linux-{{ checksum "wrapper/pom.xml" }}
40+
41+
mac:
42+
working_directory: ~/work
43+
macos:
44+
xcode: "10.0.0"
45+
steps:
46+
- checkout
47+
- restore_cache:
48+
key: gdbc-mac-{{ checksum "wrapper/pom.xml" }}
49+
- run: wrapper/setup-mac.sh
50+
- build_driver:
51+
driver_name: postgresql
52+
artifacts: libgdbc-postgresql.dylib
53+
- build_driver:
54+
driver_name: mssql
55+
artifacts: libgdbc-mssql.dylib
56+
- build_driver:
57+
driver_name: oracle
58+
artifacts: libgdbc-oracle.dylib
59+
- save_cache:
60+
paths:
61+
- ~/.m2
62+
key: gdbc-mac-{{ checksum "wrapper/pom.xml" }}
63+
64+
commit_drivers:
65+
docker:
66+
- image: circleci/golang:latest
67+
steps:
68+
- checkout
69+
- attach_workspace:
70+
at: .
71+
- run: git config user.email "elliot@identitii.com"
72+
- run: git config user.name "Elliot Shepherd (CI)"
73+
- run: git status
74+
- run: git add .
75+
- run: git status
76+
- run: git commit -m "[auto] update packaged drivers [skip ci]"
77+
- run: git push --set-upstream origin ${CIRCLE_BRANCH}
78+
79+
workflows:
80+
version: 2
81+
build:
82+
jobs:
83+
- linux
84+
- mac
85+
- approve_release:
86+
type: approval
87+
requires:
88+
- linux
89+
- mac
90+
- commit_drivers:
91+
requires:
92+
- approve_release

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
wrapper/target
22
wrapper/.settings
33
wrapper/.classpath
4-
wrapper/.project
4+
wrapper/.project
5+
\.vscode/
6+
examples/sqlx/sqlx
7+
\.dockercache
8+
wrapper-old/
9+
10+
wrapper/graal\.tar\.gz
11+
12+
wrapper/graalvm-ce-19\.1\.0/

.gitlab-ci.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
cache:
2+
paths:
3+
- .m2/
4+
5+
variables:
6+
MAVEN_OPTS: "-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dmaven.repo.local=.m2"
7+
8+
stages:
9+
- build
10+
- build_tests
11+
- test
12+
13+
mssql:
14+
stage: build
15+
image: raonigabriel/graalvm-playground:19.0.0
16+
script: wrapper/scripts/wrap-mssql.sh
17+
artifacts:
18+
paths:
19+
- mssql/
20+
21+
oracle:
22+
stage: build
23+
image: raonigabriel/graalvm-playground:19.0.0
24+
script: wrapper/scripts/wrap-oracle.sh
25+
artifacts:
26+
paths:
27+
- oracle/
28+
29+
postgresql:
30+
stage: build
31+
image: raonigabriel/graalvm-playground:19.0.0
32+
script: wrapper/scripts/wrap-postgresql.sh
33+
artifacts:
34+
paths:
35+
- postgresql/
36+
37+
mssql_test:
38+
stage: test
39+
image: golang:1.12
40+
services:
41+
- name: registry.gitlab.com/identitii/gdbc/mssql:2017-CU12-ubuntu
42+
alias: db
43+
dependencies:
44+
- mssql
45+
variables:
46+
ACCEPT_EULA: "Y"
47+
SA_PASSWORD: yourStrong(!)Password
48+
MSSQL_DB: test
49+
MSSQL_USER: root
50+
MSSQL_PASSWORD: yourStrong(!)Password
51+
MSSQL_HOST: db
52+
script: ./benchmark.sh mssql
53+
54+
oracle_test:
55+
stage: test
56+
image: golang:1.12
57+
services:
58+
- name: registry.gitlab.com/identitii/gdbc/oracle:12c-r1
59+
alias: db
60+
dependencies:
61+
- oracle
62+
variables:
63+
ORACLE_DB: xe
64+
ORACLE_USER: GDBCUSER
65+
ORACLE_PASSWORD: password
66+
ORACLE_HOST: db
67+
script: sleep 30 && ./benchmark.sh oracle
68+
69+
postgresql_test:
70+
stage: test
71+
image: golang:1.12
72+
services:
73+
- name: postgres:latest
74+
alias: db
75+
dependencies:
76+
- postgresql
77+
variables:
78+
POSTGRES_DB: test
79+
POSTGRES_USER: root
80+
POSTGRES_PASSWORD: password
81+
POSTGRES_HOST: db
82+
script: ./benchmark.sh postgresql

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2019 identiii Ltd.
1+
Copyright (c) 2019 identitii Ltd.
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

README.md

Lines changed: 98 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,108 @@
1-
(VERY MUCH WIP - This doesn't work yet)
1+
2+
3+
<img src="logo.png" width="25%" align="right"/>
24

35
# GDBC - Golang JDBC Driver Wrapper
46

5-
## What?
6-
Allows you to load and use Java database drivers from go.
7+
[![CircleCI](https://img.shields.io/circleci/build/github/identitii/gdbc.svg?token=59c033cd63c3d550c1a21cd6bc3bef5023a09c5a)](https://circleci.com/gh/identitii/gdbc/tree/master)
8+
[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/identitii/gdbc)
9+
[![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/identitii/gdbc/master/LICENSE)
10+
11+
Load and use JDBC Java database drivers from go. Without Java.
12+
13+
## IMPORTANT NOTES:
14+
- This is VERY MUCH WIP - it 'works' but has barely been tested/benchmarked. PRs/bug reports/feature requests gratefully received.
15+
- This repository will change. Do not rely on it yet. Compatibility is not guaranteed.
16+
- Very likely the drivers will be split into their own modules or repos.
17+
18+
19+
### Supported Drivers
20+
21+
More may be supported, but these are the ones we package, test, and distribute.
22+
23+
- Microsoft SQL Server (mssql)
24+
- com.microsoft.sqlserver:mssql-jdbc:7.3.0.jre8-preview
25+
- Oracle DB (oracle)
26+
- com.oracle:ojdbc6:12.1.0.1
27+
- PostgreSQL (postgresql)
28+
- org.postgresql:postgresql:42.2.5.jre6
29+
30+
### Usage
31+
32+
Import oracle, mssql, or postgresql driver.
33+
34+
```golang
35+
import _ "github.com/identitii/gdbc/oracle"
36+
```
37+
38+
Use `gdbc-(oracle|mssql|postgresql)` as the driver name, and pass in the JDBC connection string (which is passed straight through to the driver)
39+
40+
```golang
41+
pool, err = sql.Open("gdbc-oracle", "jdbc:oracle:thin:user/password@host:1521:sid")
42+
```
43+
44+
When starting your application, it will look for the compiled driver shared library in the current directory (@executable_path)
45+
e.g. libgdbc-postgresql.dylib on mac, or libgdbc-postgresql.so on linux.
46+
47+
So either put the file in the current directory, or tell it where to find it like this...
48+
49+
```bash
50+
DYLD_LIBRARY_PATH="path/to/the/shared/library" go run main.go
51+
```
52+
53+
### Benchmarks
54+
55+
The one tiny benchmark so far has these GDBC drivers about 30% faster than the pure go drivers on mac, and about 30% slower than the pure go drivers on linux.
56+
57+
### How is this done?
58+
59+
GraalVM to package the java driver as a native library, then CGO to communicate with it.
60+
61+
### Why is this done?
62+
63+
Because there are some databases that don't have or have incomplete or unsupported go drivers.
64+
65+
Initially started in order to get a fully featured oracle driver.
66+
67+
Also because it is fun.
68+
69+
### TODO
70+
71+
- [ ] Find trusted maven repositories to download drivers
72+
- [ ] Transaction isolation level config via driver
73+
- [ ] Distribute binary drivers (.dylib and .so, and .dll?) via separate repositories
74+
- [x] Cut down the binary size from 120mb to something slightly more reasonable. (done: now 30mb)
75+
- [x] Get rid of -H:IncludeResources=".*"
76+
- [ ] Extend test suite, find existing suite?
77+
- [ ] Test memory usage/leaking
78+
- [x] Linux builds
79+
- [ ] Windows builds (waiting on graalvm support)
80+
- [x] CI/CD
81+
- [ ] Implement further interfaces
82+
- [x] sql/driver.Pinger
83+
- [ ] sql/driver.RowsColumnTypeDatabaseTypeName
84+
- [ ] sql/driver.RowsColumnTypeLength
85+
- [ ] sql/driver.RowsColumnTypeNullable
86+
- [ ] sql/driver.RowsColumnTypePrecisionScale
87+
- [ ] sql/driver.NamedValueChecker
88+
- [x] Allow driver specific extensions
89+
- [ ] Oracle continuous query notification - https://docs.oracle.com/database/121/JJDBC/dbchgnf.htm#JJDBC28815
90+
91+
#### Drivers
92+
- [ ] sqlite? ("org.sqlite.JDBC" "jdbc:sqlite::memory:" "SELECT 1;")
93+
94+
### Who Created This
795

8-
## How?
9-
Uses GraalVM to compile the driver as a native library, then CGO to communicate with it.
96+
<img src="https://identitii.com/wp-content/uploads/2018/12/logo_onwh.svg" width="25%">
1097

11-
## Why?
12-
Because there are some databases that don't have go drivers.
98+
We're a fintech startup based in Sydney, Australia.
1399

14-
## Why really?
15-
Because it's fun.
100+
Find this project interesting? Why not come work with us.
16101

17-
## When?
18-
This is a side project, so it may take a while.
102+
https://identitii.com/careers/
19103

20-
## Who?
104+
### Thanks
21105

22-
identitii. We're a fintech startup in Sydney.
23-
If this kind of thing excites you, come work for us.
106+
https://github.com/japettyjohn/go-jdbc, which itself is partly based on https://github.com/xoba/goutil
24107

25-
https://identitii.com/careers/
108+
gopher logo by Mario Furmanczyk (mfurmanc on fiverr)

0 commit comments

Comments
 (0)