Skip to content
New issue

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

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

Already on GitHub? # to your account

Jdbc driver #69

Merged
merged 22 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4d18469
chore: Dependency Update and changes for mongo-scala-driver 5.0.0
QuadStingray Mar 4, 2024
094f50d
chore: plugins updated 5 dependency updates for project
QuadStingray Mar 4, 2024
3df7127
style: reformat code with scalafmt
QuadStingray Mar 4, 2024
9e73ce1
feat: support lucene query converter support search with long value o…
QuadStingray Mar 4, 2024
c6fe36b
feat(jdbc): start implementing jdbc driver for mongodb
QuadStingray Mar 6, 2024
48bf9b4
docs: update vitepress
QuadStingray Mar 11, 2024
36a4307
feat: sql converter with execution
QuadStingray Apr 17, 2024
5f5c1ab
chore: 7 dependency updates for mongodb-driver
QuadStingray Apr 17, 2024
0c8861a
refactor: added serverAddressList as connection option
QuadStingray Apr 26, 2024
0408c7e
feat: implemented jdbc driver methods
QuadStingray Apr 26, 2024
0a7a7de
feat: added show databases and show tables implementation
QuadStingray May 3, 2024
cf5aa46
feat: execute sql with database selection
QuadStingray May 4, 2024
1df9e97
style: reformat code with scalafmt
QuadStingray Jun 10, 2024
8e24215
feat: detect schema
QuadStingray Jun 13, 2024
2ecc276
feat: implemented jdbc driver methods
QuadStingray Oct 16, 2024
8a39da8
feat: compatibility for scala 2.12
QuadStingray Oct 17, 2024
08e247f
test: some errors on rerun tests
QuadStingray Oct 20, 2024
3948d48
chore: 13 dependency updates for mongodb-driver
QuadStingray Oct 20, 2024
022cc63
feat: refactor for jsqlparser 5.0
QuadStingray Oct 21, 2024
6b9dca2
docs: documentation for jdbc and the dependencies for it (schema anal…
QuadStingray Oct 22, 2024
d2f9727
fix: fix not compiling test for schema
QuadStingray Oct 22, 2024
51aa927
refactor(java): drop java 11 and 19 support because `org.apache.lucen…
QuadStingray Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main_test_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
mongodb-version: ['4.4', '5.0', '6.0', '7.0']
java: [ '11', '17' ]
java: [ '21', '23' ]
steps:
- uses: actions/checkout@main
- name: Setup TimeZone
Expand Down
44 changes: 22 additions & 22 deletions .github/workflows/other_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
mongodb-version: ['4.4', '5.0', '6.0', '7.0']
java: [ '11', '17' ]
mongodb-version: [ '4.4', '5.0', '6.0', '7.0' ]
java: [ '21', '23' ]
steps:
- uses: actions/checkout@main
- name: Set up JDK ${{ matrix.Java }}
uses: coursier/setup-action@main
with:
jvm: corretto:${{ matrix.Java }}
apps: sbt scala scalac
- name: Setup TimeZone
uses: MathRobin/timezone-action@v1.1
with:
timezoneLinux: "Europe/Berlin"
timezoneMacos: "Europe/Berlin"
timezoneWindows: "W. Europe Standard Time"
- name: Start MongoDB ${{ matrix.mongodb-version }}
uses: MongoCamp/mongodb-github-action@main
with:
mongodb-version: ${{ matrix.mongodb-version }}
- name: Run tests
run: |
timedatectl
sbt +test
- uses: actions/checkout@main
- name: Set up JDK ${{ matrix.Java }}
uses: coursier/setup-action@main
with:
jvm: corretto:${{ matrix.Java }}
apps: sbt scala scalac
- name: Setup TimeZone
uses: MathRobin/timezone-action@v1.1
with:
timezoneLinux: "Europe/Berlin"
timezoneMacos: "Europe/Berlin"
timezoneWindows: "W. Europe Standard Time"
- name: Start MongoDB ${{ matrix.mongodb-version }}
uses: MongoCamp/mongodb-github-action@main
with:
mongodb-version: ${{ matrix.mongodb-version }}
- name: Run tests
run: |
timedatectl
sbt +test
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ class RestaurantDemoSpec extends Specification with RestaurantDemoDatabaseFuncti

## Run Tests
```shell
docker run --publish 27017:27017 mongocamp/mongodb:latest;
sbt test;
docker run -d --publish 27017:27017 --name mongodb mongocamp/mongodb:latest;
sbt test;
docker rm -f mongodb;
```

## Supporters
Expand Down
35 changes: 21 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ developers := List(

licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html"))

crossScalaVersions := Seq("2.13.13", "2.12.17")
crossScalaVersions := Seq("2.13.15", "2.12.20")

scalaVersion := crossScalaVersions.value.head

Expand All @@ -61,41 +61,48 @@ resolvers += "Sonatype OSS Snapshots".at("https://oss.sonatype.org/content/repos

// Test

libraryDependencies += "org.specs2" %% "specs2-core" % "4.20.5" % Test
libraryDependencies += "org.specs2" %% "specs2-core" % "4.20.9" % Test

libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.5.0" % Test
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.5.11" % Test

libraryDependencies += "joda-time" % "joda-time" % "2.12.7" % Test
libraryDependencies += "joda-time" % "joda-time" % "2.13.0"

val circeVersion = "0.14.6"
val circeVersion = "0.14.10"

libraryDependencies ++= Seq(
"io.circe" %% "circe-core",
"io.circe" %% "circe-generic",
"io.circe" %% "circe-parser"
).map(_ % circeVersion % Test)
).map(_ % circeVersion)

libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "4.11.1"
libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "5.1.4"

libraryDependencies += "org.xerial.snappy" % "snappy-java" % "1.1.10.5" % Provided
// MongoDB 5.2.0 not supported for de.bwaldvogel -> https://github.com/bwaldvogel/mongo-java-server/issues/233
val MongoJavaServerVersion = "1.45.0"

libraryDependencies += "com.github.luben" % "zstd-jni" % "1.5.5-11" % Provided
libraryDependencies += "de.bwaldvogel" % "mongo-java-server" % MongoJavaServerVersion % Provided

libraryDependencies += "org.apache.lucene" % "lucene-queryparser" % "9.10.0"
libraryDependencies += "de.bwaldvogel" % "mongo-java-server-h2-backend" % MongoJavaServerVersion % Provided

val MongoJavaServerVersion = "1.44.0"
libraryDependencies += "org.xerial.snappy" % "snappy-java" % "1.1.10.7" % Provided

libraryDependencies += "de.bwaldvogel" % "mongo-java-server" % MongoJavaServerVersion % Provided
libraryDependencies += "com.github.luben" % "zstd-jni" % "1.5.6-6" % Provided

libraryDependencies += "de.bwaldvogel" % "mongo-java-server-h2-backend" % MongoJavaServerVersion % Provided
libraryDependencies += "org.apache.lucene" % "lucene-queryparser" % "10.0.0"

libraryDependencies += "com.github.pathikrit" %% "better-files" % "3.9.2"

libraryDependencies += "com.typesafe" % "config" % "1.4.3"

libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.5"

libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "2.11.0"
libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "2.12.0"

libraryDependencies += "com.vdurmont" % "semver4j" % "3.1.0"

libraryDependencies += "com.github.jsqlparser" % "jsqlparser" % "5.0"

libraryDependencies += "org.liquibase" % "liquibase-core" % "4.29.2" % Test

buildInfoPackage := "dev.mongocamp.driver.mongodb"

Expand Down
2 changes: 2 additions & 0 deletions build_release.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import sbtrelease.ReleasePlugin.runtimeVersion

import scala.sys.process.*

releaseVersionBump := sbtrelease.Version.Bump.NextStable

val gitAddAllTask = ReleaseStep(action = st => {
"git add .".!
st
Expand Down
95 changes: 0 additions & 95 deletions changelog/config.js

This file was deleted.

9 changes: 0 additions & 9 deletions changelog/header.hbs

This file was deleted.

14 changes: 12 additions & 2 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ function nav() {
{text: 'MongoDAO', link: '/documentation/mongo-dao/'},
{text: 'GridFsDAO', link: '/documentation/gridfs-dao/'},
{text: 'Collection', link: '/documentation/collection/'},
{text: 'LocalServer', link: '/documentation/local-server'}
{text: 'LocalServer', link: '/documentation/local-server'},
{text: 'SQL', link: '/documentation/sql'}
]
},
{
Expand Down Expand Up @@ -128,9 +129,18 @@ function sidebarDocumentation() {
items: [
{text: 'Introduction', link: '/documentation/collection/'},
{text: 'Aggregation', link: '/documentation/collection/aggregation'},
{text: 'Pagination', link: '/documentation/collection/pagination'}
{text: 'Pagination', link: '/documentation/collection/pagination'},
{text: 'Schema analyse', link: '/documentation/collection/analyse-schema'},
]
},
{
text: 'SQL', items: [
{text: 'Query Holder', link: '/documentation/sql/queryholder'},
{text: 'JDBC driver', link: '/documentation/sql/jdbc-driver'},
],
collapsible: true,
collapsed: true,
},
{
text: 'LocalServer',
link: '/documentation/local-server'
Expand Down
18 changes: 18 additions & 0 deletions docs/documentation/collection/analyse-schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Analyse Schema
The driver supports an automated detection of the schema of an existing collection. The schema is used to detect the types of the columns.

## Usage

### Schema Analysis
Analyse a collection to detect the values for each field and the percentage distribution of the types.

<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/schema/SchemaSpec.scala#schema-analysis

### Detect Schema
The Schema Detector can be used to detect the schema of a collection and is based on [Schema Anaysis](analyse-schema.md#schema-analysis). The schema is used to detect the types of the columns and generate a [JSON Schema](https://json-schema.org) for the collection. In case of multiple types of a field the Generation of the JSON Schema use the type with the most elements.

:::tip
The [JSON Schema](https://json-schema.org) format can be use to validate or generate data, as well to secure your [Mongo Collection](https://www.mongodb.com/docs/manual/core/schema-validation/).
:::

<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/schema/SchemaSpec.scala#schema-explorer
5 changes: 5 additions & 0 deletions docs/documentation/sql/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SQL Support

Since Version 2.7.1 the driver supports [SQL queries](queryholder.md) on MongoDB. The SQL queries are converted to MongoDB queries and could executed on the MongoDB database.

The driver also supports a [JDBC driver](jdbc-driver.md) to use the SQL queries in your application and migrate your database with liquibase for example.
16 changes: 16 additions & 0 deletions docs/documentation/sql/jdbc-driver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# JDBC driver

The JDBC driver is a way to use the SQL queries in your application and run them like a 'normal' SQL database. The driver is based on the [MongoSqlQueryHolder](queryholder.md) to convert the SQL query to a Mongo query and execute it on the MongoDB database.

## Usage

### Register Driver
In some environments you have to register the driver manually. This is the case for example in the tests.

<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/jdbc/BaseJdbcSpec.scala#register-driver

After the driver is registered you can use the driver like a normal [JDBC driver](https://www.baeldung.com/java-jdbc).

:::tip
The most default sql statements are supported, but because the difference between MongoDb and SQL the driver can't support SQL statements with subselects.
:::
24 changes: 24 additions & 0 deletions docs/documentation/sql/queryholder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SQL Converter to Mongo Query

The MongoSqlQueryHolder provides a way to convert a SQL query to a Mongo query and execute it on a Mongo database.

## Usage

Initialize the query holder with the SQL query you want to analyse or execute.

<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/sql/SelectSqlSpec.scala#initialize-query-holder

In most cases you simply want to run the query and get the result as a `Seq[Document]`.
::: tip
The method run returns a classical MongoDb Observable use the implicits to convert it to a `Seq[Document]`.
:::
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/sql/SelectSqlSpec.scala#query-holder-run

You can also get the information about the collection and the keys that are used in the query.

<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/sql/SelectSqlSpec.scala#extract-collection
<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/sql/SelectSqlSpec.scala#select-keys

In some cases you need the information about the function calls in the query, for example in your own [jdbc driver](jdbc-driver.md) implementation. Because the difference of MongoDb and SQL for example a sql `select count(*) from empty-collection` is a list documents with one element and the MongoDb has no document in it.

<<< @/../src/test/scala/dev/mongocamp/driver/mongodb/sql/SelectSqlSpec.scala#has-function-call
4 changes: 3 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ hero:
link: /documentation/getting-started
- theme: alt
text: View on GitHub
link: https://github.com/vuejs/vitepress
link: https://github.com/MongoCamp/mongodb-driver

features:
- title: Easy Config
details: Easy Database Config with provider and MongoConfig
- title: SQL Support
details: Support for SQL Queries on MongoDB and JDBC Driver
- title: DAO Pattern
details: Implement the DAO Pattern for simple MongoDB usage [MongoDAO.
- title: Pagination
Expand Down
Loading