Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: [ '11', '17', '21' ]
steps:
- uses: actions/checkout@v3.0.0
- name: Setup TimeZone
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/other_test.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: [ '11', '17', '21' ]
steps:
- uses: actions/checkout@v2
- name: Set up JDK ${{ matrix.Java }}
Expand Down
28 changes: 27 additions & 1 deletion .github/workflows/release_and_changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,35 @@ jobs:
body: ${{ steps.changelog.outputs.changes }}
token: ${{ github.token }}

- name: Update versions file
run: |
echo "{\"mongocamp\": \"${{ github.ref_name }}\"}" > ./docs/versions.json;
git add ./docs/versions.json

- name: Commit CHANGELOG.md
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: 'docs: update CHANGELOG.md for ${{ github.ref_name }}'
file_pattern: CHANGELOG.md
file_pattern: CHANGELOG.md

- name: Set up JDK
uses: coursier/setup-action@v1
with:
jvm: graalvm-java17:22.3.3
apps: sbt scala scalac

- name: Install pnpm
uses: pnpm/action-setup@v2.2.1
with:
version: 6.0.2

- name: Build and deploy Docu
env:
CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USER: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.email "ci@mongocamp.dev"
git config --global user.name "MongoCamp CI"
sh ./deploy_ghpages.sh
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "4.11.0"

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

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

libraryDependencies += "org.apache.lucene" % "lucene-queryparser" % "9.8.0"

Expand Down
7 changes: 4 additions & 3 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Unocss from 'unocss/vite'
import {defineConfig} from 'vitepress'
import {version} from '../../package.json'
import {SearchPlugin} from 'vitepress-plugin-search'
import fs from 'fs'

export default defineConfig({
lang: 'en-US',
Expand Down Expand Up @@ -50,6 +49,8 @@ export default defineConfig({
})

function nav() {
var versionInfos = JSON.parse(fs.readFileSync('docs/versions.json', 'utf-8'))

return [
{
text: 'Documentation',
Expand All @@ -63,7 +64,7 @@ function nav() {
]
},
{
text: version,
text: versionInfos.mongocamp,
items: [
{
text: 'Changelog',
Expand Down
1 change: 1 addition & 0 deletions docs/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"mongocamp": "2.6.6"}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name" : "mongodb-driver",
"organization" : "dev.mongocamp",
"version" : "2.6.6.snapshot",
"version" : "2.6.7.snapshot",
"author" : "info@mongocamp.dev",
"license" : "Apache-2.0",
"repository" : {
"type" : "git",
"url" : "git+https://github.com/MongoCamp/mongodb-driver.git"
},
"bugs" : {
"url" : "https://github.com/MongoCamp/mongocamp-driver/issues"
"url" : "https://github.com/MongoCamp/mongodb-driver/issues"
},
"homepage" : "https://mongodb-driver.mongocamp.dev/",
"scripts" : {
Expand Down
8 changes: 4 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.7")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")

Expand All @@ -13,13 +13,13 @@ addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")
addSbtPlugin("com.github.fedragon" % "sbt-todolist" % "0.7")

// Release
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.18")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.21")

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.1.1")

addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")

addSbtPlugin("dev.quadstingray" %% "sbt-json" % "0.6.3")
addSbtPlugin("dev.quadstingray" %% "sbt-json" % "0.6.5")

addDependencyTreePlugin

Expand Down
2 changes: 1 addition & 1 deletion scalastyle-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
</check>
<check level="warning" class="org.scalastyle.scalariform.CyclomaticComplexityChecker" enabled="true">
<parameters>
<parameter name="maximum"><![CDATA[30]]></parameter>
<parameter name="maximum"><![CDATA[35]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.UppercaseLChecker" enabled="true"></check>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.math.BigInteger
import java.time.{ LocalDate, LocalDateTime, ZoneId }
import java.util.Date
import scala.collection.mutable
import scala.concurrent.duration.Duration
import scala.jdk.CollectionConverters._
import scala.util.matching.Regex

Expand All @@ -22,7 +23,7 @@ object BsonConverter {

def lastKeyFromRelation(key: String): String = key.substring(key.lastIndexOf(DocumentKeyDivider) + 1)

def documentValueOption(document: Document, key: String): Option[Any] =
def documentValueOption(document: Document, key: String): Option[Any] = {
if (hasRelation(key)) {
val newKey = newKeyFromRelation(key)
val relation = relationKey(key)
Expand All @@ -36,13 +37,17 @@ object BsonConverter {
None
}
}
else
else {
None
}
}
else if (document.contains(key))
else if (document.contains(key)) {
Some(fromBson(document(key)))
else
}
else {
None
}
}

def updateDocumentValue(document: Document, key: String, value: Any): Document = {
val doc = org.mongodb.scala.bson.collection.mutable.Document(document.toJson())
Expand Down Expand Up @@ -110,6 +115,7 @@ object BsonConverter {
case bytes: Array[Byte] => BsonBinary(bytes)
case r: Regex => BsonRegularExpression(r)
case d: Date => BsonDateTime(d)
case d: Duration => BsonString(d.toString)
case ld: LocalDate =>
BsonDateTime(Date.from(ld.atStartOfDay(ZoneId.systemDefault()).toInstant))
case ldt: LocalDateTime =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package dev.mongocamp.driver.mongodb.bson

import org.bson.BsonValue
import org.joda.time.DateTime
import org.mongodb.scala.bson.{BsonDateTime, BsonNull}
import org.joda.time.{DateTime, Duration}
import org.mongodb.scala.bson.{BsonDateTime, BsonNull, BsonString}

class JodaConverterPlugin extends AbstractConverterPlugin {
override def customClassList: List[Class[_]] = List(classOf[DateTime])
override def customClassList: List[Class[_]] = List(classOf[DateTime], classOf[Duration])

override def toBson(value: Any): BsonValue =
value match {
case dt: DateTime => BsonDateTime(dt.toDate)
case dt: DateTime =>
BsonDateTime(dt.toDate)
case dt: org.joda.time.Duration =>
BsonString(s"${dt.getMillis}ms")
case _ =>
BsonNull()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package dev.mongocamp.driver.mongodb.bson

import org.joda.time.DateTime
import org.specs2.mutable.Specification
import org.specs2.specification.BeforeAfterAll

import scala.concurrent.duration.Duration

class JodaConverterPluginSpec extends Specification with BeforeAfterAll {

sequential

"JodaConverterPlugin" should {

"convert joda dates to bson dates" in {
val dateTime = new DateTime("2023-11-02")
val bsonDocument = BsonConverter.toBson(dateTime)
(bsonDocument.toString must be).equalTo("BsonDateTime{value=1698879600000}")
}

"convert joda duration to bson string" in {
val duration = org.joda.time.Duration.standardDays(1)
val bsonDocument = BsonConverter.toBson(duration)
(bsonDocument.toString must be).equalTo("BsonString{value='86400000ms'}")
(Duration("86400000ms").toMillis must be).equalTo(duration.getMillis)
}

}

override def beforeAll(): Unit = {
BsonConverter.converterPlugin = new JodaConverterPlugin()
}
override def afterAll(): Unit = {
BsonConverter.converterPlugin = new BaseConverterPlugin()
}
}