Filter Optional JSONB columns mapped to CustomType
See original GitHub issueI have an optional(nullable) JSONB column which is mapped to Scala Case class.
def myColumn: Rep[MyClass] = column[MyClass]("my_column")
Implicit mapping looks like:
case class MyClass(name: String, number: Int, boolean: Boolean)
def implicitJsonMapper[T: ClassTag](implicit format: OFormat[T]): JdbcType[T] with BaseTypedType[T] =
MappedJdbcType.base[T, JsValue](Json.toJson(_), _.as[T])
implicit val myClassMapper = implicitJsonMapper[MyClass]
How can I filter based on json keys inside “myColumn” column?
Obviously this didn’t work:
TableQuery[MyTable].filter(_.myColumn +> "boolean" === true)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Storing json, jsonb, hstore, xml, enum, ipaddr, etc fails with ...
Methods for implementing custom type handlers are driver-, language- and ORM-specific. Here's an example for Java and Hibernate for json .
Read more >How to use PostgreSQL's JSONB data type with Hibernate
If you want to use a JSONB column with Hibernate 6, I have great news for you. ... In Hibernate 4 and 5,...
Read more >12: 9.15. JSON Functions and Operators - PostgreSQL
A JSON null value is converted to a SQL null in all cases. · If the output column is of type json or...
Read more >Slick Tutorial - Rock the JVM Blog
Slick Table maps the table fields to the case class. ... In the above code, we are filtering the personal column which is...
Read more >Custom Types - MikroORM
Converts a value from its JS representation to its serialized JSON form of this type. ... we can use customType option and provide...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@lakshmankollipara here’s the codes of
PlayJsonImplicits
,Here, the points are
implicit def playJsonColumnExtensionMethods(c: Rep[JsValue])
andimplicit def playJsonOptionColumnExtensionMethods(c: Rep[Option[JsValue]])
.So to support
TableQuery[MyTable].filter(_.myColumn +> "boolean" === true)
, you need add definitions like these,I didn’t test it. But you can give it a try.
@1gorsh ok! <g-emoji alias="smile" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f604.png" class="emoji">😄</g-emoji>