Skip to content

Modifiers

ModelContexts can have additional behavior introduced using traits. A collection of useful traits exist in Vasat to aid with various capability

Version Control

This trait will allow any object to retain version control

scala
@DBAuto
class ArticleRepo extends DBModel[Article,SlickBaseTable] with VersionControlled[Article]

Important

For version Control to work there must be a ModelContext built and registered for the type import vasat.history.HistoricRecord

eg:

scala
@DBAuto
class HistoryRepo extends DBContext[HistoricRecord,SlickBaseTable]

This Context must be registered with the ModelRepository also

GraphQL

scala
@DBAuto
class ArticleRepo extends DBModel[Article,SlickBaseTable]  with GraphQLContext[Article]{
    override def graphQL = GraphQL.makeGraph[Article]
}

This will register this ModelContext to be avilable via GraphQL.

Read more on the graphQL capability

Encryption

This trait will store the JSON representation of a model encrypted and decrypt it on read.

A read to use implementation is the AESEncryptedModel that uses the AES algorithm.

scala
@DBAuto
class ArticleRepo extends DBModel[Article,SlickBaseTable]  with AESEncryptedModel[Article]{
    def graphQL = AES("AES key","salt")
}

Important

It is important to note, when using a DBModel fields that are mapped to columns for search are not encrypted. Using the @DBSuppress annotation on the sensitive fields is recommended

scala
case class MyObj(
    name:String,

    @DBSuppress  // stops field being written to a column
    mySecret:String
)

Important

In the case of AES, it is important not to lose or change your key as existing entires can not be read from the DB.

Performance

LargeTableSimpleSearchable

Trait will limit the ACL rules of the search function to use SimplePathACL rules only. No other ACL Rules will be used in conjunction.

This is useful for very large tables.

scala
@DBAuto
class ArticleRepo extends DBModel[Article,SimplePathTable] with LargeTableSimpleSearchable[Article,SlickBaseTable]

Behind the scenes will use a simple WHERE path like 'expr%' SQL query. For a large table to work effectivley, a DB index on the 'Path' column is also recommended.

LargeTablePathACLSearchable

Work similar to the trait above except on PathACL rather than SimplePathACL

scala
@DBAuto
class ArticleRepo extends DBPathModel[Article,SlickBaseTable] with LargeTablePathACLSearchable[Article,SlickBaseTable]

Behind the scenes the Path and Object tables perform a sql JOIN