scala - Types MapColumn, SetColumn, JsonColumn needs owner and record. What actually are these values? -
for example, have
type mapcolumn[owner <: com.websudos.phantom.dsl.cassandratable[owner, record], record, k, v] = com.websudos.phantom.column.mapcolumn[owner, record, k, v]
k
, v
obvious, owner , record? should input there?
the whole power of phantom ability map around data model , give type safe results, or had in mind when wrote it. owner
type param type of table written user , needed can stuff like:
select.where(_.id eqs id)
looks pretty simple, trick without refined type param through compiler can "memorize" columns have arbitrarily defined inside table, never able "know" in dsl code columns user writes.
so dsl has know final type of table create extending cassandratable
.
case class myrecord(id: uuid, name: string) class mytable extends cassandratable[mytable, myrecord] { object id extends uuidcolumn(this) partitionkey[uuid] // mytable owner , myrecord record. object mapcolumn extends mapcolumn[mytable, myrecord, string, string](this) }
so that's why query builders function table: owner
else. above shorthand notation for:
select.where(table => table.id eqs id)
the record
type makes cassandra results type safe. telling table case class wraps around, phantom able map results case class using implicit api approach, instead of having deal things like:
res.getstring("mystring")
such things invisible dealt under hood, , phantom "knows" results cassandra row returned belong field inside case class
. it's immensely less verbose , more efficient, since don't want care how driver deals internal parsing of netty buffers , cql message exchanges between client , database, want record back.
so record
in combination fromrow
method needed, , passed around not in columns, in every single column. difference stringcolumn
, compiler able infer type of t
, r
don't have type it.
this because of:
type stringcolumn[ owner <: cassandratable[owner, record], record ] = com.websudos.phantom.column.primitivecolumn[owner, record, string]
so in reality columns need this. collections require parameter(or 2 in case of maps), provided user, , because of compiler isn't able infer type stringcolumn
or booleancolumn
, need type them hand.
in phantom 1.26.0+, has been changed, , type parameters invisible, able type following, without having specify owner
, record
.
object map extends mapcolumn[string, string](this)
Comments
Post a Comment