Skip to content

Model stored/encoded as a delimited string in the database? #1466

Answered by meirdev
kennedy asked this question in Questions
Discussion options

You must be logged in to vote

I recommend you use a JSON column for details. anyway, you have to create a new type:

from sqlalchemy.types import TypeDecorator, String

class ActualDataType(TypeDecorator):
    impl = String

    def process_bind_param(self, value, dialect):
        if value is not None:
            value = ";".join(f"{k}={v}" for k, v in value.dict().items() if v is not None)
        return value

    def process_result_value(self, value, dialect):
        if value is not None:
            d = {}
            for value in value.split(";"):
                k, v = value.split("=")
                d[k] = v
            value = ActualData(**d)
        return value

for JSON:

from sqlalchemy.types import TypeD…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@YuriiMotov
Comment options

Answer selected by YuriiMotov
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested investigate
3 participants
Converted from issue

This discussion was converted from issue #479 on August 07, 2025 14:14.