forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql_table.go
127 lines (112 loc) · 3.29 KB
/
sql_table.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package types
import (
"fmt"
)
// SQLTable contains the structure of a SQL table,
type SQLTable struct {
Name string
Columns []*SQLTableColumn
// Map of channel name -> columns to be sent as payload on that channel
NotifyChannels map[string][]string
columns map[string]*SQLTableColumn
}
func (table *SQLTable) GetColumn(columnName string) *SQLTableColumn {
if table.columns == nil {
table.columns = make(map[string]*SQLTableColumn, len(table.Columns))
for _, column := range table.Columns {
table.columns[column.Name] = column
}
}
return table.columns[columnName]
}
// SQLTableColumn contains the definition of a SQL table column,
// the Order is given to be able to sort the columns to be created
type SQLTableColumn struct {
Name string
Type SQLColumnType
Primary bool
Length int
}
func (col *SQLTableColumn) String() string {
primaryString := ""
if col.Primary {
primaryString = " (primary)"
}
lengthString := ""
if col.Length != 0 {
lengthString = fmt.Sprintf(" (length %d)", col.Length)
}
return fmt.Sprintf("SQLTableColumn{%s%s: %v%s}",
col.Name, primaryString, col.Type, lengthString)
}
func (col *SQLTableColumn) Equals(otherCol *SQLTableColumn) bool {
columnA := *col
columnB := *otherCol
return columnA == columnB
}
// UpsertDeleteQuery contains query and values to upsert or delete row data
type UpsertDeleteQuery struct {
Query string
Values string
Pointers []interface{}
}
// SQL log & dictionary tables
const (
SQLLogTableName = "_vent_log"
SQLDictionaryTableName = "_vent_dictionary"
SQLBlockTableName = "_vent_block"
SQLTxTableName = "_vent_tx"
SQLChainInfoTableName = "_vent_chain"
)
// fixed sql column names in tables
const (
// log
SQLColumnLabelId = "_id"
SQLColumnLabelTimeStamp = "_timestamp"
SQLColumnLabelTableName = "_tablename"
SQLColumnLabelEventName = "_eventname"
SQLColumnLabelEventFilter = "_eventfilter"
SQLColumnLabelHeight = "_height"
SQLColumnLabelTxHash = "_txhash"
SQLColumnLabelAction = "_action"
SQLColumnLabelDataRow = "_datarow"
SQLColumnLabelSqlStmt = "_sqlstmt"
SQLColumnLabelSqlValues = "_sqlvalues"
// dictionary
SQLColumnLabelColumnName = "_columnname"
SQLColumnLabelColumnType = "_columntype"
SQLColumnLabelColumnLength = "_columnlength"
SQLColumnLabelPrimaryKey = "_primarykey"
SQLColumnLabelColumnOrder = "_columnorder"
// chain info
SQLColumnLabelBurrowVer = "_burrowversion"
SQLColumnLabelChainID = "_chainid"
// context
SQLColumnLabelIndex = "_index"
SQLColumnLabelEventType = "_eventtype"
SQLColumnLabelBlockHeader = "_blockheader"
SQLColumnLabelTxType = "_txtype"
SQLColumnLabelEnvelope = "_envelope"
SQLColumnLabelEvents = "_events"
SQLColumnLabelResult = "_result"
SQLColumnLabelReceipt = "_receipt"
SQLColumnLabelException = "_exception"
)
// labels for column mapping
const (
// event related
EventNameLabel = "eventName"
EventTypeLabel = "eventType"
// block related
BlockHeightLabel = "height"
BlockHeaderLabel = "blockHeader"
// transaction related
TxTxTypeLabel = "txType"
TxTxHashLabel = "txHash"
TxIndexLabel = "index"
TxEnvelopeLabel = "envelope"
TxEventsLabel = "events"
TxResultLabel = "result"
TxReceiptLabel = "receipt"
TxExceptionLabel = "exception"
)