Skip to content

Commit 8e24215

Browse files
committed
feat: detect schema
1 parent 1df9e97 commit 8e24215

14 files changed

Lines changed: 921 additions & 5 deletions

File tree

build.sbt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ libraryDependencies ++= Seq(
7373
"io.circe" %% "circe-core",
7474
"io.circe" %% "circe-generic",
7575
"io.circe" %% "circe-parser"
76-
).map(_ % circeVersion % Test)
76+
).map(_ % circeVersion)
7777

7878
libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "5.0.1"
7979

@@ -101,6 +101,8 @@ libraryDependencies += "com.vdurmont" % "semver4j" % "3.1.0"
101101

102102
libraryDependencies += "com.github.jsqlparser" % "jsqlparser" % "4.9"
103103

104+
libraryDependencies += "org.postgresql" % "postgresql" % "42.7.3"
105+
104106
buildInfoPackage := "dev.mongocamp.driver.mongodb"
105107

106108
buildInfoOptions += BuildInfoOption.BuildTime
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
{
2+
"S": {
3+
"$push": {
4+
"$switch": {
5+
"branches": [
6+
{
7+
"case": {
8+
"$eq": [
9+
"$_id.sT",
10+
"bS"
11+
]
12+
},
13+
"then": {
14+
"c": "$c",
15+
"n": "$_id.n",
16+
"t": "$_id.t"
17+
}
18+
},
19+
{
20+
"case": {
21+
"$eq": [
22+
"$_id.sT",
23+
"vS"
24+
]
25+
},
26+
"then": {
27+
"ve": {
28+
"a": {
29+
"$cond": [
30+
{
31+
"$eq": [
32+
"$_id.t",
33+
"bool"
34+
]
35+
},
36+
{
37+
"$eq": [
38+
"$a",
39+
1
40+
]
41+
},
42+
"$a"
43+
]
44+
},
45+
"g": "$g",
46+
"i": {
47+
"$cond": [
48+
{
49+
"$eq": [
50+
"$_id.t",
51+
"bool"
52+
]
53+
},
54+
{
55+
"$eq": [
56+
"$i",
57+
1
58+
]
59+
},
60+
"$i"
61+
]
62+
}
63+
}
64+
}
65+
},
66+
{
67+
"case": {
68+
"$eq": [
69+
"$_id.sT",
70+
"lS"
71+
]
72+
},
73+
"then": {
74+
"le": {
75+
"al": "$al",
76+
"gl": "$gl",
77+
"il": "$il"
78+
}
79+
}
80+
},
81+
{
82+
"case": {
83+
"$eq": [
84+
"$_id.sT",
85+
"fS"
86+
]
87+
},
88+
"then": {
89+
"cu": "$cu",
90+
"lF": "$lF",
91+
"mF": "$mF"
92+
}
93+
},
94+
{
95+
"case": {
96+
"$eq": [
97+
"$_id.sT",
98+
"vH"
99+
]
100+
},
101+
"then": {
102+
"vH": {
103+
"s": "$s",
104+
"ns": "$ns",
105+
"it": "$it",
106+
"end": {
107+
"$cond": [
108+
{
109+
"$in": [
110+
"$_id.t",
111+
[
112+
"objectId",
113+
"date"
114+
]
115+
]
116+
},
117+
{
118+
"$add": [
119+
"1970-01-01T01:00:00+01:00",
120+
{
121+
"$multiply": [
122+
"$end",
123+
1000
124+
]
125+
}
126+
]
127+
},
128+
"$end"
129+
]
130+
},
131+
"sta": {
132+
"$cond": [
133+
{
134+
"$in": [
135+
"$_id.t",
136+
[
137+
"objectId",
138+
"date"
139+
]
140+
]
141+
},
142+
{
143+
"$add": [
144+
"1970-01-01T01:00:00+01:00",
145+
{
146+
"$multiply": [
147+
"$sta",
148+
1000
149+
]
150+
}
151+
]
152+
},
153+
"$sta"
154+
]
155+
},
156+
"r": "$r"
157+
}
158+
}
159+
},
160+
{
161+
"case": {
162+
"$eq": [
163+
"$_id.sT",
164+
"lH"
165+
]
166+
},
167+
"then": {
168+
"lH": {
169+
"end": "$end",
170+
"it": "$it",
171+
"ns": "$ns",
172+
"r": "$r",
173+
"s": "$s",
174+
"sta": "$sta"
175+
}
176+
}
177+
},
178+
{
179+
"case": {
180+
"$eq": [
181+
"$_id.sT",
182+
"wH"
183+
]
184+
},
185+
"then": {
186+
"wH": {
187+
"it": "$it"
188+
}
189+
}
190+
},
191+
{
192+
"case": {
193+
"$eq": [
194+
"$_id.sT",
195+
"hH"
196+
]
197+
},
198+
"then": {
199+
"hH": {
200+
"it": "$it"
201+
}
202+
}
203+
}
204+
],
205+
"default": null
206+
}
207+
}
208+
},
209+
"_id": {
210+
"n": "$_id.n",
211+
"t": "$_id.t"
212+
}
213+
}

src/main/scala/dev/mongocamp/driver/mongodb/relation/OneToManyRelationship.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package dev.mongocamp.driver.mongodb.relation
22

3-
import dev.mongocamp.driver.mongodb.MongoDAO
3+
import dev.mongocamp.driver.mongodb.{ GenericObservable, MongoDAO }
44
import dev.mongocamp.driver.mongodb.relation.RelationCache.{ addCachedValue, getCachedValue, hasCachedValue }
55

66
case class OneToManyRelationship[A](dao: MongoDAO[A], daoKey: String, useCache: Boolean = true) extends Relationship {
77

88
def relatedRecords(value: Any): List[A] = {
99
val key = "%s_%s".format(id, value)
10-
if (!useCache || !hasCachedValue(key))
10+
if (!useCache || !hasCachedValue(key)) {
1111
addCachedValue(key, dao.find(daoKey, value).resultList())
12+
}
1213
getCachedValue[List[A]](key)
1314
}
1415

src/main/scala/dev/mongocamp/driver/mongodb/relation/OneToOneRelationship.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package dev.mongocamp.driver.mongodb.relation
22

3-
import dev.mongocamp.driver.mongodb.MongoDAO
3+
import dev.mongocamp.driver.mongodb.{ GenericObservable, MongoDAO }
44
import dev.mongocamp.driver.mongodb.relation.RelationCache.{ addCachedValue, getCachedValue, hasCachedValue }
55

66
case class OneToOneRelationship[A](dao: MongoDAO[A], daoKey: String, useCache: Boolean = true) extends Relationship {
77

88
def relatedRecord(value: Any): Option[A] = {
99
val key = "%s_%s".format(id, value)
10-
if (!useCache || !hasCachedValue(key))
10+
if (!useCache || !hasCachedValue(key)) {
1111
addCachedValue(key, dao.find(daoKey, value).resultOption())
12+
}
1213
getCachedValue[Option[A]](key)
1314
}
1415

0 commit comments

Comments
 (0)