-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
main.go
50 lines (39 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
package main
/*
$ go get gopkg.in/reform.v1/reform
$ go generate ./models
$ go run .
Read more at: https://github.com/go-reform/reform
*/
import (
"database/sql"
"myapp/controllers"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/mvc"
_ "github.com/mattn/go-sqlite3"
"gopkg.in/reform.v1"
"gopkg.in/reform.v1/dialects/sqlite3"
)
func main() {
app := iris.New()
app.Logger().SetLevel("debug")
sqlDB, err := sql.Open("sqlite3", "./myapp.db")
if err != nil {
panic(err)
}
defer sqlDB.Close()
sqlStmt := `
drop table people;
create table people (id integer not null primary key, name text, email text, created_at datetime not null, updated_at datetime null);
delete from people;
`
_, err = sqlDB.Exec(sqlStmt)
if err != nil {
panic(err)
}
db := reform.NewDB(sqlDB, sqlite3.Dialect, reform.NewPrintfLogger(app.Logger().Debugf))
mvcApp := mvc.New(app.Party("/persons"))
mvcApp.Register(db)
mvcApp.Handle(new(controllers.PersonController))
app.Listen(":8080")
}