Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Includes:
- Jdbc::ConnectionPoolCallbacks, ActiveRecord::ConnectionAdapters::PostgreSQL::Quoting, ActiveRecord::ConnectionAdapters::PostgreSQL::ReferentialIntegrity, ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaStatements, ArJdbc::Abstract::ConnectionManagement, ArJdbc::Abstract::Core, ArJdbc::Abstract::DatabaseStatements, ArJdbc::Abstract::StatementCache, ArJdbc::Abstract::TransactionSupport, ArJdbc::PostgreSQL, ArJdbc::Util::QuotedCache
- Defined in:
- lib/arjdbc/postgresql/adapter.rb
Constant Summary collapse
- OID =
AR expects OID to be available on the adapter
ActiveRecord::ConnectionAdapters::PostgreSQL::OID
- ColumnMethods =
ActiveRecord::ConnectionAdapters::PostgreSQL::ColumnMethods
- TableDefinition =
ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition
- Table =
ActiveRecord::ConnectionAdapters::PostgreSQL::Table
Constants included from ArJdbc::PostgreSQL
ArJdbc::PostgreSQL::ADAPTER_NAME, ArJdbc::PostgreSQL::NATIVE_DATABASE_TYPES
Constants included from ArJdbc::Abstract::DatabaseStatements
ArJdbc::Abstract::DatabaseStatements::NO_BINDS
Instance Attribute Summary
Attributes included from ArJdbc::Abstract::Core
Class Method Summary collapse
Instance Method Summary collapse
-
#create_unlogged_tables ⇒ Object
:singleton-method: PostgreSQL allows the creation of "unlogged" tables, which do not record data in the PostgreSQL Write-Ahead Log.
-
#datetime_type ⇒ Object
:singleton-method: PostgreSQL supports multiple types for DateTimes.
-
#initialize(connection, logger = nil, connection_parameters = nil, config = {}) ⇒ PostgreSQLAdapter
constructor
A new instance of PostgreSQLAdapter.
- #jdbc_connection_class(spec) ⇒ Object
Methods included from ArJdbc::Util::QuotedCache
#quote_column_name, #quote_table_name
Methods included from ArJdbc::PostgreSQL
#adapter_name, #add_order_by_for_association_limiting!, #all_schemas, #build_insert_sql, #build_truncate_statements, #check_version, #clear_cache!, #client_min_messages, #client_min_messages=, #configure_connection, #create_enum, #default_index_type?, #default_sequence_name, #disable_extension, #enable_extension, #enum_types, #escape_bytea, #exec_insert, #execute_batch, #explain, #extension_available?, #extension_enabled?, #extensions, #get_advisory_lock, #get_database_version, #index_algorithms, #jdbc_column_class, jdbc_connection_class, #last_insert_id_result, #max_identifier_length, #native_database_types, #quote_table_name, #release_advisory_lock, #remove_column, #reset!, #session_auth=, #set_client_encoding, #set_standard_conforming_strings, #supports_advisory_locks?, #supports_bulk_alter?, #supports_check_constraints?, #supports_comments?, #supports_common_table_expressions?, #supports_datetime_with_precision?, #supports_ddl_transactions?, #supports_explain?, #supports_expression_index?, #supports_extensions?, #supports_foreign_keys?, #supports_foreign_tables?, #supports_index_sort_order?, #supports_insert_on_conflict?, #supports_insert_returning?, #supports_json?, #supports_lazy_transactions?, #supports_materialized_views?, #supports_optimizer_hints?, #supports_partial_index?, #supports_partitioned_indexes?, #supports_pgcrypto_uuid?, #supports_ranges?, #supports_savepoints?, #supports_transaction_isolation?, #supports_validate_constraints?, #supports_views?, #use_insert_returning?, #valid_type?, #write_query?
Methods included from ArJdbc::Abstract::TransactionSupport
#begin_db_transaction, #begin_isolated_db_transaction, #commit_db_transaction, #create_savepoint, #exec_rollback_db_transaction, #exec_rollback_to_savepoint, #release_savepoint, #supports_savepoints?, #supports_transaction_isolation?
Methods included from ArJdbc::Abstract::StatementCache
#clear_cache!, #delete_cached_statement, #fetch_cached_statement
Methods included from ArJdbc::Abstract::DatabaseStatements
#exec_insert, #exec_query, #exec_update, #execute, #select_all
Methods included from ArJdbc::Abstract::ConnectionManagement
#active?, #disconnect!, #really_valid?, #reconnect!
Methods included from ArJdbc::Abstract::Core
Methods included from Jdbc::ConnectionPoolCallbacks
Constructor Details
#initialize(connection, logger = nil, connection_parameters = nil, config = {}) ⇒ PostgreSQLAdapter
Returns a new instance of PostgreSQLAdapter.
764 765 766 767 768 769 770 771 772 773 774 775 776 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 764 def initialize(connection, logger = nil, connection_parameters = nil, config = {}) # @local_tz is initialized as nil to avoid warnings when connect tries to use it @local_tz = nil @max_identifier_length = nil super(connection, logger, config) # configure_connection happens in super @type_map = Type::HashLookupTypeMap.new initialize_type_map @use_insert_returning = @config.key?(:insert_returning) ? self.class.type_cast_config_to_boolean(@config[:insert_returning]) : true end |
Class Method Details
.database_exists?(config) ⇒ Boolean
778 779 780 781 782 783 784 785 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 778 def self.database_exists?(config) conn = ActiveRecord::Base.postgresql_connection(config) conn && conn.really_valid? rescue ActiveRecord::NoDatabaseError false ensure conn.disconnect! if conn end |
Instance Method Details
#create_unlogged_tables ⇒ Object
:singleton-method: PostgreSQL allows the creation of "unlogged" tables, which do not record data in the PostgreSQL Write-Ahead Log. This can make the tables faster, but significantly increases the risk of data loss if the database crashes. As a result, this should not be used in production environments. If you would like all created tables to be unlogged in the test environment you can add the following line to your test.rb file:
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = true
719 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 719 class_attribute :create_unlogged_tables, default: false |
#datetime_type ⇒ Object
:singleton-method: PostgreSQL supports multiple types for DateTimes. By default, if you use +datetime+ in migrations, Rails will translate this to a PostgreSQL "timestamp without time zone". Change this in an initializer to use another NATIVE_DATABASE_TYPES. For example, to store DateTimes as "timestamp with time zone":
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type = :timestamptz
Or if you are adding a custom type:
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:my_custom_type] = { name: "my_custom_type_name" } ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type = :my_custom_type
If you're using +:ruby+ as your +config.active_record.schema_format+ and you change this setting, you should immediately run bin/rails db:migrate to update the types in your schema.rb.
737 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 737 class_attribute :datetime_type, default: :timestamp |
#jdbc_connection_class(spec) ⇒ Object
796 797 798 |
# File 'lib/arjdbc/postgresql/adapter.rb', line 796 def jdbc_connection_class(spec) ::ArJdbc::PostgreSQL.jdbc_connection_class end |