]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - lib/rbot/journal/postgres.rb
journal: started implementing postgres storage
[user/henk/code/ruby/rbot.git] / lib / rbot / journal / postgres.rb
1 # encoding: UTF-8
2 #-- vim:sw=2:et
3 #++
4 #
5 # :title: journal backend for postgresql
6
7 require 'pg'
8
9 module Irc
10 class Bot
11 module Journal
12   module Storage
13     class PostgresStorage < AbstractStorage
14       def initialize(opts={})
15         @uri = opts[:uri] || 'postgresql://localhost/rbot_journal'
16         @conn = PG.connect(@uri)
17         @version = @conn.exec('SHOW server_version;')[0]['server_version']
18
19         @version.gsub!(/^(\d+\.\d+)$/, '\1.0')
20         log 'journal storage: postgresql connected to version: ' + @version
21         
22         version = @version.split('.')[0,3].join.to_i
23         if version < 930
24           raise StorageError.new(
25             'PostgreSQL Version too old: %s, supported: >= 9.3' % [@version])
26         end
27         @jsonb = (version >= 940)
28         log 'journal storage: no jsonb support, consider upgrading postgres'
29
30         create_table
31       end
32
33       def create_table
34       end
35     end
36   end
37 end # Journal
38 end # Bot
39 end # Irc