Class: Baza::Database
Instance Attribute Summary collapse
Instance Method Summary
collapse
#model_name, #to_model
Constructor Details
#initialize(args) ⇒ Database
Returns a new instance of Database.
7
8
9
10
11
12
|
# File 'lib/baza/database.rb', line 7
def initialize(args)
@db = args.fetch(:db)
@driver = args.fetch(:driver)
@name = args.fetch(:name)
@name_was = @name
end
|
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
4
5
6
|
# File 'lib/baza/database.rb', line 4
def db
@db
end
|
#driver ⇒ Object
Returns the value of attribute driver.
4
5
6
|
# File 'lib/baza/database.rb', line 4
def driver
@driver
end
|
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/baza/database.rb', line 5
def name
@name
end
|
#name_was ⇒ Object
Returns the value of attribute name_was.
4
5
6
|
# File 'lib/baza/database.rb', line 4
def name_was
@name_was
end
|
Instance Method Details
#import_file!(path) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/baza/database.rb', line 14
def import_file!(path)
File.open(path, "r") do |io|
use do
Baza::Commands::Importer.new(db: @db, io: io).execute
end
end
end
|
#table(name) ⇒ Object
33
34
35
36
37
|
# File 'lib/baza/database.rb', line 33
def table(name)
table = tables(name: name).first
raise Baza::Errors::TableNotFound unless table
table
end
|
#table_exists?(name) ⇒ Boolean
39
40
41
42
43
44
|
# File 'lib/baza/database.rb', line 39
def table_exists?(name)
table(name)
true
rescue Baza::Errors::TableNotFound
false
end
|
#tables(args = {}) ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/baza/database.rb', line 22
def tables(args = {})
list_args = {database: name}
list_args[:name] = args.fetch(:name) if args[:name]
ArrayEnumerator.new do |yielder|
@db.tables.list(list_args) do |table|
yielder << table
end
end
end
|
#to_param ⇒ Object
50
51
52
|
# File 'lib/baza/database.rb', line 50
def to_param
name
end
|
#use(&blk) ⇒ Object
54
55
56
|
# File 'lib/baza/database.rb', line 54
def use(&blk)
@db.databases.with_database(name, &blk)
end
|