Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8789065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:17:57+00:00 2026-06-13T22:17:57+00:00

I need to import different libraries and do slightly different things depending on the

  • 0

I need to import different libraries and do slightly different things depending on the use of my source, ie for running and testing.

If I have various source files that look something like this for production:

import scala.slick.driver.PostgresDriver.simple._
import Database.threadLocalSession

case class SomeBusinessObject(...)

What is good way to change it into the following for testing (meaning I would like to use a different databse during testing):

import scala.slick.driver.h2.simple._
import Database.threadLocalSession

case class SomeBusinessObject(...)

Oh, and then there’s also a database class to hold the key to whatever database I’m using:

import scala.slick.driver.PostgresDriver.simple._

// Use the implicit threadLocalSession
import Database.threadLocalSession

object DB{

  val get = {
      Database.forURL("jdbc:postgresql:test:slick",
                           driver="org.postgresql.Driver",
                           user="postgres",
                           password="xxxx") 
  }
}

I did some research, and it looks like the Cake pattern may hold the key for this type of thing, but it would be great if someone could get me started (if cake’s the right approach)

UPDATE:

Since asking this question, I found exactly what I was looking for in the Slick examples. It really sets it apart neatly! I worked through the examples some weeks back, but could not recall where I saw this done.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:18:00+00:00Added an answer on June 13, 2026 at 10:18 pm

    You could build on the fact that scala allows you to use “import” nested in a class, object or trait (and not just at the root level):

    An example with scala.collection.mutable.Map and scala.collection.immutable.Map (say we want to use the immutable version of Map in test and the mutable one in Production)

    scala> trait Import1 {
         | import scala.collection.mutable.{Map => iMap}
         | def Test = iMap(1 -> "a")
         | }
    defined trait Import1
    
    scala> trait Import2 {
         | import scala.collection.immutable.{Map => iMap}
         | def Test = iMap(1 -> "a")
         | }
    defined trait Import2
    

    now you can do:

    scala> object ProductionThing extends Import1
    defined module ProductionThing
    
    scala> ProductionThing.Test
    res6: scala.collection.mutable.Map[Int,java.lang.String] = Map(1 -> a)
    
    scala> object TestingThing extends Import2
    defined module TestingThing
    
    scala> TestingThing.Test
    res7: scala.collection.immutable.Map[Int,java.lang.String] = Map(1 -> a)
    

    or you could use the same mechanism to scope your import within a class and inject that class into SomeBusinessObject.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a flat data file that I need to import into my SQL
I have a csv file that contains a location field. I need to import
I need to import some Excel spreadsheets into Java objects. I will use POI
I have two scenarios. Suppose I have 3 shared libraries that export C++ symbols,
I need to import different feeds at different times, and my plan is to
I need to import 8-10 CSV files into some JS code. Each file has
I have a csv file and i need to import it to a table
I'm trying to use mysqlimport to import text files to a mysql database. The
I need to import data from 50 similar csv files to a single excel
I often have to design XML schemas for different XML-bases import routines. It is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.