Class: Baza::Driver::Tiny
Defined Under Namespace
Classes: Commands, Result
Constant Summary
collapse
- SEPARATOR_DATABASE =
"[".freeze
- SEPARATOR_TABLE =
"[".freeze
- SEPARATOR_COLUMN =
"[".freeze
- SEPARATOR_INDEX =
"[".freeze
- SEPARATOR_VALUE =
"'".freeze
BaseSqlDriver::SELECT_ARGS_ALLOWED_KEYS
Instance Attribute Summary
#cols, #conn, #db, #indexes, #sep_col, #sep_database, #sep_index, #sep_table, #sep_val, #tables
Class Method Summary
collapse
Instance Method Summary
collapse
#count, #delete, escape, #foreign_key_support?, from_object, #insert_multi, #quote_value, quote_value, #select, #single, #sql_make_where, #supports_multiple_databases?, #transaction
Constructor Details
#initialize(db) ⇒ Tiny
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/baza/driver/tiny.rb', line 8
def initialize(db)
@sep_database = SEPARATOR_DATABASE
@sep_table = SEPARATOR_TABLE
@sep_col = SEPARATOR_COLUMN
@sep_val = SEPARATOR_VALUE
@sep_index = SEPARATOR_INDEX
super
@client = TinyTds::Client.new(username: db.opts.fetch(:user), password: db.opts.fetch(:pass), host: db.opts.fetch(:host))
end
|
Class Method Details
.escape_column(name) ⇒ Object
38
39
40
|
# File 'lib/baza/driver/tiny.rb', line 38
def self.escape_column(name)
escape_identifier(name)
end
|
.escape_database(name) ⇒ Object
34
35
36
|
# File 'lib/baza/driver/tiny.rb', line 34
def self.escape_database(name)
escape_identifier(name)
end
|
.escape_identifier(string) ⇒ Object
28
29
30
31
32
|
# File 'lib/baza/driver/tiny.rb', line 28
def self.escape_identifier(string)
string = string.to_s
raise "Invalid column-string: #{string}" if string.include?("[") || string.include?("]")
string
end
|
.escape_index(name) ⇒ Object
42
43
44
|
# File 'lib/baza/driver/tiny.rb', line 42
def self.escape_index(name)
escape_identifier(name)
end
|
.escape_table(name) ⇒ Object
46
47
48
|
# File 'lib/baza/driver/tiny.rb', line 46
def self.escape_table(name)
escape_identifier(name)
end
|
.quote_column(column_name) ⇒ Object
90
91
92
|
# File 'lib/baza/driver/tiny.rb', line 90
def self.quote_column(column_name)
quote_identifier(column_name)
end
|
.quote_database(database_name) ⇒ Object
86
87
88
|
# File 'lib/baza/driver/tiny.rb', line 86
def self.quote_database(database_name)
quote_identifier(database_name)
end
|
.quote_identifier(name) ⇒ Object
82
83
84
|
# File 'lib/baza/driver/tiny.rb', line 82
def self.quote_identifier(name)
"[#{escape_database(name)}]"
end
|
.quote_index(index_name) ⇒ Object
94
95
96
|
# File 'lib/baza/driver/tiny.rb', line 94
def self.quote_index(index_name)
quote_identifier(index_name)
end
|
.quote_table(table_name) ⇒ Object
98
99
100
|
# File 'lib/baza/driver/tiny.rb', line 98
def self.quote_table(table_name)
quote_identifier(table_name)
end
|
Instance Method Details
#close ⇒ Object
20
21
22
|
# File 'lib/baza/driver/tiny.rb', line 20
def close
@client.close
end
|
#escape(value) ⇒ Object
24
25
26
|
# File 'lib/baza/driver/tiny.rb', line 24
def escape(value)
@client.escape(value)
end
|
#escape_column(name) ⇒ Object
54
55
56
|
# File 'lib/baza/driver/tiny.rb', line 54
def escape_column(name)
self.class.escape_identifier(name)
end
|
#escape_database(name) ⇒ Object
50
51
52
|
# File 'lib/baza/driver/tiny.rb', line 50
def escape_database(name)
self.class.escape_identifier(name)
end
|
#escape_index(name) ⇒ Object
58
59
60
|
# File 'lib/baza/driver/tiny.rb', line 58
def escape_index(name)
self.class.escape_identifier(name)
end
|
#escape_table(name) ⇒ Object
62
63
64
|
# File 'lib/baza/driver/tiny.rb', line 62
def escape_table(name)
self.class.escape_identifier(name)
end
|
#insert(table_name, data, args = {}) ⇒ Object
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/baza/driver/tiny.rb', line 66
def insert(table_name, data, args = {})
sql = Baza::SqlQueries::GenericInsert.new({
db: @db,
table_name: table_name,
data: data
}.merge(args)).to_sql
result = @client.execute(sql)
result.insert if args[:return_id]
end
|
#query(sql) ⇒ Object
77
78
79
80
|
# File 'lib/baza/driver/tiny.rb', line 77
def query(sql)
result = @client.execute(sql)
Baza::Driver::Tiny::Result.new(result)
end
|
#quote_column(column_name) ⇒ Object
106
107
108
|
# File 'lib/baza/driver/tiny.rb', line 106
def quote_column(column_name)
self.class.quote_identifier(column_name)
end
|
#quote_database(database_name) ⇒ Object
102
103
104
|
# File 'lib/baza/driver/tiny.rb', line 102
def quote_database(database_name)
self.class.quote_identifier(database_name)
end
|
#quote_index(index_name) ⇒ Object
110
111
112
|
# File 'lib/baza/driver/tiny.rb', line 110
def quote_index(index_name)
self.class.quote_identifier(index_name)
end
|
#quote_table(table_name) ⇒ Object
114
115
116
|
# File 'lib/baza/driver/tiny.rb', line 114
def quote_table(table_name)
self.class.quote_identifier(table_name)
end
|