Class: Libsql::Client
- Inherits:
-
Object
- Object
- Libsql::Client
- Defined in:
- lib/libsql.rb
Constant Summary collapse
- STMT_ENDPOINT =
"/v2/pipeline".freeze
Instance Method Summary collapse
- #execute(query_string, args = nil) ⇒ Object
-
#initialize(params = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(params = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 |
# File 'lib/libsql.rb', line 8 def initialize(params = {}) @url = params[:url] @host = params[:host] @port = params[:port] _build_uri end |
Instance Method Details
#execute(query_string, args = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/libsql.rb', line 16 def execute(query_string, args = nil) argument_builder = case args in Array PositionalArgBuilder.new(*args) in Hash NamedArgBuilder.new(**args) in NilClass EmptyBuilder.new else raise NotImplementedError end if argument_builder.empty? body = { requests: [ { type: :execute, stmt: { sql: query_string } }, { type: :close } ] } else body = { requests: [ { type: :execute, stmt: { sql: query_string, argument_builder.key => argument_builder.build } }, { type: :close } ] } end response = http_client.post(STMT_ENDPOINT, body) raise StandardError, response.results.first["error"]["message"] if response.failure? QueryResult.new(response) end |