Class: Chdb::Session
- Inherits:
-
Object
- Object
- Chdb::Session
- Defined in:
- lib/chdb/session.rb
Overview
Manages ClickHouse database sessions, handling temporary and permanent paths for query execution and resource cleanup
Instance Attribute Summary collapse
-
#is_temp ⇒ Object
readonly
Returns the value of attribute is_temp.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #cleanup ⇒ Object
- #close ⇒ Object
-
#initialize(path = nil) ⇒ Session
constructor
A new instance of Session.
- #query(query_str, output_format = "CSV") ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ Session
Returns a new instance of Session.
12 13 14 15 16 17 18 19 20 |
# File 'lib/chdb/session.rb', line 12 def initialize(path = nil) if path.nil? || path.empty? @path = Dir.mktmpdir("chdb_") @is_temp = true else @path = path @is_temp = false end end |
Instance Attribute Details
#is_temp ⇒ Object (readonly)
Returns the value of attribute is_temp.
10 11 12 |
# File 'lib/chdb/session.rb', line 10 def is_temp @is_temp end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/chdb/session.rb', line 10 def path @path end |
Instance Method Details
#cleanup ⇒ Object
31 32 33 |
# File 'lib/chdb/session.rb', line 31 def cleanup FileUtils.remove_entry(@path) if Dir.exist?(@path) end |
#close ⇒ Object
27 28 29 |
# File 'lib/chdb/session.rb', line 27 def close cleanup if @is_temp && File.basename(@path).start_with?("chdb_") end |
#query(query_str, output_format = "CSV") ⇒ Object
22 23 24 25 |
# File 'lib/chdb/session.rb', line 22 def query(query_str, output_format = "CSV") output_format ||= "CSV" # Default value query_to_buffer(query_str, output_format, @path, "") end |