aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryenlin.lai <yenlin.lai@cobinhood.com>2019-02-25 16:16:31 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:04 +0800
commit97b7044a459f4ad881d8e8787ca8fbb238936bad (patch)
tree56bfa6c6ae464224ea6861a416a1e1684cd2799e
parent3274f055838e0bbc499a24ac58e06a4604d0a322 (diff)
downloaddexon-97b7044a459f4ad881d8e8787ca8fbb238936bad.tar
dexon-97b7044a459f4ad881d8e8787ca8fbb238936bad.tar.gz
dexon-97b7044a459f4ad881d8e8787ca8fbb238936bad.tar.bz2
dexon-97b7044a459f4ad881d8e8787ca8fbb238936bad.tar.lz
dexon-97b7044a459f4ad881d8e8787ca8fbb238936bad.tar.xz
dexon-97b7044a459f4ad881d8e8787ca8fbb238936bad.tar.zst
dexon-97b7044a459f4ad881d8e8787ca8fbb238936bad.zip
core: sqlvm: schema: define type for table/column/index/sequence size
The size of table in db and column/index/sequence in a table is bounded by uint8. Define types for better readability.
-rw-r--r--core/vm/sqlvm/schema/schema.go20
-rw-r--r--core/vm/sqlvm/schema/schema_test.go2
2 files changed, 17 insertions, 5 deletions
diff --git a/core/vm/sqlvm/schema/schema.go b/core/vm/sqlvm/schema/schema.go
index 4529fd7d5..76c843387 100644
--- a/core/vm/sqlvm/schema/schema.go
+++ b/core/vm/sqlvm/schema/schema.go
@@ -27,6 +27,18 @@ const (
ColumnAttrHasForeignKey
)
+// TableRef defines the type for table index in Schema.
+type TableRef uint8
+
+// ColumnRef defines the type for column index in Table.Columns.
+type ColumnRef uint8
+
+// IndexRef defines the type for array index of Column.Indices.
+type IndexRef uint8
+
+// SequenceRef defines the type for sequence index in Table.
+type SequenceRef uint8
+
// IndexAttr defines bit flags for describing index attribute.
type IndexAttr uint16
@@ -49,16 +61,16 @@ type Table struct {
type Index struct {
Name []byte
Attr IndexAttr
- Columns []uint8
+ Columns []ColumnRef
}
type column struct {
Name []byte
Type ast.DataType
Attr ColumnAttr
- Sequence uint8
- ForeignTable uint8
- ForeignColumn uint8
+ Sequence SequenceRef
+ ForeignTable TableRef
+ ForeignColumn ColumnRef
Rest interface{}
}
diff --git a/core/vm/sqlvm/schema/schema_test.go b/core/vm/sqlvm/schema/schema_test.go
index 92bfa6c91..5d252ef85 100644
--- a/core/vm/sqlvm/schema/schema_test.go
+++ b/core/vm/sqlvm/schema/schema_test.go
@@ -82,7 +82,7 @@ func (s *SchemaTestSuite) TestEncodeAndDecodeSchema() {
{
Name: []byte("idx"),
Attr: IndexAttrUnique,
- Columns: []uint8{0},
+ Columns: []ColumnRef{0},
},
},
},