Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Aug 8, 2024
1 parent 759ef10 commit 28be4c8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
14 changes: 11 additions & 3 deletions core/src/main/scala/lightdb/Field.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ sealed class Field[Doc, V](val name: String,

override def distance(from: GeoPoint, radius: Distance): Filter[Doc] =
Filter.Distance(this.asInstanceOf[Field[Doc, Option[GeoPoint]]], from, radius)

override def toString: String = s"Field(name = $name)"
}

trait Indexed[Doc, V] extends Field[Doc, V]
Expand All @@ -77,21 +79,27 @@ object Field {
get = get,
getRW = () => getRW,
indexed = true
) with Indexed[Doc, V]
) with Indexed[Doc, V] {
override def toString: String = s"Indexed(name = ${this.name})"
}

def tokenized[Doc](name: String, get: Doc => String): Tokenized[Doc] = new Field[Doc, String](
name = name,
get = get,
getRW = () => stringRW,
indexed = true
) with Tokenized[Doc]
) with Tokenized[Doc] {
override def toString: String = s"Tokenized(name = ${this.name})"
}

def unique[Doc, V](name: String, get: Doc => V)(implicit getRW: => RW[V]): UniqueIndex[Doc, V] = new Field[Doc, V](
name = name,
get = get,
getRW = () => getRW,
indexed = true
) with UniqueIndex[Doc, V]
) with UniqueIndex[Doc, V] {
override def toString: String = s"Unique(name = ${this.name})"
}

def string2Json(name: String, s: String, definition: DefType): Json = definition match {
case _ if s == null => Null
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/lightdb/aggregate/AggregateQuery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import lightdb.materialized.MaterializedAggregate
import lightdb.transaction.Transaction

case class AggregateQuery[Doc <: Document[Doc], Model <: DocumentModel[Doc]](query: Query[Doc, Model],
functions: List[AggregateFunction[_, _, Doc]],
filter: Option[AggregateFilter[Doc]] = None,
sort: List[(AggregateFunction[_, _, Doc], SortDirection)] = Nil) {
functions: List[AggregateFunction[_, _, Doc]],
filter: Option[AggregateFilter[Doc]] = None,
sort: List[(AggregateFunction[_, _, Doc], SortDirection)] = Nil) {
def filter(f: Model => AggregateFilter[Doc], and: Boolean = false): AggregateQuery[Doc, Model] = {
val filter = f(query.collection.model)
if (and && this.filter.nonEmpty) {
Expand Down
6 changes: 5 additions & 1 deletion sql/src/main/scala/lightdb/sql/SQLQueryBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ case class SQLQueryBuilder[Doc <: Document[Doc]](collection: Collection[Doc, _],
def execute(): SQLResults = executeInternal()

private def executeInternal(pre: String = "", post: String = ""): SQLResults = {
scribe.debug(s"Executing Query: $sql (${args.mkString(", ")})")
if (SQLQueryBuilder.LogQueries) scribe.info(s"Executing Query: $sql (${args.mkString(", ")})")
val combinedSql = s"$pre$sql$post"
try {
state.withPreparedStatement(combinedSql) { ps =>
Expand All @@ -94,4 +94,8 @@ case class SQLQueryBuilder[Doc <: Document[Doc]](collection: Collection[Doc, _],
case t: Throwable => throw new SQLException(s"Error executing query: $combinedSql", t)
}
}
}

object SQLQueryBuilder {
var LogQueries: Boolean = false
}

0 comments on commit 28be4c8

Please sign in to comment.