Skip to content

Commit

Permalink
feat: allow hard deletes again (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
elefeint authored Feb 21, 2024
1 parent e82e5e0 commit d68cadf
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 120 deletions.
5 changes: 1 addition & 4 deletions src/motherduck_destination_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,7 @@ DestinationSdkImpl::Truncate(::grpc::ServerContext *context,
if (request->synced_column().empty()) {
throw std::invalid_argument("Synced column is required");
}
if (request->soft().deleted_column().empty()) {
// right now, only soft deletes are supported
throw std::invalid_argument("Deleted column is required");
}

std::unique_ptr<duckdb::Connection> con =
get_connection(request->configuration(), db_name);

Expand Down
12 changes: 9 additions & 3 deletions src/sql_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,15 @@ void truncate_table(duckdb::Connection &con, const table_def &table,
const std::string absolute_table_name = table.to_escaped_string();
std::ostringstream sql;

sql << "UPDATE " << absolute_table_name << " SET "
<< KeywordHelper::WriteQuoted(deleted_column, '"') << " = true WHERE "
<< KeywordHelper::WriteQuoted(synced_column, '"')
if (deleted_column.empty()) {
// hard delete
sql << "DELETE FROM " << absolute_table_name;
} else {
// soft delete
sql << "UPDATE " << absolute_table_name << " SET "
<< KeywordHelper::WriteQuoted(deleted_column, '"') << " = true";
}
sql << " WHERE " << KeywordHelper::WriteQuoted(synced_column, '"')
<< " < make_timestamp(?)";
auto query = sql.str();
mdlog::info("truncate_table: " + query);
Expand Down
Loading

0 comments on commit d68cadf

Please sign in to comment.