Class: Chdb::Session

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_tempObject (readonly)

Returns the value of attribute is_temp.



10
11
12
# File 'lib/chdb/session.rb', line 10

def is_temp
  @is_temp
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/chdb/session.rb', line 10

def path
  @path
end

Instance Method Details

#cleanupObject



31
32
33
# File 'lib/chdb/session.rb', line 31

def cleanup
  FileUtils.remove_entry(@path) if Dir.exist?(@path)
end

#closeObject



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