Class: DataMapper::Adapters::PostgresAdapter

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 Class Method Details

type_map

public type_map

TypeMap for PostgreSQL databases.

Meta Tags

Returns:

<DataMapper::TypeMap> default TypeMap for PostgreSQL databases.

[View source]


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

public create_model_storage(repository, model)

TODO: move to dm-more/dm-migrations

[View source]


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

public destroy_model_storage(repository, model)

TODO: move to dm-more/dm-migrations

[View source]


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?

public field_exists?(storage_name, column_name)

TODO: move to dm-more/dm-migrations (if possible)

[View source]


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?

public storage_exists?(storage_name)

TODO: move to dm-more/dm-migrations (if possible)

[View source]


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

public upgrade_model_storage(repository, model)

TODO: move to dm-more/dm-migrations

[View source]


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 Method Details

create_sequence

protected create_sequence(model, property)

TODO: move to dm-more/dm-migrations

[View source]


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

protected drop_sequence(model, property)

TODO: move to dm-more/dm-migrations

[View source]


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