Skip to content

Commit

Permalink
regenerate examples
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenafamo committed Nov 25, 2022
1 parent 77dfad2 commit a15998b
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 34 deletions.
16 changes: 16 additions & 0 deletions examples/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ func (t *topVisitor) Visit(n ast.Node) ast.Visitor {

return nil

case *ast.AssignStmt:
if !t.blockFound {
return nil
}

if stmt.Tok != token.DEFINE {
return nil
}

// multiple declaration
if len(stmt.Lhs) > 1 {
return nil
}

return &valueVisitor{fset: t.fset, destination: t.destination}

case *ast.DeclStmt:
if !t.blockFound {
return nil
Expand Down
5 changes: 2 additions & 3 deletions examples/mysql/insert.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,9 @@ mysql.Insert(
qm.Values(mysql.Arg(8, "Anvil Distribution")),
qm.Values(mysql.Arg(9, "Sentry Distribution")),
qm.As("new"),
qm.OnDuplicateKeyUpdate(
qm.Set("dbname", mysql.Concat(
qm.OnDuplicateKeyUpdate().
Set("dbname", mysql.Concat(
"new.dname", mysql.S(" (formerly "), "d.dname", mysql.S(")"),
)),
),
)
```
6 changes: 2 additions & 4 deletions examples/mysql/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ Code:
mysql.Select(
qm.From(
mysql.F("generate_series", 1, 3),
qm.As("x", "p", "q", "s"),
),
).As("x", "p", "q", "s"),
qm.OrderBy("p"),
)
```
Expand Down Expand Up @@ -100,8 +99,7 @@ mysql.Select(
Minus("created_date").
As("difference")),
qm.From("presales_presalestatus")),
qm.As("differnce_by_status"),
),
).As("differnce_by_status"),
qm.Where(mysql.X("status").In(mysql.S("A"), mysql.S("B"), mysql.S("C"))),
qm.GroupBy("status"),
)
Expand Down
3 changes: 1 addition & 2 deletions examples/mysql/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ Code:

```go
mysql.Update(
qm.Table("employees"),
qm.Table("accounts"),
qm.Table("employees, accounts"),
qm.Set("sales_count", "sales_count + 1"),
qm.Where(mysql.X("accounts.name").EQ(mysql.Arg("Acme Corporation"))),
qm.Where(mysql.X("employees.id").EQ("accounts.sales_person")),
Expand Down
44 changes: 38 additions & 6 deletions examples/psql/insert.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,44 @@ psql.Insert(
qm.IntoAs("distributors", "d", "did", "dname"),
qm.Values(psql.Arg(8, "Anvil Distribution")),
qm.Values(psql.Arg(9, "Sentry Distribution")),
qm.OnConflict("did").DoUpdate().Set(
"dname",
psql.Concat(
qm.OnConflict("did").DoUpdate().
Set("dname", psql.Concat(
"EXCLUDED.dname", psql.S(" (formerly "), "d.dname", psql.S(")"),
),
).Where(psql.X("d.zipcode").NE(psql.S("21201"))),
)).
Where(psql.X("d.zipcode").NE(psql.S("21201"))),
)
```

## Upsert On Constraint

SQL:

```sql
INSERT INTO distributors AS "d" ("did", "dname")
VALUES ($1, $2), ($3, $4)
ON CONFLICT ON CONSTRAINT distributors_pkey DO UPDATE
SET "dname" = EXCLUDED. "dname"
WHERE (d.zipcode <> '21201')
```

Args:

* `8`
* `"Anvil Distribution"`
* `9`
* `"Sentry Distribution"`

Code:

```go
psql.Insert(
qm.IntoAs("distributors", "d", "did", "dname"),
qm.Values(psql.Arg(8, "Anvil Distribution")),
qm.Values(psql.Arg(9, "Sentry Distribution")),
qm.OnConflictOnConstraint("distributors_pkey").
DoUpdate().
SetExcluded("dname").
Where(psql.X("d.zipcode").NE(psql.S("21201"))),
)
```

Expand All @@ -117,6 +149,6 @@ Code:
psql.Insert(
qm.Into("films"),
qm.Values(psql.Arg("UA502", "Bananas", 105, "1971-07-13", "Comedy", "82 mins")),
qm.OnConflict(nil).DoNothing(),
qm.OnConflict().DoNothing(),
)
```
7 changes: 3 additions & 4 deletions examples/psql/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,13 @@ Code:

```go
psql.Select(
qm.From(
qm.FromFunction(
psql.F(
"json_to_recordset",
psql.Arg(`[{"a":40,"b":"foo"},{"a":"100","b":"bar"}]`),
).Col("a", "INTEGER").Col("b", "TEXT"),
psql.F("generate_series", 1, 3),
qm.As("x", "p", "q", "s"),
),
).As("x", "p", "q", "s"),
qm.OrderBy("p"),
)
```
Expand Down Expand Up @@ -139,7 +138,7 @@ psql.Select(
Minus("created_date").
As("difference")),
qm.From("presales_presalestatus")),
qm.As("differnce_by_status")),
).As("differnce_by_status"),
qm.Where(psql.X("status").In(psql.S("A"), psql.S("B"), psql.S("C"))),
qm.GroupBy("status"),
)
Expand Down
13 changes: 5 additions & 8 deletions examples/sqlite/insert.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Code:
sqlite.Insert(
qm.Into("films"),
qm.Values(sqlite.Arg("UA502", "Bananas", 105, "1971-07-13", "Comedy", "82 mins")),
qm.OnConflict(nil).DoNothing(),
qm.OnConflict().DoNothing(),
)
```

Expand All @@ -94,7 +94,7 @@ SQL:
INSERT INTO distributors AS "d" ("did", "dname")
VALUES (?1, ?2), (?3, ?4)
ON CONFLICT (did) DO UPDATE
SET dname = (EXCLUDED.dname || ' (formerly ' || d.dname || ')')
SET "dname" = EXCLUDED."dname"
WHERE (d.zipcode <> '21201')
```

Expand All @@ -112,12 +112,9 @@ sqlite.Insert(
qm.IntoAs("distributors", "d", "did", "dname"),
qm.Values(sqlite.Arg(8, "Anvil Distribution")),
qm.Values(sqlite.Arg(9, "Sentry Distribution")),
qm.OnConflict("did").DoUpdate().Set(
"dname",
sqlite.Concat(
"EXCLUDED.dname", sqlite.S(" (formerly "), "d.dname", sqlite.S(")"),
),
).Where(sqlite.X("d.zipcode").NE(sqlite.S("21201"))),
qm.OnConflict("did").DoUpdate().
SetExcluded("dname").
Where(sqlite.X("d.zipcode").NE(sqlite.S("21201"))),
)
```

Expand Down
8 changes: 2 additions & 6 deletions examples/sqlite/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ Code:

```go
sqlite.Select(
qm.From(
sqlite.F("generate_series", 1, 3),
qm.As("x", "p", "q", "s"),
),
qm.From(sqlite.F("generate_series", 1, 3)).As("x", "p", "q", "s"),
qm.OrderBy("p"),
)
```
Expand Down Expand Up @@ -100,8 +97,7 @@ sqlite.Select(
Minus("created_date").
As("difference")),
qm.From("presales_presalestatus")),
qm.As("differnce_by_status"),
),
).As("differnce_by_status"),
qm.Where(sqlite.X("status").In(sqlite.S("A"), sqlite.S("B"), sqlite.S("C"))),
qm.GroupBy("status"),
)
Expand Down
2 changes: 1 addition & 1 deletion examples/sqlite/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Code:
```go
sqlite.Update(
qm.TableAs("employees", "e"),
qm.NotIndexed(),
qm.TableNotIndexed(),
qm.Set("sales_count", "sales_count + 1"),
qm.Where(sqlite.X("id").EQ(sqlite.P(sqlite.Select(
selectQM.Columns("sales_person"),
Expand Down

0 comments on commit a15998b

Please sign in to comment.