|
|
|
@ -1,14 +1,15 @@ |
|
|
|
|
package main |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"context" |
|
|
|
|
"errors" |
|
|
|
|
"database/sql" |
|
|
|
|
"errors" |
|
|
|
|
"fmt" |
|
|
|
|
|
|
|
|
|
"github.com/uptrace/bun" |
|
|
|
|
"github.com/uptrace/bun/extra/bundebug" |
|
|
|
|
"github.com/uptrace/bun/dialect/pgdialect" |
|
|
|
|
"github.com/uptrace/bun/driver/pgdriver" |
|
|
|
|
"github.com/uptrace/bun/extra/bundebug" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var feeds []Feed |
|
|
|
@ -29,28 +30,58 @@ func main() { |
|
|
|
|
bundebug.FromEnv("BUNDEBUG"), |
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Turn these into funcs with error handling, logging, return vals etc.
|
|
|
|
|
feederr := db.NewSelect().Model(&feeds).OrderExpr("title ASC").Limit(10).Scan(ctx) |
|
|
|
|
feederr := db.NewSelect(). |
|
|
|
|
Model(&feeds). |
|
|
|
|
OrderExpr("title ASC"). |
|
|
|
|
Limit(10). |
|
|
|
|
Scan(ctx) |
|
|
|
|
|
|
|
|
|
if feederr != nil { |
|
|
|
|
errors.Join(feederr, err) |
|
|
|
|
} |
|
|
|
|
categoryerr := db.NewSelect().Model(&categories).OrderExpr("title ASC").Scan(ctx) |
|
|
|
|
categoryerr := db.NewSelect(). |
|
|
|
|
Model(&categories). |
|
|
|
|
OrderExpr("title ASC"). |
|
|
|
|
Scan(ctx) |
|
|
|
|
if categoryerr != nil { |
|
|
|
|
errors.Join(categoryerr, err) |
|
|
|
|
} |
|
|
|
|
entryerr := db.NewSelect().Model(&entries).OrderExpr("published_at ASC").Limit(10).Scan(ctx) |
|
|
|
|
entryerr := db.NewSelect(). |
|
|
|
|
Model(&entries). |
|
|
|
|
OrderExpr("published_at ASC"). |
|
|
|
|
Limit(10). |
|
|
|
|
Scan(ctx) |
|
|
|
|
if entryerr != nil { |
|
|
|
|
errors.Join(entryerr, err) |
|
|
|
|
} |
|
|
|
|
usererr := db.NewSelect().Model(&users).OrderExpr("id ASC").Scan(ctx) |
|
|
|
|
usererr := db.NewSelect(). |
|
|
|
|
Model(&users). |
|
|
|
|
OrderExpr("id ASC"). |
|
|
|
|
Scan(ctx) |
|
|
|
|
if usererr != nil { |
|
|
|
|
errors.Join(usererr, err) |
|
|
|
|
} |
|
|
|
|
fmt.Printf("%+v\n", entries) |
|
|
|
|
fmt.Printf("%+v\n", categories) |
|
|
|
|
fmt.Printf("%+v\n", feeds) |
|
|
|
|
fmt.Printf("%+v\n", users) |
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
fmt.Printf("[]Entry\n") |
|
|
|
|
for _, val := range entries { |
|
|
|
|
fmt.Printf("val = %s\n", val) |
|
|
|
|
} |
|
|
|
|
fmt.Printf("[]Category\n") |
|
|
|
|
for _, val := range categories { |
|
|
|
|
|
|
|
|
|
fmt.Printf("val = %s\n", val) |
|
|
|
|
} |
|
|
|
|
fmt.Printf("[]Feed\n") |
|
|
|
|
for _, val := range feeds { |
|
|
|
|
fmt.Printf("val = %s\n", val) |
|
|
|
|
} |
|
|
|
|
fmt.Printf("[]User\n") |
|
|
|
|
for _, val := range users { |
|
|
|
|
fmt.Printf("val = %s\n", val) |
|
|
|
|
} |
|
|
|
|
// fmt.Printf("%+v\n", entries)
|
|
|
|
|
// fmt.Printf("%+v\n", categories)
|
|
|
|
|
// fmt.Printf("%+v\n", feeds)
|
|
|
|
|
// fmt.Printf("%+v\n", users)
|
|
|
|
|
} |
|
|
|
|