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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*
* OpenBills - Self hosted browser app to generate and keep track of simple invoices
* Version - 0
* Licensed under the MIT license - https://opensource.org/licenses/MIT
*
* Copyright (c) 2021 Vidhu Kant Sharma
*/
// handles all People related database functions
package database
import (
_ "github.com/mattn/go-sqlite3"
"fmt"
)
type Person struct {
ID int
Name string
Phone string
Email string
BillAddress Address
ShipAddress Address
}
func GetAllPeople() []Person {
var allPeople []Person
rows, _ := myDatabase.Query (
`SELECT ID, Name, Phone, Email,
BillAddressLine, BillAddressCity,
BillAddressState, BillAddressPINCode,
BillAddressCountry,
ShipAddressLine,
ShipAddressCity, ShipAddressState,
ShipAddressPINCode, ShipAddressCountry
FROM People`,
)
var (
id int
name, phone, email string
billAddressLine, billAddressCity, billAddressState, billAddressPINCode, billAddressCountry string
shipAddressLine, shipAddressCity, shipAddressState, shipAddressPINCode, shipAddressCountry string
billAddress, shipAddress Address
)
for rows.Next() {
rows.Scan(
&id, &name, &phone, &email,
&billAddressLine, &billAddressCity,
&billAddressState, &billAddressPINCode,
&billAddressCountry,
&shipAddressLine, &shipAddressCity,
&shipAddressState, &shipAddressPINCode,
&shipAddressCountry,
)
billAddress = Address{billAddressLine, billAddressCity, billAddressState, billAddressPINCode, billAddressCountry}
shipAddress = Address{shipAddressLine, shipAddressCity, shipAddressState, shipAddressPINCode, shipAddressCountry}
allPeople = append(allPeople, Person{id, name, phone, email, billAddress, shipAddress})
fmt.Println(allPeople)
}
return allPeople
}
func RegisterPerson(person Person) bool {
fmt.Println(person)
register_person, _ := myDatabase.Prepare(
`INSERT INTO People
(Name, Phone, Email,
BillAddressLine, BillAddressCity,
BillAddressState, BillAddressPINCode,
BillAddressCountry,
ShipAddressLine, ShipAddressCity,
ShipAddressState, ShipAddressPINCode,
ShipAddressCountry)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
)
register_person.Exec(
person.Name, person.Phone, person.Email,
person.BillAddress.AddressLine,
person.BillAddress.City,
person.BillAddress.State,
person.BillAddress.PINCode,
person.BillAddress.Country,
person.ShipAddress.AddressLine,
person.ShipAddress.City,
person.ShipAddress.State,
person.ShipAddress.PINCode,
person.ShipAddress.Country,
)
return true
}
|