-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
55 lines (43 loc) · 1006 Bytes
/
main.go
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
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
_ "github.com/mattn/go-sqlite3"
_ "github.com/tfolkman/budget/routers"
"github.com/tfolkman/budget/models"
"log"
"time"
)
func init() {
orm.RegisterDriver("mysql", orm.DRSqlite)
orm.RegisterDataBase("default", "sqlite3", "./data/budget.db")
orm.RegisterModel(new(models.Budget))
orm.RegisterModel(new(models.Transactions))
}
func main() {
// Database alias.
name := "default"
// Drop table and re-create.
force := false
// Print log.
verbose := true
// Error.
err := orm.RunSyncdb(name, force, verbose)
if err != nil {
log.Println(err)
}
o := orm.NewOrm()
var count int
o.Raw("SELECT count(*) as Count from budget").QueryRow(&count)
if count == 0 {
currentTime := time.Now()
m := time.Now().Month()
budget := new(models.Budget)
budget.Amount = 200.00
budget.Month = int(m)
budget.Year = currentTime.Year()
budget.Name = "Groceries"
o.Insert(budget)
}
beego.Run()
}