Coder Social home page Coder Social logo

slick-joda-mapper's Introduction

slick-joda-mapper

CI

Enables you to use joda-time with Slick. You can persist DateTime, Instant, LocalDateTime, LocalDate, LocalTime, DateTimeZone with Slick.

Usage

For Slick 3.x

Slick version slick-joda-mapper version
3.4.x 2.8.1
3.3.x 2.7.1
3.2.x 2.3.0
3.1.x 2.2.0
3.0.x 2.0.0
libraryDependencies ++= Seq(
  "com.typesafe.slick" %% "slick" % slickVersion,
  "com.github.tototoshi" %% "slick-joda-mapper" % slickJodaMapperVersion,
  "joda-time" % "joda-time" % "2.12.5",
  "org.joda" % "joda-convert" % "2.2.3"
)

Import the appropriate xJodaSupport class suitable for the database you use (H2JodaSupport, PostgresJodaSupport, MySQLJodaSupport, etc.). For example, import Slick's H2Driver API and H2JodaSupport if you are using the H2 database:

import slick.driver.H2Driver.api._
import com.github.tototoshi.slick.H2JodaSupport._

As another example, if you are using the Postgres database:

import slick.driver.PostgresDriver.api._
import com.github.tototoshi.slick.PostgresJodaSupport._

Different drivers can't be mixed, You can't do the following.

import scala.slick.driver.H2Driver.api._
import com.github.tototoshi.slick.JdbcJodaSupport._

Write your own JdbcSupport when you want to write db agnostic model class.

object PortableJodaSupport extends com.github.tototoshi.slick.GenericJodaSupport(yourAbstractDriver)

import PortableJodaSupport._

For Slick 2.x

libraryDependencies ++= Seq(
    "com.typesafe.slick" %% "slick" % "2.1.0",
    "joda-time" % "joda-time" % "2.4",
    "org.joda" % "joda-convert" % "1.6",
    "com.github.tototoshi" %% "slick-joda-mapper" % "1.2.0"
)

Import xJodaSupport(H2JodaSupport, PostgresJodaSupport, MySQLJodaSupport...) class suitable for the database you use. For example, import H2JodaSupport if you are using H2Driver.

import scala.slick.driver.H2Driver.simple._
import com.github.tototoshi.slick.H2JodaSupport._

Different drivers can't be mixed, You can't do the following.

import scala.slick.driver.H2Driver.simple._
import com.github.tototoshi.slick.JdbcJodaSupport._

Write your own JdbcSupport when you want to write db agnostic model class.

object PortableJodaSupport extends com.github.tototoshi.slick.GenericJodaSupport(yourAbstractDriver)

// with play-slick
object PortableJodaSupport extends com.github.tototoshi.slick.GenericJodaSupport(play.api.db.slick.Config.driver)

import PortableJodaSupport._

Code generation

Write a custom code generator that replaces java.sql.Timestamp with whatever Joda classes you prefer.

This example maps java.sql.Timestamp to org.joda.time.DateTime using the Postgres support. When you modify it to suit your needs, make sure that the imports refer to the correct JdbcSupport class for your database and Joda classes.

import scala.slick.{model => m}
import scala.slick.codegen.SourceCodeGenerator

class CustomSourceCodeGenerator(model: m.Model) extends SourceCodeGenerator(model) {

  // add some custom imports
  // TODO: fix these imports to refer to your JdbcSupport and your Joda imports
  override def code = "import com.github.tototoshi.slick.PostgresJodaSupport._\n" + "import org.joda.time.DateTime\n" + super.code

  override def Table = new Table(_) {
    override def Column = new Column(_) {

      // munge rawType -> SQL column type HERE (scaladoc in Slick 2.1.0 is outdated or incorrect, GeneratorHelpers#mapJdbcTypeString does not exist)
      // you can filter on model.name for the column name or model.tpe for the column type
      // your IDE won't like the String here but don't worry, the return type the compiler expects here is String
      override def rawType = model.tpe match {
        case "java.sql.Timestamp"               => "DateTime" // kill j.s.Timestamp
        case _ => {
//          println(s"${model.table.table}#${model.name} tpe=${model.tpe} rawType=${super.rawType}")
          super.rawType
        }
      }
    }
  }
}

Then write a simple app harness to run code generation:

import scala.slick.driver.JdbcProfile

object CodeGen extends App {

  // http://slick.typesafe.com/doc/2.1.0/code-generation.html

  val slickDriver = "scala.slick.driver.PostgresDriver"  // TODO: replace this with your Slick driver
  val jdbcDriver = "org.postgresql.Driver"               // TODO: replace this with your JDBC driver
  val url = "jdbc:postgresql://127.0.0.1:5432/foo"       // TODO: replace this with your database's JDBC URL
  val outputFolder = "src/main/scala"                    // TODO: or whatever output folder you're in the mood for
  val pkg = "foo"                                        // TODO: your package name
  val user = "postgres"                                  // TODO: database username - optional, use forURL supports both with and without credentials
  val password = ""                                      // TODO: database password - optional, use forURL supports both with and without credentials

  val driver: JdbcProfile = scala.slick.driver.PostgresDriver  // TODO: replace this with your Slick driver

  val db = {
    // UNCOMMENT this if your database doesn't need credentials
    // driver.simple.Database.forURL(url, jdbcDriver)
    driver.simple.Database.forURL(url, driver = jdbcDriver, user = user, password = password)
  }

  db.withSession { implicit session =>
    new CustomSourceCodeGenerator(driver.createModel()).writeToFile(slickDriver, outputFolder, pkg)
  }

}

You can run and keep adjusting your source code generation using sbt run. If you get compile errors on the generated Tables.scala, just delete it and try again.

For Slick 1.x

libraryDependencies += "com.github.tototoshi" %% "slick-joda-mapper" % "0.4.1"
import com.github.tototoshi.slick.JodaSupport._

Example

https://github.com/tototoshi/slick-joda-mapper/blob/master/src/test/scala/com/github/tototoshi/slick/JodaSupportSpec.scala

Changelog

2.8.0

  • Updated slick to 3.4.1

2.7.1

  • Updated joda-time

2.7.0

  • Added a workaround for a problem related to timezone

2.6.0

  • Update dependencies
  • Add Scala 3 to cross build

2.5.0

  • Update dependencies
  • Migrate from travis-ci to GitHub Actions
  • Add explicit type annotations to implicit val
  • etc

2.4.2

  • Update joda-time to 2.10.3

2.4.1

  • Support Scala 2.13.0
  • Support Slick 3.3.1

2.4.0

  • Support Slick 3.3.0

2.3.0

  • Support Slick 3.2.0

2.2.0

  • Use JdbcProfile since JdbcDriver is deprecated.

2.1.0

  • Removed deprecated Access support

2.0.0

  • Support Slick 3.0.0.

1.2.0

  • Support Slick 2.1.0.

1.1.0

  • Added DateTimeZone support.

1.0.1

  • Added JdbcJodaSupport.

slick-joda-mapper's People

Contributors

aukgit avatar dependabot[bot] avatar dk8996 avatar guersam avatar mslinn avatar onsails avatar paul-lysak avatar rktoomey avatar scala-steward avatar tototoshi avatar xuwei-k avatar y-yu avatar yurique avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slick-joda-mapper's Issues

How to use slick-joda-mapper with injected play.api.db.slick.DatabaseConfigProvider ?

I'd like to use dependency injection to make my choice of database configurable. In other words, I don't want to hard code the database by doing something like

import com.github.tototoshi.slick.H2JodaSupport._

However, the example in the readme does not work with the latest Play 2.4.x, Slick 3.1.0 and slick-joda-mapper 2.1.0

import javax.inject.Inject
import com.github.tototoshi.slick.GenericJodaSupport
import org.joda.time.DateTime
import play.api.db.slick.DatabaseConfigProvider
import slick.driver.JdbcProfile

class MyRepository @Inject()(dbConfigProvider: DatabaseConfigProvider) {

  val dbConfig = dbConfigProvider.get[JdbcProfile]
  import dbConfig.driver.api._

  // Incompatible types !!
  // dbConfig.driver is an instance of JdbcProfile, not JdbcDriver
  private object PortableJodaSupport extends GenericJodaSupport(dbConfig.driver)

  import PortableJodaSupport._

  class MyTable(tag: Tag) extends Table[(Long, String, DateTime)](tag, "my_table") {
     def id = column[Long]("id", O.PrimaryKey)
     def name = column[String]("name")
     def time = column[DateTime]("date_time")
     def * = (id, name, time)
  }
  // ...
}

I don't see an elegant way to get hold of Slick driver. Ugly workaround would be to read the configuration and try to find the Slick driver object in the classpath.

GenericJodaSupport should be trait

Using something like:

trait GenericJodaSupport { driver: JdbcDriver =>
  // code
}

object PostgresJodaSupport extends PostgresDriver with GenericJodaSupport

instead of current

class GenericJodaSupport(val driver: JdbcDriver) {
  // code
}

object PostgresJodaSupport extends GenericJodaSupport(PostgresDriver)

would be better if somebody would like to use GenericJodaSupport as mixin with slick.driver.API.

That way you don't need import *Support object every time separately.

Is it possible to use specified TZ in DateTime?

I create DateTime with TZ UTC before I persist and then read them back.
Both in the database and in the result the TZ is set to default for the system.

I use postgres and the column is of type 'timestamptz'.
The code inserts the DateTime with ${dateTime} :: timestamptz

Am I missing something?

Throw exception for few date and time columns in a table for Microsoft SQL Server

Loading file:/..../project/liferay-MSSQL2/ce-liferay-portal-6.2-ce-ga4/tomcat-7.0.42/work/Catalina/localhost/learn-portlet/loader/portal-ext.properties
08:51:08,607 ERROR [ContainerBackgroundProcessor[StandardEngine[Catalina]]][HotDeployImpl:230] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for learn-portletlearn-portlet
com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering hook for learn-portletlearn-portlet
        at com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener.throwHotDeployException(BaseHotDeployListener.java:46)
        at com.liferay.portal.deploy.hot.HookHotDeployListener.invokeDeploy(HookHotDeployListener.java:314)
        at com.liferay.portal.deploy.hot.HotDeployImpl.doFireDeployEvent(HotDeployImpl.java:227)
        at com.liferay.portal.deploy.hot.HotDeployImpl.fireDeployEvent(HotDeployImpl.java:96)
        at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:28)
        at com.liferay.portal.kernel.servlet.PluginContextListener.fireDeployEvent(PluginContextListener.java:164)
        at com.liferay.portal.kernel.servlet.PluginContextListener.doPortalInit(PluginContextListener.java:154)
        at com.liferay.portal.kernel.util.BasePortalLifecycle.portalInit(BasePortalLifecycle.java:44)
        at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:74)
        at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:58)
        at com.liferay.portal.kernel.util.BasePortalLifecycle.registerPortalLifecycle(BasePortalLifecycle.java:54)
        at com.liferay.portal.kernel.servlet.PluginContextListener.contextInitialized(PluginContextListener.java:116)
        at com.liferay.portal.kernel.servlet.SecurePluginContextListener.contextInitialized(SecurePluginContextListener.java:151)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3954)
        at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1270)
        at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1439)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:315)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
        at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLException: A table can only have one timestamp column. Because table 'LEARN_CERT_STATE' already has one, the column 'USER_JOINED_DATE' cannot be added.
        at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
        at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2820)
        at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2258)
        at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:632)
        at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
        at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
        at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.execute(JtdsPreparedStatement.java:558)
        at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:823)
        at scala.slick.driver.JdbcInvokerComponent$DDLInvoker$$anonfun$create$1$$anonfun$apply$mcV$sp$1$$anonfun$apply$1.apply(JdbcInvokerComponent.scala:50)
        at scala.slick.driver.JdbcInvokerComponent$DDLInvoker$$anonfun$create$1$$anonfun$apply$mcV$sp$1$$anonfun$apply$1.apply(JdbcInvokerComponent.scala:50)
        at scala.slick.jdbc.JdbcBackend$SessionDef$class.withPreparedStatement(JdbcBackend.scala:191)
        at scala.slick.jdbc.JdbcBackend$BaseSession.withPreparedStatement(JdbcBackend.scala:389)
        at scala.slick.driver.JdbcInvokerComponent$DDLInvoker$$anonfun$create$1$$anonfun$apply$mcV$sp$1.apply(JdbcInvokerComponent.scala:50)
        at scala.slick.driver.JdbcInvokerComponent$DDLInvoker$$anonfun$create$1$$anonfun$apply$mcV$sp$1.apply(JdbcInvokerComponent.scala:49)
        at scala.collection.Iterator$class.foreach(Iterator.scala:742)
        at scala.collection.Iterator$JoinIterator.foreach(Iterator.scala:191)
        at scala.slick.driver.JdbcInvokerComponent$DDLInvoker$$anonfun$create$1.apply$mcV$sp(JdbcInvokerComponent.scala:49)
        at scala.slick.driver.JdbcInvokerComponent$DDLInvoker$$anonfun$create$1.apply(JdbcInvokerComponent.scala:49)
        at scala.slick.driver.JdbcInvokerComponent$DDLInvoker$$anonfun$create$1.apply(JdbcInvokerComponent.scala:49)
        at scala.slick.jdbc.JdbcBackend$BaseSession.withTransaction(JdbcBackend.scala:419)
        at scala.slick.driver.JdbcInvokerComponent$DDLInvoker.create(JdbcInvokerComponent.scala:48)
        at com.arcusys.learn.liferay.SlickDbCreator$$anonfun$create$1$$anonfun$apply$1.apply(SetupDatabase.scala:87)
        at com.arcusys.learn.liferay.SlickDbCreator$$anonfun$create$1$$anonfun$apply$1.apply(SetupDatabase.scala:87)
        at scala.collection.immutable.List.foreach(List.scala:381)

LocalTime Mapper

Hi Toshiyuki,

Thanks for the wonderful library. I request you too add LocalTime class support to it.

Regards,
Abhishek

java.lang.NoClassDefFoundError: scala/slick/profile/StandardParameterizedQueries

I get this exception on running -

Caused by: java.lang.NoClassDefFoundError: scala/slick/profile/StandardParameterizedQueries
at com.github.tototoshi.slick.JodaLocalDateSupport$class.$init$(JodaSupport.scala:38) ~[slick-joda-mapper_2.10-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at com.github.tototoshi.slick.JodaSupport$.(JodaSupport.scala:74) ~[slick-joda-mapper_2.10-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at com.github.tototoshi.slick.JodaSupport$.(JodaSupport.scala) ~[slick-joda-mapper_2.10-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
at in.bharathwrites.domain.BlogDAO$Blogs.date(BlogDAO.scala:20) ~[classes/:na]

I think my code is straightforward... the complaining file is here

Am still a Slick and Scala newbie. So I could be very dumb and missing something trivial...

BTW, am using Slick 2.0.0-M3

Feature Request: Support extracting date components (year, month, ...)

I'm using slick-joda-mapper with its GenericJodaSupport trait. I want to be able to write queries like

val query = MyTable.filter(entry => year(entry.date) === my_year)

MySQL has the YEAR(...) function for that, PostgreSQL has EXTRACT(YEAR FROM ...).
I've written some own code that enables this (see below), but it would be cool if this functionality would be imported by GenericJodaSupport already.

Here code that makes this work in MySQL:

val year = SimpleFunction.unary[DateTime,Int]("YEAR")

And here for PostgreSQL:

val year = SimpleExpression.unary[DateTime, Int] { (node, queryBuilder) =>
   queryBuilder.sqlBuilder += "extract(year from "
   queryBuilder.expr(node)
   queryBuilder.sqlBuilder += ")"
}

Same is possible for month, day, hour, ...

LocalDate Query

Hi tototoshi,

I am not able to query for a specific date or filter for specific date. Not sure how to write where clause for LocalDate. Can you help?

Thanks & Regards,
Abhishek

Cannot subtract instants

I would expect subtracting two instants yields an interval, but it gives a type error:

LiteralColumn(Instant.now()) - record.loggedAt

Error:(12, 91) value - is not a member of scala.slick.lifted.LiteralColumn[org.joda.time.Instant]

slick 3.3.2 is out

I just noticed when upgrading my libraries, that slick 3.3.2 is already out. No immediate need to do anything, but maybe you want to upgrade here as well.

Use DATETIME with MySQL?

I read that TIMESTAMP in MySQL is having a lot of magic that you usually want to avoid when using Slick. Have you considered mapping it into SQL type DATETIME instead?

Cannot find implicit value for parameter (Slick 3.0.0)

Just added slick-joda-mapper to our project, but alas... does not seem to be working. We are on Slick 3.0.0 and Postgres 9.4.

build.sbt says:

    "joda-time" % "joda-time" % "2.7",
    "org.joda" % "joda-convert" % "1.7",
    "com.github.tototoshi" %% "slick-joda-mapper" % "2.0.0",

But compile says:

[error] /Users/zbeckman/Projects/Glimpulse/Server-2/project/glimpulse-server/app/models/GPGlimple.scala:20: could not find implicit value for parameter tt: slick.ast.TypedType[org.joda.time.DateTime]
[error]     def created = column[DateTime]("d_timestamp_created")

For completeness, here's the important bits of the model:

import org.joda.time.DateTime
import slick.driver.PostgresDriver.api._
import com.github.tototoshi.slick.PostgresJodaSupport

class GPGlimpleModel(tag: Tag) extends Table[GPGlimple](tag, GPGlimpleModelMeta.schema, GPGlimpleModelMeta.table) {
    def id = column[Long]("n_glimple_id", O.PrimaryKey)
    def created = column[DateTime]("d_timestamp_created")

DateTime comparisons don't work with SQLite

The following SQL syntax (generated by slick):

x2."run_date" >= {ts '2014-03-28 00:00:00.0'}

is not valid with SQLite, so it causes any such queries to fail.

This comes from a slick query like this:

val today = new DateTime().withTimeAtStartOfDay()
val yesterday = today.minusDays(1)
val yesterdaysRun = ReportRuns.forReport(report).filter {run => 
    run.runDate >= yesterday && run.runDate < today
}.sortBy(_.runDate.desc).firstOption

So any slick query that compares joda DateTime objects will fail. SQLite stores timestamps as a long I believe.

Here is a slightly deeper discussion on Stack Overflow as I was debugging this problem:

http://stackoverflow.com/questions/22703609/why-am-i-getting-a-sqlite-error-using-sqlite3-with-scala-slick-joda-datetime/22739584?noredirect=1#comment34660285_22739584

Wrong SQLLiteral if client runs on non-UTC machine

Currently the code goes from DateTime/LocalDateTime/... to Timestamp...
https://github.com/tototoshi/slick-joda-mapper/blob/master/src/main/scala/com/github/tototoshi/slick/converter/JodaSqlTypeCoverter.scala#L61

...and then calls a toString on the timestamp
https://github.com/tototoshi/slick-joda-mapper/blob/master/src/main/scala/com/github/tototoshi/slick/JodaTypeMapper.scala#L108

but this is wrong, eg

Joda DateTime toString

2014-04-24T08:30:00.000+02:00

Timestamp toString

2014-04-24 08:30:00.0

Literal

{ts '2014-04-24 08:30:00.0'}

My db server is on UTC, my web app on Europe/Brussels (currently +02.00)

The literal should have been

{ts '2014-04-24 06:30:00.0'}

Three workarounds

  • compile the query which will avoid the use of literals and delegate to the driver
    http://slick.typesafe.com/doc/2.0.0/queries.html#compiled-queries
  • set timezone on the jvm, eg -Duser.timezone="UTC" but this might break other stuff
  • manually change the millis of the provided date to get the desired date literal (I consider this a very ugly hack)

The toString on Timestamp is local timezone dependent and should not be used for a sql literal.
I suggest using a DateTimeFormat and calling withZone(DateTimeZone.UTC) on the Formatter (DateTimeFormat is thread-safe and immutable, and the formatters it returns are as well.)

I'm not sure that my proposed solution is always correct, what if the server does not run on UTC? It should at least be configurable/pluggable how the literal is built. Some jdbc drivers also have parameters to tweak date/time behaviour (eg useJDBCCompliantTimezoneShift on MySQL)

Inserting or updating dates is not affected by this issue as those are not using literals and delegate to the driver.

Error in where clause

Hello,

I am trying to query a date like so

val now = new DateTime

Then using existing query object

query.where(_.eventDate >= now.minusHours(5))

but I get the error

value >= is not a member of scala.slick.lifted.Column[org.joda.time.DateTime]

Any ideas ?

Support 3.0.0-M1

[error] /Users/toshi/work/scala/slick-joda-mapper/src/main/scala/com/github/tototoshi/slick/JodaTypeMapper.scala:39: object creation impossible, since:
[error] it has 3 unimplemented members.
[error] /** As seen from object TypeMapper, the missing signatures are as follows.
[error]  *  For convenience, these are usable as stub implementations.
[error]  */
[error]   def getValue(r: java.sql.ResultSet,idx: Int): org.joda.time.DateTimeZone = ???
[error]   def setValue(v: org.joda.time.DateTimeZone,p: java.sql.PreparedStatement,idx: Int): Unit = ???
[error]   def updateValue(v: org.joda.time.DateTimeZone,r: java.sql.ResultSet,idx: Int): Unit = ???
[error]   object TypeMapper extends driver.DriverJdbcType[DateTimeZone]
[error]          ^
[error] /Users/toshi/work/scala/slick-joda-mapper/src/main/scala/com/github/tototoshi/slick/JodaTypeMapper.scala:67: object creation impossible, since:
[error] it has 3 unimplemented members.
[error] /** As seen from object TypeMapper, the missing signatures are as follows.
[error]  *  For convenience, these are usable as stub implementations.
[error]  */
[error]   def getValue(r: java.sql.ResultSet,idx: Int): org.joda.time.LocalDate = ???
[error]   def setValue(v: org.joda.time.LocalDate,p: java.sql.PreparedStatement,idx: Int): Unit = ???
[error]   def updateValue(v: org.joda.time.LocalDate,r: java.sql.ResultSet,idx: Int): Unit = ???
[error]   object TypeMapper extends driver.DriverJdbcType[LocalDate]
[error]          ^
[error] /Users/toshi/work/scala/slick-joda-mapper/src/main/scala/com/github/tototoshi/slick/JodaTypeMapper.scala:96: object creation impossible, since:
[error] it has 3 unimplemented members.
[error] /** As seen from object TypeMapper, the missing signatures are as follows.
[error]  *  For convenience, these are usable as stub implementations.
[error]  */
[error]   def getValue(r: java.sql.ResultSet,idx: Int): org.joda.time.DateTime = ???
[error]   def setValue(v: org.joda.time.DateTime,p: java.sql.PreparedStatement,idx: Int): Unit = ???
[error]   def updateValue(v: org.joda.time.DateTime,r: java.sql.ResultSet,idx: Int): Unit = ???
[error]   object TypeMapper extends driver.DriverJdbcType[DateTime]
[error]          ^
[error] /Users/toshi/work/scala/slick-joda-mapper/src/main/scala/com/github/tototoshi/slick/JodaTypeMapper.scala:125: object creation impossible, since:
[error] it has 3 unimplemented members.
[error] /** As seen from object TypeMapper, the missing signatures are as follows.
[error]  *  For convenience, these are usable as stub implementations.
[error]  */
[error]   def getValue(r: java.sql.ResultSet,idx: Int): org.joda.time.Instant = ???
[error]   def setValue(v: org.joda.time.Instant,p: java.sql.PreparedStatement,idx: Int): Unit = ???
[error]   def updateValue(v: org.joda.time.Instant,r: java.sql.ResultSet,idx: Int): Unit = ???
[error]   object TypeMapper extends driver.DriverJdbcType[Instant]
[error]          ^
[error] /Users/toshi/work/scala/slick-joda-mapper/src/main/scala/com/github/tototoshi/slick/JodaTypeMapper.scala:154: object creation impossible, since:
[error] it has 3 unimplemented members.
[error] /** As seen from object TypeMapper, the missing signatures are as follows.
[error]  *  For convenience, these are usable as stub implementations.
[error]  */
[error]   def getValue(r: java.sql.ResultSet,idx: Int): org.joda.time.LocalDateTime = ???
[error]   def setValue(v: org.joda.time.LocalDateTime,p: java.sql.PreparedStatement,idx: Int): Unit = ???
[error]   def updateValue(v: org.joda.time.LocalDateTime,r: java.sql.ResultSet,idx: Int): Unit = ???
[error]   object TypeMapper extends driver.DriverJdbcType[LocalDateTime]
[error]          ^
[error] /Users/toshi/work/scala/slick-joda-mapper/src/main/scala/com/github/tototoshi/slick/JodaTypeMapper.scala:183: object creation impossible, since:
[error] it has 3 unimplemented members.
[error] /** As seen from object TypeMapper, the missing signatures are as follows.
[error]  *  For convenience, these are usable as stub implementations.
[error]  */
[error]   def getValue(r: java.sql.ResultSet,idx: Int): org.joda.time.LocalTime = ???
[error]   def setValue(v: org.joda.time.LocalTime,p: java.sql.PreparedStatement,idx: Int): Unit = ???
[error]   def updateValue(v: org.joda.time.LocalTime,r: java.sql.ResultSet,idx: Int): Unit = ???
[error]   object TypeMapper extends driver.DriverJdbcType[LocalTime]
[error]          ^
[warn] one warning found
[error] 6 errors found
[error] (compile:compile) Compilation failed
[error] Total time: 30 s, completed 2014/12/20 1:46:50

Unable to find 2.0.0.0-SNAPSHOT version

Hi team,

First of all, thanks a lot for developing such a useful framework.

I just tried to add " "com.github.tototoshi" %% "slick-joda-mapper" % "2.0.0-SNAPSHOT"" to my build.sbt file, but it is thoriwng "unresolved Dependency" error.

sbt.ResolvedException: unresolved dependency: com.github.totoshi#slick-jodamapper_2.11;2.0.0-SNAPSHOT: not found.

build sbt screenshot
joda_mapper_error

Please help!

Many Thanks,

Joo

LocalDateTime

Could you please add support for LocalDateTime? Thanks.

Slick 2.0 support?

Can you please add support for Slick 2.0? I know it's in pre-release at the moment, but hopefully a 2.0 final won't be too far away :-)

Support for Joda Time Instant type?

I tested locally implementing (based on slick-joda-mapper 1.0, which I'm currently using because I'm not using the newer slick yet) a converter for Joda Time Instant with an implementation just like your DateTime implementation. The straightforward implementation seemed to work.

Any chance you'd be willing to put in official support for Instant in both your 1.x and 2.x codelines? I'd love to remove my provisional implementation in preference for something from this module if possible.

Thanks for the very useful module!

Cannot find implicit TypeMapper?

Hi!

I cannot get it to run. The test below gives me this compiler error:

- not enough arguments for method column: (implicit tm: 
 scala.slick.lifted.TypeMapper[org.joda.time.DateTime])scala.slick.lifted.Column[org.joda.time.DateTime]. Unspecified value parameter tm.
- could not find implicit value for parameter tm: scala.slick.lifted.TypeMapper[org.joda.time.DateTime]

What am i missing? i am using
"com.typesafe.play" %% "play-slick" % "0.4.0",
"com.github.tototoshi" %% "slick-joda-mapper" % "1.0.0-SNAPSHOT"
with play 2.1.1

package models.slick

import com.github.tototoshi.slick.JodaSupport._
import org.joda.time.DateTime
import scala.slick.driver.H2Driver.simple._

object Test extends Table[(DateTime)]("TEST"){
    def testDateTime = column[DateTime]("TEST_DATE_TIME")
}

Cheers

GenericJodaSupport Slick 3.0 play-slick 1.0.0 README example not working

Per the README, you can create your own agnostic adapter for play-slick via:

object PortableJodaSupport extends com.github.tototoshi.slick.GenericJodaSupport(play.api.db.slick.Config.driver)

However, that no longer seems to exist. Specifically, play.api.db.slick.Config doesn't seem to exist. Perhaps this needs an update? I can't seem to find where this has moved.

Thanks!

Problem with Slick 2.0

I'm trying to use Slick 2.0.0-RC1, along with slick-joda-mapper 1.0.0-SNAPSHOT

Everything compiles fine, but at runtime I am getting the following exception in the QueryCompiler every time I try to query for an object that has a Joda object (LocalDate in this instance).

error scala.slick.SlickException: JdbcProfile has no TypeInfo for type com.github.tototoshi.slick.JodaLocalDateMapper$TypeMapper$/DATE
scala.slick.SlickException: JdbcProfile has no TypeInfo for type com.github.tototoshi.slick.JodaLocalDateMapper$TypeMapper$/DATE
at scala.slick.driver.JdbcTypesComponent$class.typeInfoFor(JdbcTypesComponent.scala:127)
at scala.slick.driver.JdbcDriver$.typeInfoFor(JdbcProfile.scala:100)

Is this something known?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.