Class: Lexicon::Common::Psql
- Inherits:
-
Object
- Object
- Lexicon::Common::Psql
- Defined in:
- lib/lexicon/common/psql.rb
Instance Method Summary collapse
- #execute(command, search_path:) ⇒ Object
- #execute_raw(command) ⇒ Object
-
#initialize(url:, executor:) ⇒ Psql
constructor
A new instance of Psql.
- #load_sql(file, search_path:) ⇒ Object
Constructor Details
#initialize(url:, executor:) ⇒ Psql
Returns a new instance of Psql.
8 9 10 11 |
# File 'lib/lexicon/common/psql.rb', line 8 def initialize(url:, executor:) @url = url @executor = executor end |
Instance Method Details
#execute(command, search_path:) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/lexicon/common/psql.rb', line 15 def execute(command, search_path:) command = " SET search_path TO \#{Array(search_path).join(', ')};\n \#{command}\n SQL\n\n execute_raw(command)\nend\n" |
#execute_raw(command) ⇒ Object
25 26 27 28 29 |
# File 'lib/lexicon/common/psql.rb', line 25 def execute_raw(command) @executor.execute " psql '\#{url}' --quiet -c \#{Shellwords.escape(command)}\n BASH\nend\n" |
#load_sql(file, search_path:) ⇒ Object
33 34 35 36 37 |
# File 'lib/lexicon/common/psql.rb', line 33 def load_sql(file, search_path:) @executor.execute " echo 'SET SEARCH_PATH TO \#{Array(search_path).join(', ')};' | cat - \#{file} | psql '\#{url}'\n BASH\nend\n" |