Skip to content

Commit

Permalink
remove group by condition
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeljesus committed Feb 26, 2018
1 parent 4868471 commit 2ac5066
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 22 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ Dump the latest 100 users with it's orders

[[Tables]]
Name = "orders"
PrimaryKey = "id"
[[Tables.Relationships]]
ForeignKey = "user_id"
ReferencedTable = "users"
Expand Down
7 changes: 0 additions & 7 deletions examples/user-orders.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
[[Tables]]
# Dump only orders which are related to the matching users
Name = "orders"
PrimaryKey = "id"
# Behind the scenes it will generate the following sql query:
# SELECT orders.* FROM orders
# JOIN users ON users.id = orders.user_id
# WHERE users.status = 'active'
# ORDER BY created_at DESC
# GROUP BY order_items.id
[[Tables.Relationships]]
Table = "orders"
ForeignKey = "user_id"
ReferencedTable = "users"
ReferencedKey = "id"
[Tables.Filter]
Expand All @@ -35,22 +32,18 @@
[[Tables]]
# Dump only order items which are related to the matching users orders
Name = "order_items"
PrimaryKey = "id"
# Behind the scenes it will generate the following sql query:
# SELECT order_items.* FROM order_items
# JOIN orders ON orders.id = order_items.order_id
# JOIN users ON users.id = orders.user_id
# WHERE users.status = 'active'
# ORDER BY created_at DESC
# GROUP BY order_items.id
[[Tables.Relationships]]
Table = "order_items"
ForeignKey = "order_id"
ReferencedTable = "orders"
ReferencedKey = "id"
[[Tables.Relationships]]
Table = "orders"
ForeignKey = "user_id"
ReferencedTable = "users"
ReferencedKey = "id"
[Tables.Filter]
Expand Down
1 change: 0 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type (
// Table represents a klepto table definition
Table struct {
Name string
PrimaryKey string
IgnoreData bool
Filter Filter
Anonymise map[string]string
Expand Down
2 changes: 0 additions & 2 deletions pkg/dumper/generic/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ 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,
Expand Down Expand Up @@ -149,7 +148,6 @@ func (p *sqlDumper) relationshipConfigToOptions(relationshipsConfig []*config.Re
Table: r.Table,
ReferencedTable: r.ReferencedTable,
ReferencedKey: r.ReferencedKey,
ForeignKey: r.ForeignKey,
})
}

Expand Down
1 change: 0 additions & 1 deletion pkg/dumper/query/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func (d *textDumper) relationshipConfigToOptions(relationshipsConfig []*config.R
opts = append(opts, &reader.RelationshipOpt{
ReferencedTable: r.ReferencedTable,
ReferencedKey: r.ReferencedKey,
ForeignKey: r.ForeignKey,
})
}

Expand Down
7 changes: 0 additions & 7 deletions pkg/reader/generic/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,6 @@ func (s *SqlReader) buildQuery(tableName string, opts reader.ReadTableOpt) (sq.S
))
}

if len(opts.Relationships) > 0 {
if opts.PrimaryKey == "" {
opts.PrimaryKey = "id"
}
query = query.GroupBy(fmt.Sprintf("%s.%s", tableName, opts.PrimaryKey))
}

if opts.Match != "" {
query = query.Where(opts.Match)
}
Expand Down
3 changes: 0 additions & 3 deletions pkg/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ type (

// ReadTableOpt represents the read table options
ReadTableOpt struct {
// PrimaryKey is the primary key
PrimaryKey string
// Columns contains the (quoted) column of the table
Columns []string
// Match is a condition field to dump only certain amount data
Expand All @@ -48,7 +46,6 @@ type (
// RelationshipOpt represents the relationships options
RelationshipOpt struct {
Table string
ForeignKey string
ReferencedTable string
ReferencedKey string
}
Expand Down

0 comments on commit 2ac5066

Please sign in to comment.