-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquerys.go
39 lines (32 loc) · 1.38 KB
/
querys.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
package main
import (
"context"
"fmt"
)
func insertCustomer(customer Customer) (int64, error) {
result, err := conn.Exec(context.Background(), "INSERT INTO public.customers (uuid, first_name, last_name, address, phone_number, email, employer, "+
"annual_income, request_credit_amount, additional_information) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);", customer.UUID, customer.FirstName,
customer.LastName, customer.Address, customer.PhoneNumber, customer.Email, customer.Employer, customer.AnnualIncome, customer.RequestedCreditAmount, customer.AdditionalInformation)
if err != nil {
return 0, fmt.Errorf("unable to execute the query. %v", err)
}
return result.RowsAffected(), nil
}
// func fetchAllCustomers(conn *pgxpool.Pool) {
// var customers []Customer
// rows, err := conn.Query(context.Background(), "SELECT * FROM customers")
// if err != nil {
// fmt.Fprintf(os.Stderr, "QueryRow failed: %v\n", err)
// os.Exit(1)
// }
// for rows.Next() {
// var customer Customer
// err := rows.Scan(&customer.ID, &customer.UUID, &customer.FirstName, &customer.LastName, &customer.Address,
// &customer.PhoneNumber, &customer.Email, &customer.Employer, &customer.AnnualIncome, &customer.RequestedCreditAmount, &customer.AdditionalInformation)
// if err != nil {
// fmt.Println(err)
// }
// customers = append(customers, customer)
// }
// fmt.Println(customers)
// }