Class: DataMapper::Adapters::PostgresAdapter
- Object
- DataMapper::Adapters::AbstractAdapter
- DataMapper::Adapters::DataObjectsAdapter
- DataMapper::Adapters::PostgresAdapter
Included Modules
Constructor Summary
This class inherits a constructor from DataMapper::Adapters::DataObjectsAdapter.
Public Visibility
Public Class Method Summary
| type_map |
TypeMap for PostgreSQL databases. Returns: |
|---|
Public Instance Method Summary
| #create_model_storage(repository, model) |
TODO: move to dm-more/dm-migrations. |
|---|---|
| #destroy_model_storage(repository, model) |
TODO: move to dm-more/dm-migrations. |
| #field_exists?(storage_name, column_name) |
TODO: move to dm-more/dm-migrations (if possible). |
| #storage_exists?(storage_name) |
TODO: move to dm-more/dm-migrations (if possible). |
| #upgrade_model_storage(repository, model) |
TODO: move to dm-more/dm-migrations. |
Public Instance Methods Inherited from DataMapper::Adapters::DataObjectsAdapter
avg, count, create, delete, execute, max, min, query, read_set, sum, transaction_primitive, update
Public Instance Methods Inherited from DataMapper::Adapters::AbstractAdapter
alter_model_storage, alter_property_storage, create_property_storage, current_transaction, delete_set, destroy_property_storage, pop_transaction, push_transaction, read, read_one, within_transaction?
Public Instance Methods Inherited from Object
Public Class Method Details
type_map
TypeMap for PostgreSQL databases.
12 13 14 15 16 17 18 19 20 21
# File 'dm-core/lib/dm-core/adapters/postgres_adapter.rb', line 12 def self.type_map @type_map ||= TypeMap.new(super) do |tm| tm.map(DateTime).to('TIMESTAMP') tm.map(Integer).to('INT4') tm.map(Float).to('FLOAT8') end end
Public Instance Method Details
create_model_storage
TODO: move to dm-more/dm-migrations
55 56 57 58
# File 'dm-core/lib/dm-core/adapters/postgres_adapter.rb', line 55 def create_model_storage(repository, model) add_sequences(model) without_notices { super } end
destroy_model_storage
TODO: move to dm-more/dm-migrations
61 62 63 64 65 66 67
# File 'dm-core/lib/dm-core/adapters/postgres_adapter.rb', line 61 def destroy_model_storage(repository, model) success = without_notices { super } model.properties(name).each do |property| drop_sequence(model, property) if property.serial? end success end
field_exists?
TODO: move to dm-more/dm-migrations (if possible)
36 37 38 39 40
# File 'dm-core/lib/dm-core/adapters/postgres_adapter.rb', line 36 def field_exists?(storage_name, column_name) statement = "SELECT COUNT(*)\nFROM \"pg_class\"\nJOIN \"pg_attribute\" ON \"pg_class\".\"oid\" = \"pg_attribute\".\"attrelid\"\nWHERE \"pg_attribute\".\"attname\" = ? AND \"pg_class\".\"relname\" = ? AND \"pg_attribute\".\"attnum\" >= 0\n".compress_lines query(statement, column_name, storage_name).first > 0 end
storage_exists?
TODO: move to dm-more/dm-migrations (if possible)
21 22 23 24 25
# File 'dm-core/lib/dm-core/adapters/postgres_adapter.rb', line 21 def storage_exists?(storage_name) statement = "SELECT COUNT(*)\nFROM \"information_schema\".\"columns\"\nWHERE \"table_name\" = ? AND \"table_schema\" = current_schema()\n".compress_lines query(statement, storage_name).first > 0 end
upgrade_model_storage
TODO: move to dm-more/dm-migrations
49 50 51 52
# File 'dm-core/lib/dm-core/adapters/postgres_adapter.rb', line 49 def upgrade_model_storage(repository, model) add_sequences(model) super end
Protected Visibility
Protected Instance Method Summary
| #create_sequence(model, property) |
TODO: move to dm-more/dm-migrations. |
|---|---|
| #drop_sequence(model, property) |
TODO: move to dm-more/dm-migrations. |
Protected Instance Methods Inherited from DataMapper::Adapters::DataObjectsAdapter
Protected Instance Method Details
create_sequence
TODO: move to dm-more/dm-migrations
72 73 74 75
# File 'dm-core/lib/dm-core/adapters/postgres_adapter.rb', line 72 def create_sequence(model, property) return if sequence_exists?(model, property) execute(create_sequence_statement(model, property)) end
drop_sequence
TODO: move to dm-more/dm-migrations
78 79 80
# File 'dm-core/lib/dm-core/adapters/postgres_adapter.rb', line 78 def drop_sequence(model, property) without_notices { execute(drop_sequence_statement(model, property)) } end