aboutsummaryrefslogtreecommitdiff
path: root/server/database/people.go
blob: 01cbba888801824e9efe2632dae13a3c2c13a11f (plain)
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
/*
 * 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"
)
type Person struct {
  ID    int
  Name  string
  Phone string
  Email string
}

func GetAllPeople() []Person {
  var allPeople []Person
  rows, _ := myDatabase.Query(
    `SELECT id, Name, Phone, Email FROM People`,
  )

  var (
    name, phone, email string
    id int
  )

  for rows.Next() {
    rows.Scan(&id, &name, &phone, &email)
    allPeople = append(allPeople, Person{id, name, phone, email})
  }

  return allPeople
}

func RegisterPerson(person Person) bool {

  register_person, _ := myDatabase.Prepare(
    `INSERT INTO People
    (Name, Phone, Email)
    VALUES (?, ?, ?)`,
  )

  register_person.Exec(
    person.Name, person.Phone, person.Email,
  )

  return true
}