Module: Arfi::PostgreSQL::DatabaseStatementsPatch
- Defined in:
- lib/arfi/extensions/active_record/connection_adapters/postgresql/database_statements.rb
Overview
ActiveRecord adapter patch for PostgreSQL.
When a query fails with ‘PG::UndefinedFunction`, ARFI checks whether the missing function is managed by ARFI (file exists under db/functions). If yes, ARFI loads function SQL files via SqlFunctionLoader.load! and retries the failed query once.
Constant Summary collapse
- ARFI_UNDEFINED_FUNCTION =
/ function\s+([a-zA-Z0-9_."]+)\s*\(.*?\)\s+does\s+not\s+exist /ix.freeze
- THREAD_GUARD_KEY =
:arfi_reloading_functions
Instance Method Summary collapse
-
#exec_query(*args, **kwargs) ⇒ Object
Execute a SQL query, reloading missing ARFI-managed functions and retrying on PG::UndefinedFunction.
-
#execute(*args, **kwargs) ⇒ Object
Execute raw SQL, reloading missing ARFI-managed functions and retrying on PG::UndefinedFunction.
-
#internal_exec_query(*args, **kwargs) ⇒ Object
Execute an internal query, reloading missing ARFI-managed functions and retrying on PG::UndefinedFunction.
-
#raw_execute(*args, **kwargs) ⇒ Object
Execute a raw SQL statement, reloading missing ARFI-managed functions and retrying on PG::UndefinedFunction.
Instance Method Details
#exec_query(*args, **kwargs) ⇒ Object
Execute a SQL query, reloading missing ARFI-managed functions and retrying on PG::UndefinedFunction.
34 35 36 37 38 39 |
# File 'lib/arfi/extensions/active_record/connection_adapters/postgresql/database_statements.rb', line 34 def exec_query(*args, **kwargs) super rescue StandardError => e raise unless arfi_try_reload_and_retry?(e) retry end |
#execute(*args, **kwargs) ⇒ Object
Execute raw SQL, reloading missing ARFI-managed functions and retrying on PG::UndefinedFunction.
48 49 50 51 52 53 |
# File 'lib/arfi/extensions/active_record/connection_adapters/postgresql/database_statements.rb', line 48 def execute(*args, **kwargs) super rescue StandardError => e raise unless arfi_try_reload_and_retry?(e) retry end |
#internal_exec_query(*args, **kwargs) ⇒ Object
Execute an internal query, reloading missing ARFI-managed functions and retrying on PG::UndefinedFunction.
76 77 78 79 80 81 |
# File 'lib/arfi/extensions/active_record/connection_adapters/postgresql/database_statements.rb', line 76 def internal_exec_query(*args, **kwargs) super rescue StandardError => e raise unless arfi_try_reload_and_retry?(e) retry end |
#raw_execute(*args, **kwargs) ⇒ Object
Execute a raw SQL statement, reloading missing ARFI-managed functions and retrying on PG::UndefinedFunction.
62 63 64 65 66 67 |
# File 'lib/arfi/extensions/active_record/connection_adapters/postgresql/database_statements.rb', line 62 def raw_execute(*args, **kwargs) super rescue StandardError => e raise unless arfi_try_reload_and_retry?(e) retry end |