Skip to content

Automatically format the list of update columns?Β #136

@landlockedsurfer

Description

@landlockedsurfer

Hi @AugustNagro !

I'm currently trying out Magnum and things are working really nicely!! 😊 Thanks for this wonderful library! πŸ™

So far there was just one use case where I got stuck. I tried to format an upsert statement in Postgres SQL but could not find anything to automate the formatting of the set clause.
E.g.:

INSERT INTO user (id, name, age) VALUES (?, ?, ?)
ON CONFLICT (id) DO UPDATE SET 
    name = ?,
    age = ?;

or the "progresque" version:

INSERT INTO user (id, name, age) VALUES (?, ?, ?)
ON CONFLICT (id) DO UPDATE SET 
    name = EXCLUDED.name,
    age = EXCLUDED.age;

Could something like TableInfo.updateCols[T](value:T) help automate the formatting of the set clause?

sql"INSERT INTO $table ${table.insertColumns} values ($user) ON CONFLICT (${user.id}) DO UPDATE SET ${table.updsateCols(user)}"

This would be very useful when new fields are added since this would automatically include the update of values for any newly added columns.

Kind regards,
Manfred

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions