Class: MemoriClient::Proxy::Client
- Inherits:
-
Object
- Object
- MemoriClient::Proxy::Client
- Defined in:
- lib/memori_client/proxy/client.rb
Overview
Initialize a DB Proxy Client, which connects to the AIsuru proxy client to interact with backend and engine databases, in read-only mode. Usage:
client = AisuruProxyClient.new(base_url: “https://…”, api_key: “XXX”)
Status: client.status
Tables list and table information client.tables(id: ‘backend’, schema: ‘memoriai’) client.table_schema(id: ‘backend’, schema: ‘memoriai’, table: ‘ActionLog’)
SQL Query sql = <<~SQL SELECT * FROM memoriai.“ActionLog” LIMIT 10 OFFSET 0 SQL client.query(id: ‘backend’, sql: sql)
Constant Summary collapse
- CONNECTIONS =
['backend', 'engine'].freeze
Instance Method Summary collapse
-
#initialize(base_url:, api_key:) ⇒ Client
constructor
A new instance of Client.
-
#query(id:, sql:) ⇒ Object
Execute a SQL query.
-
#status ⇒ Object
Get the status of the API.
-
#table_schema(id:, schema: nil, table:) ⇒ Object
Get the schema of a specific table.
-
#tables(id:, schema: nil) ⇒ Object
Get a list of tables for a specific connection.
Constructor Details
#initialize(base_url:, api_key:) ⇒ Client
Returns a new instance of Client.
30 31 32 33 |
# File 'lib/memori_client/proxy/client.rb', line 30 def initialize(base_url:, api_key:) @base_url = base_url @api_key = api_key end |
Instance Method Details
#query(id:, sql:) ⇒ Object
Execute a SQL query
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/memori_client/proxy/client.rb', line 77 def query(id:, sql:) unless CONNECTIONS.include?(id) raise ArgumentError, "Invalid connection id: #{id}" end path = "api/v1/#{id}/query" uri = URI.join(@base_url, path) response = post_raw_content(uri, sql) [response.code, response.body] end |
#status ⇒ Object
Get the status of the API
36 37 38 39 40 41 |
# File 'lib/memori_client/proxy/client.rb', line 36 def status path = "api/v1/status" uri = URI.join(@base_url, path) response = get(uri) [response.code, response.body] end |
#table_schema(id:, schema: nil, table:) ⇒ Object
Get the schema of a specific table
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/memori_client/proxy/client.rb', line 62 def table_schema(id:, schema: nil, table:) unless CONNECTIONS.include?(id) raise ArgumentError, "Invalid connection id: #{id}" end path = "api/v1/#{id}/tables/#{table}/schema" path += "?schema=#{schema}" if schema uri = URI.join(@base_url, path) response = get(uri) [response.code, response.body] end |
#tables(id:, schema: nil) ⇒ Object
Get a list of tables for a specific connection
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/memori_client/proxy/client.rb', line 46 def tables(id:, schema: nil) unless CONNECTIONS.include?(id) raise ArgumentError, "Invalid connection id: #{id}" end path = "api/v1/#{id}/tables" path += "?schema=#{schema}" if schema uri = URI.join(@base_url, path) response = get(uri) [response.code, response.body] end |