Class: PostPolicy::DataSource::Sql

Inherits:
Base
  • Object
show all
Defined in:
lib/postpolicy/plugins/datasource/sql.rb

Instance Method Summary collapse

Constructor Details

#initialize(query) ⇒ Sql

Returns a new instance of Sql.



6
7
8
# File 'lib/postpolicy/plugins/datasource/sql.rb', line 6

def initialize( query )
  @query = query
end

Instance Method Details

#exists?(value) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/postpolicy/plugins/datasource/sql.rb', line 10

def exists?( value )
  result = false
  connection do |conn|
    command = conn.create_command( @query )
    reader = command.execute_reader
    while reader.next! 
      if reader.values[0] && reader.values[0] == value
        result = true
        break
      end
    end
  end
  result
end