Skip to content

Commit

Permalink
implement sort by
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeljesus committed Feb 23, 2018
1 parent 522ab48 commit d165e3a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/dumper/generic/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (p *sqlDumper) readAndDumpTables(done chan<- struct{}, configTables config.
opts = reader.ReadTableOpt{
PrimaryKey: tableConfig.PrimaryKey,
Match: tableConfig.Filter.Match,
Sorts: tableConfig.Filter.Sorts,
Limit: tableConfig.Filter.Limit,
Relationships: p.relationshipConfigToOptions(tableConfig.Relationships),
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/reader/generic/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func (s *SqlReader) buildQuery(tableName string, opts reader.ReadTableOpt) (sq.S
query = query.Where(opts.Match)
}

for k, v := range opts.Sorts {
query = query.OrderBy(fmt.Sprintf("%s %s", k, v))
}

if opts.Limit > 0 {
query = query.Limit(opts.Limit)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type (
Columns []string
// Match is a condition field to dump only certain amount data
Match string
// Sort the results
Sorts map[string]string
// Defines a limit of results to be fetched
Limit uint64
// Relationships defines an slice of relationship definitions
Expand Down

0 comments on commit d165e3a

Please sign in to comment.