Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions postgres/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package postgres
54 changes: 54 additions & 0 deletions postgres/contact_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package postgres

import (
"github.com/jorgeastorga/contakx/contakx"
_"database/sql"
"github.com/jinzhu/gorm"
"log"
)

type ContactService struct {
AppDB *gorm.DB
}

///ContactService returns a user for a given id.
func (c *ContactService) Contact(id int) (contact contakx.Contact, err error){
//var *contact contakx.Contact
c.AppDB.First(&contact, id)
return contact, err
}

func (c *ContactService) CreateContact(contact *contakx.Contact) error {
err := c.AppDB.Create(&contakx.Contact{
FirstName:contact.FirstName,
LastName: contact.LastName,
Address1: contact.Address1,
Address2: contact.Address2,
City: contact.City,
State: contact.State,
ZipCode: contact.ZipCode,
Company: contact.Company,
Email: contact.Email,
Phone: contact.Phone}).Error

if err != nil {
log.Println("Error creating the contact: ", err.Error())
}

return err
}

func (c *ContactService)OpenDB(dbConnection string){
//Database Connection Setup: PostgreSQL
var err error
c.AppDB, err = gorm.Open("postgres", dbConnection)

if err != nil{
log.Println("Failed to connect to the database", err.Error())
} else {
log.Println("DB Connection: connected to the database successfully")
}

}


1 change: 1 addition & 0 deletions postgres/session.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package postgres