Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is purpose of anorm's Pk?

I'm writing Playframework 2.0 application using Scala and Anorm to access db.

Currently I'm using Pk[Long] for id fields and I'm worry about additional get call needed to access actual value. So I start using plain Long for id fields and everything still work perfect.

What Pk is for, and should I use it instead of plain types? Does Pk gives me additional features/benefits over plain types?

like image 670
lambdas Avatar asked Jun 23 '12 09:06

lambdas


1 Answers

Pk allows you to specify a typed primary key.

Also, say you have a contrived model like this:

case class MyModel(id: Pk[Long], foo: String)

You have the benefit of constructing an instance of your model with:

MyModel(anorm.NotAssigned, "notKnownAtRuntime")

...if your database is responsible for generating your keys, or otherwise:

MyModel(anorm.Id(123L), "knownAtRuntime")
like image 168
opyate Avatar answered Nov 08 '22 17:11

opyate