aboutsummaryrefslogtreecommitdiff
path: root/cmd/airlines/main.go
blob: 092a280f650a2139e5a07678fe8955125259db70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	ljson "airlines/pkg/adapters/json"
	"airlines/pkg/store"

	"github.com/joho/godotenv"
)

func main() {
	// run with MAKE only
	err := godotenv.Load("../../.env")
	if err != nil {
		fmt.Println(err)
	}

	store, err := store.NewStore(fmt.Sprintf("postgres://%s:%s@%s:%s/%s", os.Getenv("DB_USER"), os.Getenv("DB_PASSWORD"), os.Getenv("DB_HOST"), os.Getenv("DB_PORT"), os.Getenv("DB_NAME")))
	if err != nil {
		panic(err)
	}
	_ = store.AutoMigrate()

	// i, err := json.ImportForumProfilesJSON(context.Background(), store, "../../full.json", 16384)
	// fmt.Println(i, err)
	f, err := os.Open("../../full.json")

	dec := json.NewDecoder(f)
	// optional: be strict about unexpected fields
	// dec.DisallowUnknownFields()

	var root ljson.JsonRoot
	if err := dec.Decode(&root); err != nil {
		panic(err)
	}

	root.DumpToDb(context.Background(), store)
	// fmt.Println(root)

}