Implement pagination and simple filtering
This commit is contained in:
@@ -21,6 +21,7 @@ type Client struct {
|
||||
|
||||
// Struct to hold table rows browsing options
|
||||
type RowsOptions struct {
|
||||
Where string // Custom filter
|
||||
Offset int // Number of rows to skip
|
||||
Limit int // Number of rows to fetch
|
||||
SortColumn string // Column to sort by
|
||||
@@ -99,6 +100,10 @@ func (client *Client) Table(table string) (*Result, error) {
|
||||
func (client *Client) TableRows(table string, opts RowsOptions) (*Result, error) {
|
||||
sql := fmt.Sprintf(`SELECT * FROM "%s"`, table)
|
||||
|
||||
if opts.Where != "" {
|
||||
sql += fmt.Sprintf(" WHERE %s", opts.Where)
|
||||
}
|
||||
|
||||
if opts.SortColumn != "" {
|
||||
if opts.SortOrder == "" {
|
||||
opts.SortOrder = "ASC"
|
||||
@@ -118,6 +123,16 @@ func (client *Client) TableRows(table string, opts RowsOptions) (*Result, error)
|
||||
return client.query(sql)
|
||||
}
|
||||
|
||||
func (client *Client) TableRowsCount(table string, opts RowsOptions) (*Result, error) {
|
||||
sql := fmt.Sprintf(`SELECT COUNT(1) FROM "%s"`, table)
|
||||
|
||||
if opts.Where != "" {
|
||||
sql += fmt.Sprintf(" WHERE %s", opts.Where)
|
||||
}
|
||||
|
||||
return client.query(sql)
|
||||
}
|
||||
|
||||
func (client *Client) TableInfo(table string) (*Result, error) {
|
||||
return client.query(statements.PG_TABLE_INFO, table)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user