-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQLLiteQueryResult.go
70 lines (53 loc) · 1.47 KB
/
SQLLiteQueryResult.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
package SQLL
import (
//"database/sql"
_ "github.com/mattn/go-sqlite3"
per "github.com/eshu0/persist/pkg/interfaces"
)
type SQLLiteQueryResult struct {
per.IQueryResult `json:"-"`
Results []per.IDataItem `json:"results,omitempty"`
Result per.IDataItem `json:"result,omitempty"`
RowsAffected int64 `json:"rowsaffected,omitempty"`
LastInsertId int64 `json:"lastinserti,omitempty"`
Succeeded bool `json:"succeeded,omitempty"`
ErrorData error `json:"errordata,omitempty"`
}
func ResultToSQLLiteQueryResult(data per.IQuery) SQLLiteQueryResult {
res := data.(SQLLiteQueryResult)
return res
}
func NewDataQueryResult(succes bool, items []per.IDataItem) SQLLiteQueryResult {
res := SQLLiteQueryResult{}
res.Succeeded = succes
res.Results = items
return res
}
func NewRowsAffectedQueryResult(val int64) SQLLiteQueryResult {
res := SQLLiteQueryResult{}
res.Succeeded = val >= 0
res.RowsAffected = val
return res
}
func NewInsertRowsQueryResult(val int64) SQLLiteQueryResult {
res := SQLLiteQueryResult{}
res.Succeeded = val >= 0
res.LastInsertId = val
return res
}
func NewEmptyFailedSQLLiteQueryResult() SQLLiteQueryResult {
res := SQLLiteQueryResult{}
res.Succeeded =false
return res
}
func NewEmptySucceedSQLLiteQueryResult() SQLLiteQueryResult {
res := SQLLiteQueryResult{}
res.Succeeded =true
return res
}
func (res SQLLiteQueryResult) QuerySucceeded() bool{
return res.Succeeded
}
func (res SQLLiteQueryResult) Error() error {
return res.ErrorData
}