Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Make update method send PATCH, and add separate replace method which can send PUT #39

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/weaviate/objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ def update(
)
validate_consistency_level!(consistency_level) unless consistency_level.nil?

response = client.connection.patch("#{PATH}/#{class_name}/#{id}") do |req|
req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?

req.body = {}
req.body["id"] = id
req.body["class"] = class_name
req.body["properties"] = properties
req.body["vector"] = vector unless vector.nil?
end

response.body
end

# Replace an individual data object based on its uuid.
def replace(
class_name:,
id:,
properties:,
vector: nil,
consistency_level: nil
)
validate_consistency_level!(consistency_level) unless consistency_level.nil?

response = client.connection.put("#{PATH}/#{class_name}/#{id}") do |req|
req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?

Expand Down
33 changes: 33 additions & 0 deletions lib/weaviate/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,39 @@ def update(
properties: nil,
inverted_index_config: nil,
replication_config: nil
)
response = client.connection.patch("#{PATH}/#{class_name}") do |req|
req.body = {}
req.body["class"] = class_name unless class_name.nil?
req.body["description"] = description unless description.nil?
req.body["vectorIndexType"] = vector_index_type unless vector_index_type.nil?
req.body["vectorIndexConfig"] = vector_index_config unless vector_index_config.nil?
req.body["vectorizer"] = vectorizer unless vectorizer.nil?
req.body["moduleConfig"] = module_config unless module_config.nil?
req.body["properties"] = properties unless properties.nil?
req.body["invertedIndexConfig"] = inverted_index_config unless inverted_index_config.nil?
req.body["replicationConfig"] = replication_config unless replication_config.nil?
end

if response.success?
end
response.body
end

# Update settings of an existing schema class.
# TODO: Fix it.
# This endpoint keeps returning the following error:
# => {"error"=>[{"message"=>"properties cannot be updated through updating the class. Use the add property feature (e.g. \"POST /v1/schema/{className}/properties\") to add additional properties"}]}
def replace(
class_name:,
description: nil,
vector_index_type: nil,
vector_index_config: nil,
vectorizer: nil,
module_config: nil,
properties: nil,
inverted_index_config: nil,
replication_config: nil
)
response = client.connection.put("#{PATH}/#{class_name}") do |req|
req.body = {}
Expand Down
Loading