aboutsummaryrefslogtreecommitdiff
path: root/server/database/people.go
diff options
context:
space:
mode:
authorMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-08-08 16:11:08 +0530
committerMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-08-08 16:11:08 +0530
commit8c906c98b2a2994286731357831ca8005ef0d73f (patch)
treefd4f7a283e230d149099fe285ae7a56cda237e64 /server/database/people.go
parent0f0e5f7408969fcc4473746919bb0e8aaa89947c (diff)
Added better support for saving client data
Diffstat (limited to 'server/database/people.go')
-rw-r--r--server/database/people.go70
1 files changed, 59 insertions, 11 deletions
diff --git a/server/database/people.go b/server/database/people.go
index 25aa393..f0b05b8 100644
--- a/server/database/people.go
+++ b/server/database/people.go
@@ -4,13 +4,14 @@
* Licensed under the MIT license - https://opensource.org/licenses/MIT
*
* Copyright (c) 2021 Vidhu Kant Sharma
-*/
+ */
// handles all People related database functions
-package database
+package database
import (
- _ "github.com/mattn/go-sqlite3"
+ _ "github.com/mattn/go-sqlite3"
+ "fmt"
)
@@ -22,38 +23,85 @@ type Person struct {
Email string
BillAddress Address
ShipAddress Address
- GSTIN string
}
func GetAllPeople() []Person {
var allPeople []Person
rows, _ := myDatabase.Query (
- `SELECT ID, Name, Phone, Email, BillAddress, ShipAddress, GSTIN FROM People`,
+ `SELECT ID, Name, Phone, Email,
+
+ BillAddressLine, BillAddressCity,
+ BillAddressState, BillAddressPINCode,
+ BillAddressCountry,
+
+ ShipAddressLine,
+ ShipAddressCity, ShipAddressState,
+ ShipAddressPINCode, ShipAddressCountry
+
+ FROM People`,
)
var (
id int
- name, phone, email, gstin string
+ 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, &billAddress, &shipAddress, &gstin)
- allPeople = append(allPeople, Person{id, name, phone, email, billAddress, shipAddress, gstin})
+ 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, BillAddress, ShipAddress, GSTIN)
- VALUES (?, ?, ?, ?, ?, ?)`,
+ (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, person.ShipAddress, person.GSTIN,
+ 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