Skip to content

Feature Request: Conditional Upsert in Postgrest-Dart #998

Open
@BottlePumpkin

Description

@BottlePumpkin

Feature Request: Conditional Upsert in Postgrest-Dart

Is your feature request related to a problem? Please describe.
I'm always frustrated when I need to upsert data conditionally. Currently, the upsert method in Postgrest-Dart does not support conditional logic. This means that if I want to upsert a record only if certain conditions are met (e.g., the new value is greater than the existing value), I need to perform multiple steps: fetching the existing record, comparing the values, and then deciding whether to proceed with the upsert. This introduces unnecessary complexity and additional network requests.

Describe the solution you'd like
I would like to propose the addition of conditional upsert functionality to the Postgrest-Dart library. The upsert method should support conditional logic using comparison operators like less than (lt), greater than (gt), etc. This would streamline the process and reduce the number of steps needed to perform conditional upsert operations.

Example Usage:

final response = await client.from('table_name').upsert(data, onConflict: 'user_id', lt: {'score': currentScore});

In this example, the upsert will only proceed if the score in the existing record is less than the currentScore in the new data.

Describe alternatives you've considered
An alternative solution is to manually fetch the existing record, compare the values client-side, and then decide whether to proceed with the upsert. However, this approach introduces additional network overhead and complexity in the client-side code. Using RPC (remote procedure call) functions is another alternative, but it requires setting up and maintaining additional server-side logic, which can be cumbersome for simple conditional upsert operations.

Additional context
Adding conditional logic to the upsert method would significantly improve its functionality and flexibility, making it more useful for a variety of data operations. It would reduce the number of network requests, simplify client-side code, and enhance the efficiency of data operations. If the team agrees that this feature would be beneficial, I would be happy to contribute to the implementation and submit a pull request.

Thank you for considering this feature request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedThis issue is blocked by another issueenhancementNew feature or requestpostgrestThis issue or pull request is related to postgrest

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions