e30c89c1bf982431043994602c0a2faa03dcd115
[mailshears.git] / src / postfixadmin_db.rb
1 require 'postgres'
2
3 class PostfixadminDb
4
5 def initialize(db_host,
6 db_port,
7 db_opts,
8 db_tty,
9 db_name,
10 db_user,
11 db_pass)
12
13 @db_host = db_host
14 @db_port = db_port
15 @db_opts = db_opts
16 @db_tty = db_tty
17 @db_name = db_name
18 @db_user = db_user
19 @db_pass = db_pass
20 end
21
22
23 def get_accounts_from_db()
24 # Just assume PostgreSQL for now.
25 begin
26 connection = PGconn.connect(@db_host,
27 @db_port,
28 @db_opts,
29 @db_tty,
30 @db_name,
31 @db_user,
32 @db_pass)
33
34 sql_query = 'SELECT address FROM alias;'
35 result = connection.query(sql_query)
36 connection.close()
37 rescue PGError => e
38 # But pretend like we're database-agnostic in case we ever are.
39 raise DatabaseError.new(e)
40 end
41
42 return result
43 end
44
45 end