Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
Overview
The PostgreSQL adapter works both with the C-based (www.postgresql.jp/interfaces/ruby/) and the Ruby-base (available both as gem and from rubyforge.org/frs/?group_id=234&release_id=1145) drivers.
Options:
-
:host
– Defaults to localhost
-
:port
– Defaults to 5432
-
:username
– Defaults to nothing
-
:password
– Defaults to nothing
-
:database
– The name of the database. No default, must be provided.
-
:schema_order
– An optional schema order string that is using in a SET search_path TO <schema_order> call on connection.
Instance Method Summary
collapse
#add_column, #add_limit!, #create_table, #drop_table, #initialize, #initialize_schema_information, #quote_string, #remove_column, #reset_runtime, #structure_dump, #transaction
Instance Method Details
#adapter_name ⇒ Object
108
109
110
|
# File 'lib/active_record/connection_adapters/postgresql_adapter.rb', line 108
def adapter_name()
'PostgreSQL'
end
|
#begin_db_transaction ⇒ Object
92
|
# File 'lib/active_record/connection_adapters/postgresql_adapter.rb', line 92
def begin_db_transaction() execute "BEGIN" end
|
#columns(table_name, name = nil) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/active_record/connection_adapters/postgresql_adapter.rb', line 67
def columns(table_name, name = nil)
table_structure(table_name).inject([]) do |columns, field|
columns << Column.new(field[0], field[2], field[1])
columns
end
end
|
#commit_db_transaction ⇒ Object
93
|
# File 'lib/active_record/connection_adapters/postgresql_adapter.rb', line 93
def commit_db_transaction() execute "COMMIT" end
|
#execute(sql, name = nil) ⇒ Object
80
81
82
|
# File 'lib/active_record/connection_adapters/postgresql_adapter.rb', line 80
def execute(sql, name = nil)
log(sql, name, @connection) { |connection| connection.query(sql) }
end
|
#insert(sql, name = nil, pk = nil, id_value = nil) ⇒ Object
74
75
76
77
78
|
# File 'lib/active_record/connection_adapters/postgresql_adapter.rb', line 74
def insert(sql, name = nil, pk = nil, id_value = nil)
execute(sql, name = nil)
table = sql.split(" ", 4)[2]
return id_value || last_insert_id(table, pk)
end
|
#quote(value, column = nil) ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/active_record/connection_adapters/postgresql_adapter.rb', line 96
def quote(value, column = nil)
if value.class == String && column && column.type == :binary
quote_bytea(value)
else
super
end
end
|
#quote_column_name(name) ⇒ Object
104
105
106
|
# File 'lib/active_record/connection_adapters/postgresql_adapter.rb', line 104
def quote_column_name(name)
return "\"#{name}\""
end
|
#rollback_db_transaction ⇒ Object
94
|
# File 'lib/active_record/connection_adapters/postgresql_adapter.rb', line 94
def rollback_db_transaction() execute "ROLLBACK" end
|
#select_all(sql, name = nil) ⇒ Object
58
59
60
|
# File 'lib/active_record/connection_adapters/postgresql_adapter.rb', line 58
def select_all(sql, name = nil)
select(sql, name)
end
|
#select_one(sql, name = nil) ⇒ Object
62
63
64
65
|
# File 'lib/active_record/connection_adapters/postgresql_adapter.rb', line 62
def select_one(sql, name = nil)
result = select(sql, name)
result.nil? ? nil : result.first
end
|
#update(sql, name = nil) ⇒ Object
Also known as:
delete
84
85
86
87
88
|
# File 'lib/active_record/connection_adapters/postgresql_adapter.rb', line 84
def update(sql, name = nil)
result = nil
log(sql, name, @connection) { |connection| result = connection.exec(sql) }
result.cmdtuples
end
|