Method: PostgresqlWeb::Connection#data
- Defined in:
- lib/postgresql_web/connection.rb
#data(table_name, per_page, page) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/postgresql_web/connection.rb', line 43 def data(table_name, per_page, page) if page <= 1 page = 1 end total_records = connection.exec("select count(1) from #{table_name}").column_values(0).first sql = "select * from #{table_name}" if page > 1 sql += " offset #{per_page * (page - 1)}" end sql += " limit #{per_page}" puts sql data = connection.exec(sql).to_a puts [data, total_records] end |