How EXACTLY is Slick's SimpleLiteral used?

KArvan

I want to use some extra features of PostgreSQL in my code but I don't want to fill the place with SQL string interpolations.

Currently I have:

/** Use 'now()' through Slick. */
val psqlNow = SimpleFunction.nullary[java.sql.Date]("now")

//Not really my code, but we only care for 2 lines.
def aQuery(limiter: Column[Int]) = {
  myTable
    .filter(_.validFrom >= psqlNow)
    .filter(_.validUntil <= psqlNow)
    .filter(_.fakeId === limiter).map(e => (e.fakeId, e.name)
}

But I want to use 'CURRENT_DATE', which I is a literal (and using it in place of "now" throws an exception). Can someone provide an actual example, because I can't get this to compile:

/** Use 'CURRENT_DATE' through Slick. */
val psqlNow = SimpleLiteral("CURRENT_DATE")(...WHAT GOES HERE?...)

//Not really my code, but we only care for 2 lines.
def aQuery(limiter: Column[Int]) = {
  myTable
    .filter(_.validFrom >= psqlNow)
    .filter(_.validUntil <= psqlNow)
    .filter(_.fakeId === limiter).map(e => (e.fakeId, e.name)
}

And I also want to change the following to lifted Slick, can I do it with SimpleLiteral (to somehow put 'count(*) OVER() recordsFiltered' into the generated query?

SELECT *, count(*) OVER() recordsFiltered FROM example
WHERE id = $1

The examples are trivial, the actual code is a series of folds over filtering criteria.

cvogt
import scala.slick.ast.TypedType

val current_date = Column.forNode[java.sql.Date](new SimpleLiteral("CURRENT_DATE")(implicitly[TypedType[java.sql.Date]]))

does the trick. Better support is missing at the moment.

I added a PR, so in Slick 2.2 it will be supported like this:

val current_date = SimpleLiteral[java.sql.Date]("CURRENT_DATE")

See https://github.com/slick/slick/pull/981

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How and where exactly is htmlspecialchars() or {{}} to be used?

From Dev

How are reactive streams used in Slick for inserting data

From Dev

What exactly is txPower for Bluetooth LE and how is it used?

From Dev

How exactly is my 'missing' memory being used?

From Dev

How exactly is the WWDR Intermediate Certificate used when signing an app?

From Dev

How exactly IAppBuilder.CreatePerOwinContext<T> should be used?

From Dev

What exactly are MultiPartEntity and Form Data? How are they used to upload images in android?

From Dev

How exactly are the Get and Set methods used and implemented in c#

From Dev

How exactly is the WWDR Intermediate Certificate used when signing an app?

From Dev

How exactly is a subnet mask used when determining where to send a packet to?

From Dev

What exactly is VRAM used for?

From Dev

How Nodejs's internal threadpool works exactly?

From Dev

How exactly does Tomcat's Threadpool work

From Dev

How exactly is React's Virtual DOM faster?

From Dev

How to setup username and password with Slick's source code generator?

From Dev

How to return compound types in Slick's Case-If-Then-Else

From Dev

How to return full row using Slick's insertOrUpdate

From Dev

How can I avoid Slick's model declaration verbosity and repetitiveness

From Dev

How to setup username and password with Slick's source code generator?

From Dev

Where exactly is REST authentication used?

From Dev

'->' operator in C and how it's used

From Dev

How exactly works the Spring Security intercept-url's?

From Dev

How does Python's matplotlib.pyplot.quiver exactly work?

From Dev

Java Applet: setForeground() what exactly it does? and how to see it's effect?

From Dev

How exactly does perl's -0 option work?

From Dev

How exactly works the Spring Security intercept-url's?

From Dev

How to make my input field output exactly what's inputted?

From Dev

Scala/Slick - JSON writers for case class used to map slick tables

From Dev

How can I get the exactly ip address which used to connect in iOS?

Related Related

  1. 1

    How and where exactly is htmlspecialchars() or {{}} to be used?

  2. 2

    How are reactive streams used in Slick for inserting data

  3. 3

    What exactly is txPower for Bluetooth LE and how is it used?

  4. 4

    How exactly is my 'missing' memory being used?

  5. 5

    How exactly is the WWDR Intermediate Certificate used when signing an app?

  6. 6

    How exactly IAppBuilder.CreatePerOwinContext<T> should be used?

  7. 7

    What exactly are MultiPartEntity and Form Data? How are they used to upload images in android?

  8. 8

    How exactly are the Get and Set methods used and implemented in c#

  9. 9

    How exactly is the WWDR Intermediate Certificate used when signing an app?

  10. 10

    How exactly is a subnet mask used when determining where to send a packet to?

  11. 11

    What exactly is VRAM used for?

  12. 12

    How Nodejs's internal threadpool works exactly?

  13. 13

    How exactly does Tomcat's Threadpool work

  14. 14

    How exactly is React's Virtual DOM faster?

  15. 15

    How to setup username and password with Slick's source code generator?

  16. 16

    How to return compound types in Slick's Case-If-Then-Else

  17. 17

    How to return full row using Slick's insertOrUpdate

  18. 18

    How can I avoid Slick's model declaration verbosity and repetitiveness

  19. 19

    How to setup username and password with Slick's source code generator?

  20. 20

    Where exactly is REST authentication used?

  21. 21

    '->' operator in C and how it's used

  22. 22

    How exactly works the Spring Security intercept-url's?

  23. 23

    How does Python's matplotlib.pyplot.quiver exactly work?

  24. 24

    Java Applet: setForeground() what exactly it does? and how to see it's effect?

  25. 25

    How exactly does perl's -0 option work?

  26. 26

    How exactly works the Spring Security intercept-url's?

  27. 27

    How to make my input field output exactly what's inputted?

  28. 28

    Scala/Slick - JSON writers for case class used to map slick tables

  29. 29

    How can I get the exactly ip address which used to connect in iOS?

HotTag

Archive