export
might be able to solve that, not sure
Task
(as quoted in the snippet above) along with DAO/Repository. Now that we spoke of H2 (only for testing), question I am getting is - is it a good idea to test with H2 when the production is going to be something else. Kind of beginner with slick - not sure if this advisable. If so - any directions ? Thanks
SchemaGenerator
is needed. SchemeGenerator
requires Database
and collection Table[Model]
. There is also this sticky import statement import slick.jdbc.PostgresProfile.api._
which I want to keep it min files as possible. Given these I am looking for design these classes.
The question is why you want to keep that import statement in as min files as possible? If it's because your project is the barebones for building other projects, then you can always store somewhere in a global object the profile you want to use. Something like
object DatabaseGlobals {
def profile = slick.jdbc.PostgresProfile
}
and then you can import that instead, via my.package.DatabaseGlobals.profile.api._
.
If the reason is for mocks in tests, then I think you can put your table definitions inside a trait which requires an abstract jdbc profile, and feed that profile by extending the trait (I think that works)
WrappingQuery
(like forUpdate
) implicit protected class AddNoWait[E, U, C[_]](val q: Query[E, U, C]) {
def nowait: Query[E, U, C] = {
???
new WrappingQuery[E, U, C](q.toNode, q.shaped)
}
}
The question is why you want to keep that import statement in as min files as possible? If it's because your project is the barebones for building other projects, then you can always store somewhere in a global object the profile you want to use. Something like
object DatabaseGlobals { def profile = slick.jdbc.PostgresProfile }
and then you can import that instead, via
my.package.DatabaseGlobals.profile.api._
.
If the reason is for mocks in tests, then I think you can put your table definitions inside a trait which requires an abstract jdbc profile, and feed that profile by extending the trait (I think that works)
@sherpal - Intention is to use an in memory database for testing.
Here is something that I am trying to do with Slick.
AUTO_INC
columnAUTO_INC
doing its part in assigning an incremented value automaticallyupdate table set global_offset = select max(global_offset)+1 from table
Besides the fact that this might have performance implications, the underlying sequence of the AUTO_INC
column does not get updated. Hence this same value can be inserted in another row as well through an insert statement.
Any help how I can do this with Slick ? Thanks.
Can someone tell me if this config looks correct for mysql using Slick 3.3.1 on Scala 2.12?
nc {
mysql {
profile = "slick.jdbc.MySQLProfile$"
dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
properties = {
driver = "com.mysql.cj.jdbc.Driver"
databaseName = "analytics_cache_schema"
serverName = "localhost"
portNumber = 3306
user = "analytics_cache"
password = "qwe90qwe"
characterEncoding = "utf8"
useUnicode = true
}
numThreads = 10
keepAliveConnection = true
}
}
I initialize with Database.forConfig("nc.mysql")
but getting this error: java.lang.ClassNotFoundException: slick.jdbc.DatabaseUrlDataSource
It only happens in EMR 6.0.0 in Spark 2.4.4, and not in my tests run by sbt
If I inspect my jar with I can see slick/jdbc/DatabaseUrlDataSource.class
is included
I have a simple insert that looks like:
records += Record(c1, c2, c3)
I'd like to change it to make that insert conditional. I don't want to proceed with the insert if a record exists where the all the columns match but c3 is null
.
I'd like to have Slick generate the following:
insert into mytable (c1, c2, c3) values ('one', 'two', 'three')
where not exists (select 1 from mytable where c1 = 'one' and c2 = 'two' and c3 is null);
Hi everyone, does anyone have experience using Slick with the Squants library? I am trying to add two colums of Rep[Length] together. The thing I'm running into seems like an implicit string conversion is being applied, messing things up. The first value (bow
) is lifted and read as Rep[Length]
, the second (stern
) however has anyOptionLift(primitiveShape(stringColumnType))
implicit added to it. Both bow
and stern
in the for comprehension are read as Rep[Length]
but the yield uses the any2stringadd
implicit causing a String expected error.
val length: Rep[Option[Length]] = for {
bow <- nearbyVessel.distanceToBow
stern <- nearbyVessel.distanceToStern
} yield bow + stern
Any suggestions on how I can solve this by using explicit extension methods or writing my own are greatly appreciated, cheers.
java.lang.ClassNotFoundException: slick.jdbc.DatabaseUrlDataSource
Database.forConfig("nc.mysql")
(see earlier message)DatabaseUrlDataSource
directly in the shellscala> import slick.jdbc.DatabaseUrlDataSource
import slick.jdbc.DatabaseUrlDataSource
scala> new DatabaseUrlDataSource()
res7: slick.jdbc.DatabaseUrlDataSource = slick.jdbc.DatabaseUrlDataSource@15ff0f79
ClassNotFoundException
during database initialization, but now I'm facing a different error java.lang.NullPointerException
at slick.jdbc.DriverDataSource.getConnection(DriverDataSource.scala:101)
at slick.jdbc.DataSourceJdbcDataSource.createConnection(JdbcDataSource.scala:68)
at slick.jdbc.JdbcBackend$BaseSession.<init>(JdbcBackend.scala:494)
at slick.jdbc.JdbcBackend$DatabaseDef.createSession(JdbcBackend.scala:46)
at slick.jdbc.JdbcBackend$DatabaseDef.createSession(JdbcBackend.scala:37)
at slick.basic.BasicBackend$DatabaseDef.acquireSession(BasicBackend.scala:250)
at slick.basic.BasicBackend$DatabaseDef.acquireSession$(BasicBackend.scala:249)
at slick.jdbc.JdbcBackend$DatabaseDef.acquireSession(JdbcBackend.scala:37)
at slick.basic.BasicBackend$DatabaseDef$$anon$3.run(BasicBackend.scala:275)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Database.forURL
and try to write to the db, the mysql driver connects using a different database URL and I get an error saying the table doesn't exist. Anyone experience something like this?