-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.go
More file actions
41 lines (35 loc) · 889 Bytes
/
database.go
File metadata and controls
41 lines (35 loc) · 889 Bytes
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
package libgorion
import (
"database/sql"
"time"
)
// Datastore methods
type Datastore interface {
AddWorker(string) error
DeleteWorker(string) error
DisableWorkerCard(string) error
EnableWorkerCard(string) error
Company() ([]*Company, error)
Doors() ([]*Door, error)
Workers(string) ([]*Worker, error)
Events(string, string, string, uint, bool) ([]*Event, error)
EventsValues() ([]*Event, error)
EventsTail(time.Duration, string) error
WorkedTime(string, string, string, string) ([]*Event, error)
}
// Database structure used as receiver in methods
type Database struct {
*sql.DB
}
// OpenDB opening connecting to server
// return pointer to struct DB and error
func OpenDB(dsn string) (*Database, error) {
db, err := sql.Open("mssql", dsn)
if err != nil {
return nil, err
}
if err = db.Ping(); err != nil {
return nil, err
}
return &Database{DB: db}, nil
}