Posts

Showing posts from February, 2014

scala, slick and NotesService

I forgot to add a full version of the NotesService that was discussed in a previous blog. Let's revisit the NotesService interface: /** * Primarily for larger notes/docs storage. * The API allows the note content to be retrieved * separately. Sometimes, we want to separate * out the larger, less changing content from * our core database into a separate component. A note * can be a picture, a spreadsheet, HTML, XML or * even just a text document. While times, * these types of documents are just stored in a * standard RDBMS database, there are other options * such as a document management systems or * file-system. * * This trait does not prescribe how to * create {{{Note}}} objects. Also, the {{{Note}}}, * {{{NoteId}}} and other types will probably escape * whatever object instantiates this object * so the types will need to be accessible to the outer * world for working with the service. That means * we will have to watch-out for path-dependent * type accesss issues as we employ th…

scala slick and sub-selects for max value

I am learning slick. A bit of tough road initially. The blogs and other posts out there really help. Thistutorial was especially helpful. My domain was storing note objects in database and tracking revisions. Here's the table structure: classNotes(tag:Tag)extendsTable[(Int, Int, java.sql.Timestamp, Boolean, Option[String])](tag,"Notes"){// some dbs cannot return compound primary key, so use a standard intdefid=column[Int]("id",O.AutoInc,O.PrimaryKey)defdocId=column[Int]("docId")defcreatedOn=column[java.sql.Timestamp]("createdOn")defcontent=column[Option[String]]("content")deflatest=column[Boolean]("latest")def*=(id,docId,createdOn,latest,content)defindex1=index("index1",docId)defindex2=index("index2",createdOn)defindex3=index("index3",latest)}valNotes=TableQuery[Notes] There are more enhancements needed for this table, but you get the gist. So we can query the table for a specific document id…