nbcp.myoql.db.mongo.component.MongoWhereClip.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ktmyoql Show documentation
Show all versions of ktmyoql Show documentation
kotlin orm -- mysql,mongo , just like ktorm
The newest version!
package nbcp.myoql.db.mongo
import nbcp.base.comm.JsonMap
import nbcp.base.extend.IsCollectionType
import nbcp.base.extend.IsMapType
import nbcp.base.extend.IsSimpleType
import java.util.*
class MongoWhereClip() : LinkedList() {
constructor(map: Map) : this() {
if (map is JsonMap) {
this.add(map);
return;
}
this.add(JsonMap(map))
}
fun putAll(map: Map) {
if (map is JsonMap) {
this.add(map);
return;
}
this.add(JsonMap(map));
}
fun addWhere(key: String, value: Any?) {
this.add(JsonMap(key to value))
}
/**
* 从根级查找指定条件的值。
* @param column , 可能是 _id , user._id
* @return 可能是简单类型,也可能是List类型
*/
fun findValueFromRootLevel(column: String): Any? {
for (map in this) {
val findedValue = getValueFromMap(map, column);
if (findedValue != null) {
return findedValue;
}
}
return null;
}
private fun getValueFromMap(map: Map, column: String): Any? {
if (map.keys.size == 1 && map.keys.first() == "\$and") {
var vs = map.values.first() as Collection