-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
51 lines (45 loc) · 870 Bytes
/
models.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
package main
import (
"bufio"
"encoding/csv"
"github.com/jinzhu/gorm"
"io"
"os"
)
type Expense struct {
gorm.Model
Date string
Description string
Debit string
Credit string
Balance string
}
type User struct {
gorm.Model
FirstName string
LastName string
Username string
Password string
Email string
}
type Category struct {
Description string
}
func ImportCsv(filename string) {
file, err := os.Open(filename)
CheckError(err)
r1, err := bufio.NewReader(file).ReadSlice('\n')
CheckError(err)
_, err = file.Seek(int64(len(r1)), io.SeekStart)
CheckError(err)
reader, _ := csv.NewReader(file).ReadAll()
for i := range reader {
GetDB().Create(&Expense{
Date: reader[i][1],
Description: reader[i][2],
Debit: reader[i][3],
Credit: reader[i][4],
Balance: reader[i][5],
})
}
}