-
Notifications
You must be signed in to change notification settings - Fork 0
/
defs.go
executable file
·96 lines (80 loc) · 1.95 KB
/
defs.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package sqlitehench
import (
"fmt"
"strings"
"time"
"github.com/kambahr/go-collections"
)
type DBAccess struct {
driverName string
MaxIdleConns uint
MaxOpenConns uint
PRAGMA []string
ShrinkDatabaseFiles bool
//Remote IRemoteSQLite
// ShrinkWatchList keeps a list of sqlite database
// file paths that are to be shrinked in a set internval.
ShrinkWatchList []string
}
// CollectionInfo holds Grid info for use in the client javascript.
type CollectionInfo struct {
RecordCount int
TotalPages int
PageSize int
PageNo int
PositionFrom int
PositionTo int
}
type LonqQueryArgs struct {
ResultTable *collections.Table
RowsFetched int64
TotalToFetch int64
TotalPages int
PageSize int
Status string
}
const (
Err_DatabaseIsLocked = "database is locked"
Err_FileIsNotDatabase = "file is not a database"
Err_DatabaseFileNotExists = "database file does not exist"
Err_NoRowsFound = "no rows found"
)
// convertStringToTime --
// dateTimeString => 2020-06-22T10:20:38
// on error it returns: 0001-01-01T00:00:00.000Z
func (d *DBAccess) convertStringToTime(dateTimeString string) (time.Time, error) {
var s string
dateTimeString = strings.Trim(dateTimeString, " ")
if strings.Contains(dateTimeString, " ") {
// Missing T
v := strings.Split(dateTimeString, " ")
v[1] = fmt.Sprintf("T%s", v[1])
dateTimeString = strings.Join(v, "")
}
tEmpty, err := time.Parse(time.RFC3339, "0001-01-01T00:00:00.000Z")
if err != nil {
return tEmpty, err
}
s = strings.Replace(dateTimeString, " ", "T", 1)
v := strings.Split(dateTimeString, ".")
if len(v) > 1 {
z := ""
if len(v[1]) >= 4 {
z = v[1][:3]
} else {
z = "000"
}
// check again
if len(z) < 3 {
z = "000"
}
s = fmt.Sprintf("%s.%sZ", v[0], z)
} else {
s = fmt.Sprintf("%s.000Z", s)
}
t, err := time.Parse(time.RFC3339, s)
if err != nil {
return tEmpty, err
}
return t, err
}