Class: DB::Context::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/db/context/query.rb

Direct Known Subclasses

Transaction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pool, **options) ⇒ Query

Returns a new instance of Query.



27
28
29
30
# File 'lib/db/context/query.rb', line 27

def initialize(pool, **options)
	@pool = pool
	@connection = pool.acquire
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



32
33
34
# File 'lib/db/context/query.rb', line 32

def connection
  @connection
end

Instance Method Details

#call(statement, **options) ⇒ Object



52
53
54
55
56
# File 'lib/db/context/query.rb', line 52

def call(statement, **options)
	@connection.send_query(statement, **options)
	
	return @connection.next_result
end

#closeObject



34
35
36
37
38
39
40
41
42
# File 'lib/db/context/query.rb', line 34

def close
	if @connection
		self.flush
		
		@pool.release(@connection)
		
		@connection = nil
	end
end

#flushObject



66
67
68
69
# File 'lib/db/context/query.rb', line 66

def flush
	until @connection.next_result.nil?
	end
end

#next_resultObject



48
49
50
# File 'lib/db/context/query.rb', line 48

def next_result
	@connection.next_result
end

#resultsObject



58
59
60
61
62
63
64
# File 'lib/db/context/query.rb', line 58

def results
	while result = self.next_result
		yield result
	end
	
	return nil
end

#send_query(statement, **options) ⇒ Object



44
45
46
# File 'lib/db/context/query.rb', line 44

def send_query(statement, **options)
	@connection.send_query(statement, **options)
end