class JunglePath::DBAccess::IO::DB

Attributes

base[R]
config[R]
copy[R]
database_name[R]
delete[R]
insert[R]
postgresql[R]
schema[R]
select[R]
update[R]

Public Class Methods

new(config, logger=nil) click to toggle source
# File lib/jungle_path/db_access/io/db.rb, line 25
def initialize(config, logger=nil)
        @logger = logger
        @config = config
        @postgresql = config
        @db = JunglePath::DBAccess::IO.connection(
                database_type: config.type,
                user_name: config.user_name,
                database_name: config.name,
                host: config.host,
                extensions: config.extensions,
                password: config.password,
                port: config.port,
                options: config.options
        )
        @select = JunglePath::DBAccess::IO::Select.new @db, @logger
        @insert = JunglePath::DBAccess::IO::Insert.new @db, @logger
        @update = JunglePath::DBAccess::IO::Update.new @db, @logger
        @delete = JunglePath::DBAccess::IO::Delete.new @db, @logger
        @schema = JunglePath::DBAccess::IO::Schema.new @db, @logger
        @copy = JunglePath::DBAccess::IO::Copy.new @db, @logger
        @base = @db
        @database_name = config.name
end

Public Instance Methods

copy_table_data(from_table, to_table) click to toggle source
# File lib/jungle_path/db_access/io/db.rb, line 65
def copy_table_data(from_table, to_table)
        JunglePath::DBAccess::Meta::Table.copy_data(self, from_table, to_table)
end
create_table_like(from_table, to_table) click to toggle source
# File lib/jungle_path/db_access/io/db.rb, line 61
def create_table_like(from_table, to_table)
        JunglePath::DBAccess::Meta::Table.create_like(self, from_table, to_table)
end
drop_table?(table_name) click to toggle source
# File lib/jungle_path/db_access/io/db.rb, line 49
def drop_table? table_name
        JunglePath::DBAccess::Meta::Table.drop? self, table_name
end
get_max_id_for_table(table_name, id_column_name=:id) click to toggle source
# File lib/jungle_path/db_access/io/db.rb, line 75
def get_max_id_for_table(table_name, id_column_name=:id)
        ds = @db["select max(#{id_column_name}) as max_id from \"#{table_name}\""]
        result = ds.first
        max_id = result[:max_id]
end
rename_table(table_name, new_table_name) click to toggle source
# File lib/jungle_path/db_access/io/db.rb, line 57
def rename_table table_name, new_table_name
        JunglePath::DBAccess::Meta::Table.rename_table self, table_name, new_table_name
end
reset_sequence_for_table(table_name) click to toggle source
# File lib/jungle_path/db_access/io/db.rb, line 69
def reset_sequence_for_table(table_name)
        #max = @db[table_name.to_sym].max(:id) + 1
        #@db.run "alter sequence #{table_name}_id_seq restart with #{max}"
        @db.run "select setval('#{table_name}_id_seq', (select max(id)+1 from \"#{table_name}\"), false)"
end
table_exists?(table_name) click to toggle source
# File lib/jungle_path/db_access/io/db.rb, line 53
def table_exists? table_name
        JunglePath::DBAccess::Meta::Table.exists? self, table_name
end
transaction() { || ... } click to toggle source
# File lib/jungle_path/db_access/io/db.rb, line 81
def transaction
        @db.transaction do
                yield
        end
end

Private Instance Methods

begin_transaction() click to toggle source
# File lib/jungle_path/db_access/io/db.rb, line 89
def begin_transaction
        # not implemented :)
end
commit_transaction() click to toggle source
# File lib/jungle_path/db_access/io/db.rb, line 93
def commit_transaction
        # not implemented :)
end
rollback_transaction() click to toggle source
# File lib/jungle_path/db_access/io/db.rb, line 97
def rollback_transaction
        # not implemented :)
end