Class: MiniSql::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_sql/connection.rb

Direct Known Subclasses

Postgres::Connection, Sqlite::Connection

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get(raw_connection, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/mini_sql/connection.rb', line 6

def self.get(raw_connection, options = {})
  if (defined? ::PG::Connection) && (PG::Connection === raw_connection) 
    Postgres::Connection.new(raw_connection, options)
  elsif (defined? ::ArJdbc)
    Postgres::Connection.new(raw_connection, options)
  elsif (defined? ::SQLite3::Database) && (SQLite3::Database === raw_connection)
    Sqlite::Connection.new(raw_connection, options)
  else
    raise ArgumentError, 'unknown connection type!'
  end
end

Instance Method Details

#build(sql) ⇒ Object



40
41
42
# File 'lib/mini_sql/connection.rb', line 40

def build(sql)
  Builder.new(self, sql)
end

#escape_string(str) ⇒ Object

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/mini_sql/connection.rb', line 44

def escape_string(str)
  raise NotImplementedError, "must be implemented by child connection"
end

#exec(sql, *params) ⇒ Object

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/mini_sql/connection.rb', line 32

def exec(sql, *params)
  raise NotImplementedError, "must be implemented by child connection"
end

#query(sql, *params) ⇒ Object

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/mini_sql/connection.rb', line 28

def query(sql, *params)
  raise NotImplementedError, "must be implemented by child connection"
end

#query_hash(sql, *params) ⇒ Object

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/mini_sql/connection.rb', line 36

def query_hash(sql, *params)
  raise NotImplementedError, "must be implemented by child connection"
end

#query_single(sql, *params) ⇒ Object

Returns a flat array containing all results. Note, if selecting multiple columns array will be flattened

Parameters:

  • sql (String)

    the query to run

  • params (Array or Hash)

    , params to apply to query

Returns:

  • (Object)

    a flat array containing all results

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/mini_sql/connection.rb', line 24

def query_single(sql, *params)
  raise NotImplementedError, "must be implemented by child connection"
end