Question

I have been trying to get the IDE project to recognize the clauses used by Squeryl. I have add the Squeryl*.jar to my project dependencies yet still I have to import the classes for clause "From" to be used. More specifically I had to extend objects with "import org.squeryl.dsl.boilerplate.FromSignatures" just to make "from" work. That was a weird still viable solution but commands "like/select" cant bee imported.. What is going on? I even tryed implementing the select method..

    def select[R](r: =>R): R

    object ExternalVendor extends FromSignatures{
      def findAll = tx {
        from(vendors)(s => select(s)) map(s => s) }

      def select[R](r: =>R): R
      //def select[QueryYield[_R]](r: =>QueryYield[_R]): QueryYield[_R]
    }

until it gave me problems with "R" saying select(s) not expected type "QueryYield[_R]" Please help..

Code:

   package object models {
              implicit val transactionFailures: Table[TransactionFailure] = LowkeySchema.transactionFailures
              implicit val vendors: Table[ExternalVendor] = LowkeySchema.vendors
              implicit val products: Table[Product] = LowkeySchema.products
            }

            trait Model[A] extends KeyedEntity[Long] { this: A =>
              val id: Long = 0
              def save(implicit table: Table[A]): Either[Throwable, String] = {
                tx {
                  try {
                    table.insert(this)
                    Right("Domain object is saved successfully")
                  } catch {
                    case exception: Throwable => Left(exception)
                  }
                }
              }
            }

            abstract class ExternalVendor(val name: String, val url: String) extends Model[ExternalVendor]

            object ExternalVendor extends FromSignatures{
              def findAll = tx {
                from(vendors)(s => select(s)) map(s => s) }
              //def select[QueryYield[_R]](r: =>QueryYield[_R]): QueryYield[_R]
            }

            abstract class Product(val description: String,
                          val vendorName: String,
                          val basePrice: Double,
                          val plusPercent: Double)
              extends Model[Product] {
              def calculatePrice = basePrice + (basePrice * plusPercent / 100)
            }

            object Product extends FromSignatures{
              def findByDescription(description: String): Option[Product] =
                tx {
                  products.where(p => p.description like description).headOption
                }
            }
Was it helpful?

Solution

The documentation on this could stand to be improved. In Squeryl 0.9.5, for typical use, you want to:

import org.squeryl._
import PrimitiveTypeMode._

The latter import will bring in most of what you need.

In Squeryl 0.9.6 PrimitiveTypeMode is deprecated and you would define your own EntryPoint object that you would import from instead.

OTHER TIPS

I assume you've read the getting started section in squeryl's documentation. After set up, the imports from one of the examples should be sufficient:

import org.squeryl._
import adapters._
import dsl._
import dsl.ast.{RightHandSideOfIn, BinaryOperatorNodeLogicalBoolean}
import framework._
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top