|
|
|
@ -3,6 +3,7 @@ package main |
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"context" |
|
|
|
|
"errors" |
|
|
|
|
"database/sql" |
|
|
|
|
"github.com/uptrace/bun" |
|
|
|
|
"github.com/uptrace/bun/extra/bundebug" |
|
|
|
@ -10,7 +11,13 @@ import ( |
|
|
|
|
"github.com/uptrace/bun/driver/pgdriver" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var feeds []Feed |
|
|
|
|
var categories []Category |
|
|
|
|
var entries []Entry |
|
|
|
|
var users []User |
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
|
var err error |
|
|
|
|
ctx := context.Background() |
|
|
|
|
dsn := "postgres://apache:@localhost:5432/miniflux?sslmode=disable" |
|
|
|
|
// dsn := "unix://user:pass@dbname/var/run/postgresql/.s.PGSQL.5432"
|
|
|
|
@ -22,31 +29,28 @@ func main() { |
|
|
|
|
bundebug.FromEnv("BUNDEBUG"), |
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
var feeds []Feed |
|
|
|
|
var categories []Category |
|
|
|
|
var entries []Entry |
|
|
|
|
var users []User |
|
|
|
|
|
|
|
|
|
// Turn these into funcs with error handling, logging, return vals etc.
|
|
|
|
|
feederr := db.NewSelect().Model(&feeds).OrderExpr("title ASC").Limit(10).Scan(ctx) |
|
|
|
|
|
|
|
|
|
if feederr != nil { |
|
|
|
|
return |
|
|
|
|
errors.Join(feederr, err) |
|
|
|
|
} |
|
|
|
|
fmt.Printf("%+v\n", feeds) |
|
|
|
|
categoryerr := db.NewSelect().Model(&categories).OrderExpr("title ASC").Scan(ctx) |
|
|
|
|
if categoryerr != nil { |
|
|
|
|
return |
|
|
|
|
errors.Join(categoryerr, err) |
|
|
|
|
} |
|
|
|
|
fmt.Printf("%+v\n", categories) |
|
|
|
|
entryerr := db.NewSelect().Model(&entries).OrderExpr("published_at ASC").Limit(10).Scan(ctx) |
|
|
|
|
if entryerr != nil { |
|
|
|
|
return |
|
|
|
|
errors.Join(entryerr, err) |
|
|
|
|
} |
|
|
|
|
fmt.Printf("%+v\n", entries) |
|
|
|
|
usererr := db.NewSelect().Model(&users).OrderExpr("id ASC").Scan(ctx) |
|
|
|
|
if usererr != nil { |
|
|
|
|
return |
|
|
|
|
errors.Join(usererr, err) |
|
|
|
|
} |
|
|
|
|
fmt.Printf("%+v\n", entries) |
|
|
|
|
fmt.Printf("%+v\n", categories) |
|
|
|
|
fmt.Printf("%+v\n", feeds) |
|
|
|
|
fmt.Printf("%+v\n", users) |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
} |
|
|
|
|