Skip to content

Commit

Permalink
docs: documentation for jdbc and the dependencies for it (schema anal…
Browse files Browse the repository at this point in the history
…ysis and sql execution)
  • Loading branch information
QuadStingray committed Oct 22, 2024
1 parent 022cc63 commit 6b9dca2
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 194 deletions.
15 changes: 8 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,21 @@ libraryDependencies ++= Seq(
"io.circe" %% "circe-parser"
).map(_ % circeVersion)

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

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

libraryDependencies += "com.github.luben" % "zstd-jni" % "1.5.6-6" % Provided

libraryDependencies += "org.apache.lucene" % "lucene-queryparser" % "10.0.0"
libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "5.1.4"

// MongoDB 5.2.0 not supported for de.bwaldvogel -> https://github.com/bwaldvogel/mongo-java-server/issues/233
val MongoJavaServerVersion = "1.45.0"

libraryDependencies += "de.bwaldvogel" % "mongo-java-server" % MongoJavaServerVersion % Provided

libraryDependencies += "de.bwaldvogel" % "mongo-java-server-h2-backend" % MongoJavaServerVersion % Provided

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

libraryDependencies += "com.github.luben" % "zstd-jni" % "1.5.6-6" % 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"
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
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"name" : "mongodb-driver",
"organization" : "dev.mongocamp",
"version" : "2.7.1.snapshot",
"author" : "info@mongocamp.dev",
"license" : "Apache-2.0",
"type" : "module",
"repository" : {
"type" : "git",
"url" : "git+https://github.com/MongoCamp/mongodb-driver.git"
"name": "mongodb-driver",
"organization": "dev.mongocamp",
"version": "2.8.0",
"author": "info@mongocamp.dev",
"license": "Apache-2.0",
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/MongoCamp/mongodb-driver.git"
},
"bugs" : {
"url" : "https://github.com/MongoCamp/mongodb-driver/issues"
"bugs": {
"url": "https://github.com/MongoCamp/mongodb-driver/issues"
},
"homepage" : "https://mongodb-driver.mongocamp.dev/",
"scripts" : {
"docs:serve" : "vitepress serve docs --port 5555",
"docs:build" : "pnpm docs:external; vitepress build docs",
"docs:external" : "sh docs/external/fileloader.sh",
"docs:dev" : "pnpm docs:external; vitepress dev docs"
"homepage": "https://mongodb-driver.mongocamp.dev/",
"scripts": {
"docs:serve": "vitepress serve docs --port 5555",
"docs:build": "pnpm docs:external; vitepress build docs",
"docs:external": "sh docs/external/fileloader.sh",
"docs:dev": "pnpm docs:external; vitepress dev docs"
},
"devDependencies" : {
"@iconify-json/fluent-emoji" : "^1.1.18",
"@unocss/preset-icons" : "^0.58.5",
"unocss" : "^0.58.5",
"vitepress" : "1.0.0-rc.45"
"devDependencies": {
"@iconify-json/fluent-emoji": "^1.2.1",
"@unocss/preset-icons": "^0.63.4",
"unocss": "^0.63.4",
"vitepress": "1.4.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ case class MongoPreparedStatement(connection: MongoJdbcConnection) extends Calla
new MongoDbResultSet(null, List.empty, 0)
} else {
var response = queryHolder.run(connection.getDatabaseProvider).results(getQueryTimeout)
if (response.isEmpty && queryHolder.selectFunctionCall) {
if (response.isEmpty && queryHolder.hasFunctionCallInSelect) {
val emptyDocument = mutable.Map[String, Any]()
queryHolder.getKeysForEmptyDocument.foreach(key => {
emptyDocument.put(key, null)
Expand Down
Loading

0 comments on commit 6b9dca2

Please sign in to comment.