Class: Baza::Driver::Pg
Defined Under Namespace
Classes: Column, Columns, Commands, CreateIndexSqlCreator, Database, Databases, ForeignKey, ForeignKeys, Index, Indexes, Result, Table, Tables
Constant Summary
BaseSqlDriver::SELECT_ARGS_ALLOWED_KEYS, BaseSqlDriver::SEPARATOR_COLUMN, BaseSqlDriver::SEPARATOR_DATABASE, BaseSqlDriver::SEPARATOR_INDEX, BaseSqlDriver::SEPARATOR_TABLE, BaseSqlDriver::SEPARATOR_VALUE
Instance Attribute Summary collapse
#cols, #db, #indexes, #sep_col, #sep_database, #sep_index, #sep_table, #sep_val, #tables
Class Method Summary
collapse
Instance Method Summary
collapse
#count, #delete, escape, #escape_column, escape_column, escape_database, #escape_database, #escape_index, escape_index, escape_table, #escape_table, #foreign_key_support?, #insert, #insert_multi, #quote_column, quote_column, quote_database, #quote_database, #quote_index, quote_index, #quote_table, quote_table, quote_value, #quote_value, #select, #single, #sql_make_where, #supports_multiple_databases?, #transaction
Constructor Details
#initialize(db) ⇒ Pg
Returns a new instance of Pg.
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/baza/driver/pg.rb', line 39
def initialize(db)
super
@sep_database = '"'
@sep_table = '"'
@sep_col = '"'
@sep_index = '"'
if db.opts[:conn]
@conn = db.opts.fetch(:conn)
elsif db.opts[:db]
reconnect
end
end
|
Instance Attribute Details
#conn ⇒ Object
Returns the value of attribute conn.
4
5
6
|
# File 'lib/baza/driver/pg.rb', line 4
def conn
@conn
end
|
Class Method Details
.args ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/baza/driver/pg.rb', line 20
def self.args
[{
label: "Host",
name: "host"
}, {
label: "Port",
name: "port"
}, {
label: "Username",
name: "user"
}, {
label: "Password",
name: "pass"
}, {
label: "Database",
name: "db"
}]
end
|
.from_object(args) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/baza/driver/pg.rb', line 6
def self.from_object(args)
if args[:object].class.name == "PG::Connection"
return {
type: :success,
args: {
type: :pg,
conn: args[:object]
}
}
end
nil
end
|
Instance Method Details
#close ⇒ Object
91
92
93
|
# File 'lib/baza/driver/pg.rb', line 91
def close
@conn.close
end
|
#connected? ⇒ Boolean
54
55
56
|
# File 'lib/baza/driver/pg.rb', line 54
def connected?
@conn ? true : false
end
|
#escape(string) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/baza/driver/pg.rb', line 58
def escape(string)
if @conn
@conn.escape_string(string.to_s)
else
PG::Connection.escape_string(string.to_s)
end
end
|
#query(sql) ⇒ Object
80
81
82
|
# File 'lib/baza/driver/pg.rb', line 80
def query(sql)
Baza::Driver::Pg::Result.new(self, @conn.exec(sql))
end
|
#query_ubuf(sql) ⇒ Object
84
85
86
87
88
89
|
# File 'lib/baza/driver/pg.rb', line 84
def query_ubuf(sql)
@conn.send_query(sql)
@conn.set_single_row_mode
result = @conn.get_result
Baza::Driver::Pg::Result.new(self, result, unbuffered: true)
end
|
#reconnect ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/baza/driver/pg.rb', line 66
def reconnect
require "pg" unless ::Object.const_defined?(:PG)
close if @conn && !@conn.finished?
args = {dbname: db.opts.fetch(:db)}
args[:port] = db.opts.fetch(:port) if db.opts[:port]
args[:host] = db.opts.fetch(:host) if db.opts[:host]
args[:user] = db.opts.fetch(:user) if db.opts[:user]
args[:password] = db.opts.fetch(:pass) if db.opts[:pass]
@conn = PG::Connection.new(args)
end
|