Skip to content

Commit

Permalink
Refactored Field types to be within object
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Sep 19, 2024
1 parent daa865a commit f42b255
Show file tree
Hide file tree
Showing 25 changed files with 59 additions and 41 deletions.
3 changes: 2 additions & 1 deletion async/src/main/scala/lightdb/async/AsyncCollection.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package lightdb.async

import cats.effect.IO
import lightdb.{Field, Id, UniqueIndex}
import lightdb._
import lightdb.Field._
import lightdb.collection.Collection
import lightdb.doc.{Document, DocumentModel}
import lightdb.transaction.Transaction
Expand Down
3 changes: 2 additions & 1 deletion async/src/main/scala/lightdb/async/AsyncQuery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package lightdb.async
import cats.effect.IO
import fabric.Json
import lightdb.aggregate.AggregateFunction
import lightdb.{Field, Id, Query, SearchResults, Sort, SortDirection, UniqueIndex}
import lightdb._
import lightdb.Field._
import lightdb.collection.Collection
import lightdb.distance.Distance
import lightdb.doc.{Document, DocumentModel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package lightdb.async

import cats.effect.IO
import lightdb.doc.{Document, DocumentModel}
import lightdb.{Field, Id, UniqueIndex}
import lightdb._
import lightdb.Field._

case class AsyncTransactionConvenience[Doc <: Document[Doc], Model <: DocumentModel[Doc]](collection: AsyncCollection[Doc, Model]) {
def insert(doc: Doc): IO[Doc] = collection.transaction { implicit transaction =>
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ val developerURL: String = "https://matthicks.com"

name := projectName
ThisBuild / organization := org
ThisBuild / version := "0.13.0-SNAPSHOT"
ThisBuild / version := "0.13.0-SNAPSHOT1"
ThisBuild / scalaVersion := scala213
ThisBuild / crossScalaVersions := allScalaVersions
ThisBuild / scalacOptions ++= Seq("-unchecked", "-deprecation")
Expand Down
28 changes: 14 additions & 14 deletions core/src/main/scala/lightdb/Field.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,6 @@ sealed class Field[Doc <: Document[Doc], V](val name: String,
override def toString: String = s"Field(name = $name)"
}

trait Indexed[Doc <: Document[Doc], V] extends Field[Doc, V]

trait UniqueIndex[Doc <: Document[Doc], V] extends Indexed[Doc, V]

trait Tokenized[Doc <: Document[Doc]] extends Indexed[Doc, String]

class FacetField[Doc <: Document[Doc]](name: String,
get: Doc => List[FacetValue],
val hierarchical: Boolean,
val multiValued: Boolean,
val requireDimCount: Boolean) extends Field[Doc, List[FacetValue]](name, get, getRW = () => implicitly[RW[List[FacetValue]]], indexed = true) with Indexed[Doc, List[FacetValue]] {
def drillDown(path: String*): DrillDownFacetFilter[Doc] = DrillDownFacetFilter(name, path.toList)
}

object Field {
val NullString: String = "||NULL||"

Expand Down Expand Up @@ -170,4 +156,18 @@ object Field {
case t: Throwable => throw new RuntimeException(s"Failure to convert $name = $s to $definition", t)
}
}

trait Indexed[Doc <: Document[Doc], V] extends Field[Doc, V]

trait UniqueIndex[Doc <: Document[Doc], V] extends Indexed[Doc, V]

trait Tokenized[Doc <: Document[Doc]] extends Indexed[Doc, String]

class FacetField[Doc <: Document[Doc]](name: String,
get: Doc => List[FacetValue],
val hierarchical: Boolean,
val multiValued: Boolean,
val requireDimCount: Boolean) extends Field[Doc, List[FacetValue]](name, get, getRW = () => implicitly[RW[List[FacetValue]]], indexed = true) with Indexed[Doc, List[FacetValue]] {
def drillDown(path: String*): DrillDownFacetFilter[Doc] = DrillDownFacetFilter(name, path.toList)
}
}
1 change: 1 addition & 0 deletions core/src/main/scala/lightdb/Query.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lightdb

import fabric.Json
import lightdb.Field._
import lightdb.aggregate.{AggregateFunction, AggregateQuery}
import lightdb.collection.Collection
import lightdb.distance.Distance
Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/lightdb/SearchResults.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package lightdb

import lightdb.Field._
import lightdb.doc.{Document, DocumentModel}
import lightdb.facet.FacetResult
import lightdb.transaction.Transaction
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/lightdb/collection/Collection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import lightdb.store.Store
import lightdb.transaction.Transaction
import lightdb.trigger.CollectionTriggers
import lightdb.util.Initializable
import lightdb.{Id, Query, UniqueIndex}
import lightdb._
import lightdb.Field._

import java.util.concurrent.ConcurrentHashMap
import scala.jdk.CollectionConverters.IteratorHasAsScala
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/lightdb/doc/DocumentModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import fabric.rw._
import lightdb.collection.Collection
import lightdb.facet.FacetValue
import lightdb.filter.FilterBuilder
import lightdb.{FacetField, Field, Id, Indexed, Tokenized, Unique, UniqueIndex}
import lightdb._
import lightdb.Field._

import scala.language.implicitConversions

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/lightdb/facet/FacetQuery.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package lightdb.facet

import lightdb.FacetField
import lightdb.Field.FacetField
import lightdb.doc.Document

case class FacetQuery[Doc <: Document[Doc]](field: FacetField[Doc],
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/lightdb/store/InMemoryIndexes.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lightdb.store

import lightdb.{Id, Indexed, Query, SearchResults, UniqueIndex}
import lightdb._
import lightdb.Field._
import lightdb.collection.Collection
import lightdb.doc.{Document, DocumentModel}
import lightdb.transaction.Transaction
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/lightdb/store/MapStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package lightdb.store

import lightdb.aggregate.AggregateQuery
import lightdb.collection.Collection
import lightdb.{Field, Id, LightDB, Query, SearchResults, UniqueIndex}
import lightdb._
import lightdb.Field._
import lightdb.doc.{Document, DocumentModel}
import lightdb.materialized.MaterializedAggregate
import lightdb.transaction.Transaction
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/lightdb/store/Store.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import lightdb.collection.Collection
import lightdb.doc.{Document, DocumentModel}
import lightdb.materialized.MaterializedAggregate
import lightdb.transaction.Transaction
import lightdb.{Field, Id, Indexed, Query, SearchResults, Unique, UniqueIndex}
import lightdb._
import lightdb.Field._

import java.io.File

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/lightdb/store/split/SplitStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import lightdb.doc.{Document, DocumentModel}
import lightdb.materialized.MaterializedAggregate
import lightdb.store.{Conversion, Store, StoreMode}
import lightdb.transaction.{Transaction, TransactionKey}
import lightdb.{Field, Id, Query, SearchResults, UniqueIndex}
import lightdb._
import lightdb.Field._

import scala.language.implicitConversions

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package lightdb.trigger

import lightdb.UniqueIndex
import lightdb.Field
import lightdb.collection.Collection
import lightdb.doc.{Document, DocumentModel}
import lightdb.transaction.Transaction
Expand All @@ -23,7 +23,7 @@ trait BasicCollectionTrigger[Doc <: Document[Doc], Model <: DocumentModel[Doc]]
}
}

override final def delete[V](index: UniqueIndex[Doc, V], value: V)(implicit transaction: Transaction[Doc]): Unit = {
override final def delete[V](index: Field.UniqueIndex[Doc, V], value: V)(implicit transaction: Transaction[Doc]): Unit = {
collection.query.filter(_ => index === value).iterator.foreach(removing)
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/lightdb/trigger/CollectionTrigger.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package lightdb.trigger

import lightdb.UniqueIndex
import lightdb.Field
import lightdb.doc.Document
import lightdb.transaction.Transaction

trait CollectionTrigger[Doc <: Document[Doc]] {
def insert(doc: Doc)(implicit transaction: Transaction[Doc]): Unit = {}
def upsert(doc: Doc)(implicit transaction: Transaction[Doc]): Unit = {}
def delete[V](index: UniqueIndex[Doc, V], value: V)(implicit transaction: Transaction[Doc]): Unit = {}
def delete[V](index: Field.UniqueIndex[Doc, V], value: V)(implicit transaction: Transaction[Doc]): Unit = {}
def truncate(): Unit = {}
def dispose(): Unit = {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package lightdb.trigger

import lightdb.UniqueIndex
import lightdb.Field.UniqueIndex
import lightdb.doc.Document
import lightdb.transaction.Transaction

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/lightdb/util/InMemoryIndex.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lightdb.util

import lightdb.{Field, Id, Indexed}
import lightdb._
import lightdb.Field._
import lightdb.doc.Document

import java.util.Comparator
Expand Down
3 changes: 2 additions & 1 deletion halodb/src/main/scala/lightdb/halodb/HaloDBStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import fabric.io.{JsonFormatter, JsonParser}
import fabric.rw.{Asable, Convertible}
import lightdb.aggregate.AggregateQuery
import lightdb.collection.Collection
import lightdb.{Field, Id, LightDB, Query, SearchResults, UniqueIndex}
import lightdb._
import lightdb.Field._
import lightdb.doc.{Document, DocumentModel}
import lightdb.materialized.MaterializedAggregate
import lightdb.store.{Conversion, Store, StoreManager, StoreMode}
Expand Down
3 changes: 2 additions & 1 deletion lucene/src/main/scala/lightdb/lucene/LuceneStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import fabric.rw.{Asable, Convertible}
import lightdb.SortDirection.Ascending
import lightdb.aggregate.{AggregateQuery, AggregateType}
import lightdb.collection.Collection
import lightdb.{FacetField, Field, Id, LightDB, Query, SearchResults, Sort, SortDirection, Tokenized, UniqueIndex}
import lightdb._
import lightdb.Field._
import lightdb.doc.{Document, DocumentModel, JsonConversion}
import lightdb.facet.{FacetResult, FacetResultValue}
import lightdb.filter.{Condition, Filter}
Expand Down
5 changes: 2 additions & 3 deletions mapdb/src/main/scala/lightdb/mapdb/MapDBStore.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package lightdb.mapdb

import fabric.io.{JsonFormatter, JsonParser}
import fabric.rw.{Asable, Convertible}
import lightdb.aggregate.AggregateQuery
import lightdb.collection.Collection
import lightdb.{Field, Id, LightDB, Query, SearchResults, UniqueIndex}
import lightdb._
import lightdb.Field._
import lightdb.doc.{Document, DocumentModel}
import lightdb.materialized.MaterializedAggregate
import lightdb.store.{Conversion, Store, StoreManager, StoreMode}
Expand Down
5 changes: 3 additions & 2 deletions redis/src/main/scala/lightdb/redis/RedisStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package lightdb.redis

import lightdb.aggregate.AggregateQuery
import lightdb.collection.Collection
import lightdb.{Field, Id, Query, SearchResults, UniqueIndex}
import lightdb._
import lightdb.Field._
import lightdb.doc.{Document, DocumentModel}
import lightdb.materialized.MaterializedAggregate
import lightdb.store.{Conversion, Store, StoreMode}
import lightdb.transaction.{Transaction, TransactionKey}
import redis.clients.jedis.{Jedis, JedisPool, JedisPoolConfig}
import _root_.redis.clients.jedis.{Jedis, JedisPool, JedisPoolConfig}

import scala.jdk.CollectionConverters.IteratorHasAsScala

Expand Down
3 changes: 2 additions & 1 deletion rocksdb/src/main/scala/lightdb/rocksdb/RocksDBStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import fabric.io.{JsonFormatter, JsonParser}
import fabric.rw.{Asable, Convertible}
import lightdb.aggregate.AggregateQuery
import lightdb.collection.Collection
import lightdb.{Field, Id, Query, SearchResults, UniqueIndex}
import lightdb._
import lightdb.Field._
import lightdb.doc.{Document, DocumentModel}
import lightdb.materialized.MaterializedAggregate
import lightdb.store.{Conversion, Store, StoreMode}
Expand Down
3 changes: 2 additions & 1 deletion sql/src/main/scala/lightdb/sql/SQLArg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import fabric.io.JsonFormatter
import fabric.rw._
import lightdb.doc.Document
import lightdb.spatial.Geo
import lightdb.{Field, Id, Tokenized}
import lightdb._
import lightdb.Field._

import java.sql.{JDBCType, PreparedStatement, SQLType, Types}

Expand Down
4 changes: 3 additions & 1 deletion sql/src/main/scala/lightdb/sql/SQLStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import lightdb.sql.connect.ConnectionManager
import lightdb.store.{Conversion, Store, StoreMode}
import lightdb.transaction.{Transaction, TransactionKey}
import lightdb.util.ActionIterator
import lightdb.{Field, Id, Indexed, Query, SearchResults, Sort, SortDirection, Tokenized, UniqueIndex}
import lightdb._
import lightdb.Field._

import java.sql.{Connection, PreparedStatement, ResultSet}
import scala.language.implicitConversions
Expand Down Expand Up @@ -491,6 +492,7 @@ abstract class SQLStore[Doc <: Document[Doc], Model <: DocumentModel[Doc]] exten
throw new UnsupportedOperationException("Distance filtering not supported in SQL!")

private def filter2Part(f: Filter[Doc]): SQLPart = f match {
case f: Filter.DrillDownFacetFilter[Doc] => throw new UnsupportedOperationException(s"SQLStore does not support Facets: $f")
case f: Filter.Equals[Doc, _] if f.field(collection.model).isArr =>
val values = f.getJson(collection.model).asVector
val parts = values.map { json =>
Expand Down

0 comments on commit f42b255

Please sign in to comment.