diff --git a/docs/guide.md b/docs/guide.md index bd8a1bc..fa9852b 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -520,7 +520,20 @@ query { } ``` -### Advanced queries +### Sorting + +To sort or ordering results just use the `order_by` argument. This can be combined with `where`, `search`, etc to build complex queries to fit you needs. + +```graphql +query { + products(order_by: { cached_votes_total: desc }) { + id + name + } +} +``` + +### Filtering Super Graph support complex queries where you can add filters, ordering,offsets and limits on the query. For example the below query will list all products where the price is greater than 10 and the id is not 5. diff --git a/psql/insert.go b/psql/insert.go index 64f7ffd..a61cbdf 100644 --- a/psql/insert.go +++ b/psql/insert.go @@ -131,7 +131,6 @@ func nestedInsertRelColumnsMap(item kvitem) map[string]struct{} { func renderNestedInsertRelColumns(w io.Writer, item kvitem, values bool) error { if len(item.items) == 0 { if item.relPC != nil && item.relPC.Type == RelOneToMany { - io.WriteString(w, `, `) if values { colWithTable(w, item.relPC.Left.Table, item.relPC.Left.Col) } else { @@ -141,14 +140,18 @@ func renderNestedInsertRelColumns(w io.Writer, item kvitem, values bool) error { } else { // Render child foreign key columns if child-to-parent // relationship is one-to-many + i := 0 for _, v := range item.items { if v.relCP.Type == RelOneToMany { - io.WriteString(w, `, `) + if i != 0 { + io.WriteString(w, `, `) + } if values { colWithTable(w, v.relCP.Left.Table, v.relCP.Left.Col) } else { quoted(w, v.relCP.Right.Col) } + i++ } } } diff --git a/psql/mutate.go b/psql/mutate.go index 0afc7f0..32f69d6 100644 --- a/psql/mutate.go +++ b/psql/mutate.go @@ -360,6 +360,7 @@ func renderInsertUpdateColumns(w io.Writer, values bool) (uint32, error) { root := &qc.Selects[0] + renderedCol := false n := 0 for _, cn := range ti.Columns { @@ -386,6 +387,10 @@ func renderInsertUpdateColumns(w io.Writer, } else { quoted(w, cn.Name) } + + if !renderedCol { + renderedCol = true + } n++ } @@ -407,10 +412,17 @@ func renderInsertUpdateColumns(w io.Writer, io.WriteString(w, root.PresetMap[cn]) io.WriteString(w, `' :: `) io.WriteString(w, col.Type) - } else { quoted(w, cn) } + + if !renderedCol { + renderedCol = true + } + } + + if len(skipcols) != 0 && renderedCol { + io.WriteString(w, `, `) } return 0, nil } diff --git a/psql/update.go b/psql/update.go index 284ceee..8ca9ef4 100644 --- a/psql/update.go +++ b/psql/update.go @@ -164,7 +164,6 @@ func renderNestedUpdateRelColumns(w io.Writer, item kvitem, values bool) error { // relationship is one-to-many for _, v := range item.items { if v._ctype > 0 && v.relCP.Type == RelOneToMany { - io.WriteString(w, `, `) if values { colWithTable(w, v.relCP.Left.Table, v.relCP.Left.Col) } else { diff --git a/serv/cmd_migrate.go b/serv/cmd_migrate.go index 6d88565..e7ec4b4 100644 --- a/serv/cmd_migrate.go +++ b/serv/cmd_migrate.go @@ -203,7 +203,7 @@ func cmdDBMigrate(cmd *cobra.Command, args []string) { } if err != nil { - logger.Info().Err(err).Send() + logger.Fatal().Err(err).Send() // if err, ok := err.(m.MigrationPgError); ok { // if err.Detail != "" {