diff --git a/pkg/dumper/generic/sql.go b/pkg/dumper/generic/sql.go index 6a0b43c..df50336 100644 --- a/pkg/dumper/generic/sql.go +++ b/pkg/dumper/generic/sql.go @@ -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), } diff --git a/pkg/reader/generic/sql.go b/pkg/reader/generic/sql.go index b46d625..5548a5e 100644 --- a/pkg/reader/generic/sql.go +++ b/pkg/reader/generic/sql.go @@ -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) } diff --git a/pkg/reader/reader.go b/pkg/reader/reader.go index 1c9caed..f9ec430 100644 --- a/pkg/reader/reader.go +++ b/pkg/reader/reader.go @@ -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