Class: Chroma::Resources::Database
- Inherits:
-
Object
- Object
- Chroma::Resources::Database
- Includes:
- APIOperations::Request
- Defined in:
- lib/chroma/resources/database.rb
Overview
The Database class provides methods for interacting with the Chroma database server.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tenant ⇒ Object
readonly
Returns the value of attribute tenant.
Class Method Summary collapse
-
.auth_identity ⇒ Object
Get the current user’s identity, tenant, and databases of the Chroma database server.
-
.create(name) ⇒ Object
Create a new database on the tenant.
-
.delete(database_name) ⇒ Object
Deletes a database from the tenant.
-
.get(database_name) ⇒ Object
Retrieves a database from the tenant.
-
.healthcheck ⇒ Object
Check the hearlthcheck of the Chroma database server.
-
.heartbeat ⇒ Object
Check the heartbeat of the Chroma database server.
-
.list ⇒ Object
Lists all databases from the tenant.
-
.pre_flight_checks ⇒ Object
Check the pre-flight checks of the Chroma database server.
-
.reset ⇒ Object
Reset the Chroma database server.
-
.version ⇒ Object
Get the version of the Chroma database server.
Instance Method Summary collapse
-
#collections_count ⇒ Object
Count the total number of collections in the database object.
-
#initialize(id:, name:, tenant:) ⇒ Database
constructor
A new instance of Database.
Methods included from APIOperations::Request
Constructor Details
#initialize(id:, name:, tenant:) ⇒ Database
Returns a new instance of Database.
15 16 17 18 19 |
# File 'lib/chroma/resources/database.rb', line 15 def initialize(id:, name:, tenant:) @id = id @name = name @tenant = tenant end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/chroma/resources/database.rb', line 11 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/chroma/resources/database.rb', line 12 def name @name end |
#tenant ⇒ Object (readonly)
Returns the value of attribute tenant.
13 14 15 |
# File 'lib/chroma/resources/database.rb', line 13 def tenant @tenant end |
Class Method Details
.auth_identity ⇒ Object
Get the current user’s identity, tenant, and databases of the Chroma database server.
Returns the current user’s identity, tenant, and databases of the Chroma database server.
24 25 26 27 28 29 30 |
# File 'lib/chroma/resources/database.rb', line 24 def self.auth_identity result = execute_request(:get, "#{Chroma.api_url}/auth/identity") return result.success.body if result.success? raise_failure_error(result) end |
.create(name) ⇒ Object
Create a new database on the tenant.
name - The name of the database.
Examples
database = Chorma::Resources::Database.create("database-name")
Returns true if the database was successfully created, raises Chroma::APIError otherwise.
114 115 116 117 118 119 120 121 122 |
# File 'lib/chroma/resources/database.rb', line 114 def self.create(name) payload = {name: name} result = execute_request(:post, "#{Chroma.api_url}/tenants/#{Chroma.tenant}/databases", payload) return true if result.success? raise_failure_error(result) end |
.delete(database_name) ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/chroma/resources/database.rb', line 153 def self.delete(database_name) result = execute_request(:delete, "#{Chroma.api_url}/tenants/#{Chroma.tenant}/databases/#{database_name}") return true if result.success? raise_failure_error(result) end |
.get(database_name) ⇒ Object
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/chroma/resources/database.rb', line 133 def self.get(database_name) result = execute_request(:get, "#{Chroma.api_url}/tenants/#{Chroma.tenant}/databases/#{database_name}") if result.success? data = result.success.body new(id: data["id"], name: data["name"], tenant: data["tenant"]) else raise_failure_error(result) end end |
.healthcheck ⇒ Object
Check the hearlthcheck of the Chroma database server.
Return a Hash with a boolean.
57 58 59 60 61 62 63 |
# File 'lib/chroma/resources/database.rb', line 57 def self.healthcheck result = execute_request(:get, "#{Chroma.api_url}/healthcheck") return result.success.body if result.success? raise_failure_error(result) end |
.heartbeat ⇒ Object
Check the heartbeat of the Chroma database server.
Return a Hash with a timestamp.
68 69 70 71 72 73 74 |
# File 'lib/chroma/resources/database.rb', line 68 def self.heartbeat result = execute_request(:get, "#{Chroma.api_url}/heartbeat") return result.success.body if result.success? raise_failure_error(result) end |
.list ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/chroma/resources/database.rb', line 94 def self.list result = execute_request(:get, "#{Chroma.api_url}/tenants/#{Chroma.tenant}/databases") if result.success? data = result.success.body data.map { |item| new(id: item["id"], name: item["name"], tenant: item["tenant"]) } else raise_failure_error(result) end end |
.pre_flight_checks ⇒ Object
Check the pre-flight checks of the Chroma database server.
Return a Hash with a timestamp.
79 80 81 82 83 84 85 |
# File 'lib/chroma/resources/database.rb', line 79 def self.pre_flight_checks result = execute_request(:get, "#{Chroma.api_url}/pre-flight-checks") return result.success.body if result.success? raise_failure_error(result) end |
.reset ⇒ Object
Reset the Chroma database server. This can’t be undone.
Returns true on success or raise a Chroma::Error on failure.
46 47 48 49 50 51 52 |
# File 'lib/chroma/resources/database.rb', line 46 def self.reset result = execute_request(:post, "#{Chroma.api_url}/reset") return result.success.body if result.success? raise_failure_error(result) end |
.version ⇒ Object
Get the version of the Chroma database server.
Returns the version of the Chroma database server.
35 36 37 38 39 40 41 |
# File 'lib/chroma/resources/database.rb', line 35 def self.version result = execute_request(:get, "#{Chroma.api_url}/version") return result.success.body if result.success? raise_failure_error(result) end |
Instance Method Details
#collections_count ⇒ Object
169 170 171 172 173 174 175 |
# File 'lib/chroma/resources/database.rb', line 169 def collections_count result = self.class.execute_request(:get, "#{Chroma.api_url}/tenants/#{Chroma.tenant}/databases/#{name}/collections_count") return result.success.body if result.success? self.class.raise_failure_error(result) end |