Mapper: Add ability to provide a encoding/decoding functions to ModelOptions.columns

Description

Hi,

We have a common use case where we have a complex object with various sub objects/arrays that can't easily be represented in a table schema. We use a blob column to store the serialized object and just use the other columns for the primary key or filtering. During insertion we want to be able to serialize and set the blob as the mapper is mapping the columns. This could be achieved during insertion by providing an encoding function to the ModelOptions. We are trying to avoid building a mapping layer on top the cassandra-driver mapper.

Example Object


Example Schema

 

Ideal Configuration:

Environment

None

Pull Requests

None

Activity

Show:
Jorge Bay Gondra
January 9, 2020, 9:31 AM

Indeed! mapping conversions is a missing feature of the mapper. I agree that it would be nice to have.

I really like your API proposal for mapping configuration, I would suggest 2 things:

  • Encoding and decoding are overused words across the driver, I think we should avoid to introduce a new thing named encoding. I would suggest the conversion functions to be called: “toModel” (db representation to model representation) and “fromModel” (model representation to db).

  • We should still support specifying the column to property name.

 

With that in mind, a complete example would be:

If you would like to submit a pull request, and would like some input in the process, feel free to open one and mark it as a “work in progress” on the repo.

Rafael Fernandez
January 10, 2020, 12:18 AM

Both sounds good.

Regarding a pull request, I am quite limited in time. What would be your time estimate to complete this task? 5, 10, 20, 40 hours?

Jorge Bay Gondra
January 10, 2020, 9:06 AM

I am quite limited in time

I understand, I was just suggesting that if you wanted to contribute this feature, you can even start with a “WIP” pull request

About the estimation, it depends on the level of familiarity with the existing code, usually it takes some time to ramp up.

Done

Assignee

Jorge Bay Gondra

Reporter

Rafael Fernandez

Reviewer

None

Fix versions

Labels

None

Components

PM Priority

None

Affects versions

Priority

Major
Configure