You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
2.5 KiB
Go
108 lines
2.5 KiB
Go
package projectInsight
|
|
|
|
import (
|
|
"database/sql"
|
|
_ "github.com/go-sql-driver/mysql"
|
|
"log"
|
|
"mercury/src/util"
|
|
)
|
|
|
|
const (
|
|
InsightDatabaseName = "insight"
|
|
)
|
|
|
|
var (
|
|
insightUserMappingFunction = func(rows *sql.Rows) *InsightUser {
|
|
user := InsightUser{}
|
|
err := rows.Scan(&user.Id, &user.FirstName, &user.LastName, &user.EmailAddress)
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
return &user
|
|
}
|
|
|
|
insightTimeEntryUpdateFunction = func(s *sql.Stmt, item *InsightTimeEntry) {
|
|
_, err := s.Exec(item.ActualHours,
|
|
item.TimeEntryDate,
|
|
item.TimeEntryDescription,
|
|
item.ProjectId,
|
|
item.TaskId,
|
|
item.TimeSheetId,
|
|
item.UserId)
|
|
if err != nil {
|
|
log.Printf("%#v\n", s)
|
|
log.Panic(err)
|
|
}
|
|
}
|
|
|
|
insightUserUpdateFunction = func(s *sql.Stmt, item *InsightUser) {
|
|
_, err := s.Exec(item.Id, item.FirstName, item.LastName, item.EmailAddress)
|
|
if err != nil {
|
|
log.Printf("%#v\n", s)
|
|
log.Panic(err)
|
|
}
|
|
}
|
|
)
|
|
|
|
//<editor-fold name="InsightDBConnector">
|
|
/*======================================================================================
|
|
InsightDBConnector
|
|
======================================================================================*/
|
|
|
|
type InsightDBConnector struct {
|
|
*util.DBConnectorGeneric
|
|
}
|
|
|
|
func NewDBConnection() *InsightDBConnector {
|
|
dbGeneric := util.DBConnectorGeneric{}
|
|
return &InsightDBConnector{&dbGeneric}
|
|
}
|
|
|
|
func (c *InsightDBConnector) CreateTables() {
|
|
tableCreationScripts := []string{"create-insight-user-table.sql", "create-insight-timeEntry-table.sql"}
|
|
|
|
for _, scriptName := range tableCreationScripts {
|
|
c.ExecuteSqlScript(InsightDatabaseName, scriptName)
|
|
}
|
|
}
|
|
|
|
func (c *InsightDBConnector) UpdateTimeEntries(entries *[]*InsightTimeEntry) {
|
|
util.BulkUpdate[InsightTimeEntry](
|
|
c.DBConnectorGeneric,
|
|
InsightDatabaseName,
|
|
"update-insight-timeEntry.sql",
|
|
entries,
|
|
insightTimeEntryUpdateFunction,
|
|
)
|
|
}
|
|
|
|
func (c *InsightDBConnector) UpdateUsers(users *[]*InsightUser) {
|
|
util.BulkUpdate[InsightUser](
|
|
c.DBConnectorGeneric,
|
|
InsightDatabaseName,
|
|
"update-insight-users.sql",
|
|
users,
|
|
insightUserUpdateFunction,
|
|
)
|
|
}
|
|
|
|
func (c *InsightDBConnector) ReadUsers() *[]*InsightUser {
|
|
return util.QueryForObjects[InsightUser](
|
|
c.DBConnectorGeneric,
|
|
InsightDatabaseName,
|
|
"read-insight-allUsers.sql",
|
|
insightUserMappingFunction,
|
|
)
|
|
}
|
|
|
|
func (c *InsightDBConnector) ReadEngineerUsers() *[]*InsightUser {
|
|
return util.QueryForObjects[InsightUser](
|
|
c.DBConnectorGeneric,
|
|
InsightDatabaseName,
|
|
"read-insight-engineerUsers.sql",
|
|
insightUserMappingFunction,
|
|
)
|
|
}
|
|
|
|
//</editor-fold>
|