Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add if_not_exists in OpWrite to make behavior more clear #5286

Closed
Xuanwo opened this issue Nov 5, 2024 Discussed in #5223 · 4 comments · Fixed by #5305
Closed

Add if_not_exists in OpWrite to make behavior more clear #5286

Xuanwo opened this issue Nov 5, 2024 Discussed in #5223 · 4 comments · Fixed by #5305
Assignees
Labels
core good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Xuanwo
Copy link
Member

Xuanwo commented Nov 5, 2024

Discussed in #5223

Originally posted by Xuanwo October 22, 2024
OpenDAL now supports the use of "*" in if_none_match to perform conditional write operations:

let _ = op.write_with(path, bs).if_none_match("*").await?;

However, it's somewhat difficult to grasp at first glance. Do you think it's a good idea to include if_not_exists?

So we can write code like:

let _ = op.write_with(path, bs).if_not_exists(true).await?;

After this change, we will still allow users to use if_none_match("*"), but we will no longer document it, making it a service implementation detail.

@Xuanwo Xuanwo added good first issue Good for newcomers help wanted Extra attention is needed core labels Nov 5, 2024
@kemingy
Copy link
Contributor

kemingy commented Nov 6, 2024

Can I take this?

@Xuanwo
Copy link
Member Author

Xuanwo commented Nov 6, 2024

Can I take this?

Of course. Thank you in advance, have fun!

@swanandx
Copy link

swanandx commented Nov 10, 2024

why are we passing a boolean to if_not_exists ? what will be behavior when we pass false?

let _ = op.write_with(path, bs).if_not_exists(false).await?;

@Xuanwo
Copy link
Member Author

Xuanwo commented Nov 11, 2024

why are we passing a boolean to if_not_exists ?

Passing a boolean into if_not_exists make it easier to write code like:

async fn users_logic(require_not_exists: bool) {
  op.write_with(path, content).if_not_exists(require_not_exists).await;
}

Instead of:

async fn users_logic(require_not_exists: bool) {
  if require_not_exists {
    op.write_with(path, content).if_not_exists().await;
  } else {
    op.write_with(path, content).await;
  }
}

what will be behavior when we pass false?

This is a condition. While it's set to false, no such condition will be applied to this write operation.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
core good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants