Class: SequelRails::Storage::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel_rails/storage/abstract.rb

Direct Known Subclasses

Jdbc, Mysql, Postgres, Sqlite

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Abstract

Returns a new instance of Abstract.



6
7
8
9
# File 'lib/sequel_rails/storage/abstract.rb', line 6

def initialize(config)
  @config = config
  parse_url
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/sequel_rails/storage/abstract.rb', line 4

def config
  @config
end

Instance Method Details

#charsetObject



67
68
69
# File 'lib/sequel_rails/storage/abstract.rb', line 67

def charset
  @charset ||= config['charset'] || ENV['CHARSET'] || 'utf8'
end

#close_connectionsObject

To be overriden by subclasses



39
40
41
# File 'lib/sequel_rails/storage/abstract.rb', line 39

def close_connections
  true
end

#collationObject



71
72
73
# File 'lib/sequel_rails/storage/abstract.rb', line 71

def collation
  @collation ||= config['collation'] || ENV['COLLATION']
end

#createObject



11
12
13
14
15
# File 'lib/sequel_rails/storage/abstract.rb', line 11

def create
  res = _create
  warn "[sequel] Created database '#{database}'" if res
  res
end

#databaseObject



43
44
45
# File 'lib/sequel_rails/storage/abstract.rb', line 43

def database
  @database ||= config['database'] || config['path']
end

#dropObject



17
18
19
20
21
22
23
24
# File 'lib/sequel_rails/storage/abstract.rb', line 17

def drop
  return if ::Sequel::DATABASES.size == 0

  ::Sequel::Model.db.disconnect
  res = _drop
  warn "[sequel] Dropped database '#{database}'" if res
  res
end

#dump(filename) ⇒ Object



26
27
28
29
30
# File 'lib/sequel_rails/storage/abstract.rb', line 26

def dump(filename)
  res = _dump filename
  warn "[sequel] Dumped structure of database '#{database}' to '#{filename}'" if res
  res
end

#hostObject



55
56
57
# File 'lib/sequel_rails/storage/abstract.rb', line 55

def host
  @host ||= config['host'] || ''
end

#load(filename) ⇒ Object



32
33
34
35
36
# File 'lib/sequel_rails/storage/abstract.rb', line 32

def load(filename)
  res = _load filename
  warn "[sequel] Loaded structure of database '#{database}' from '#{filename}'" if res
  res
end

#ownerObject



63
64
65
# File 'lib/sequel_rails/storage/abstract.rb', line 63

def owner
  @owner ||= config['owner'] || ''
end

#passwordObject



51
52
53
# File 'lib/sequel_rails/storage/abstract.rb', line 51

def password
  @password ||= config['password'] || ''
end

#portObject



59
60
61
# File 'lib/sequel_rails/storage/abstract.rb', line 59

def port
  @port ||= config['port'] || ''
end

#schema_information_dump(migrator, sql_dump) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/sequel_rails/storage/abstract.rb', line 79

def schema_information_dump(migrator, sql_dump)
  res = ''
  inserts = schema_information_inserts(migrator, sql_dump)
  if inserts.any?
    res = inserts.join("\n")
    unless sql_dump
      res = <<-RUBY.strip_heredoc
        Sequel.migration do
          change do
            #{res}
          end
        end
      RUBY
    end
  end
  res
end

#search_pathObject



75
76
77
# File 'lib/sequel_rails/storage/abstract.rb', line 75

def search_path
  @search_path ||= config['search_path'] || '"$user", public'
end

#usernameObject



47
48
49
# File 'lib/sequel_rails/storage/abstract.rb', line 47

def username
  @username ||= config['username'] || config['user'] || ''
end