From 59b0851e5df743206a5cd03047560535effd61ae Mon Sep 17 00:00:00 2001 From: huangsimin Date: Fri, 6 Mar 2020 18:34:43 +0800 Subject: [PATCH] json to table --- .gitignore | 1 + go.mod | 3 +++ go.sum | 10 ++++++++++ rocksdb.go | 5 ++--- table_struct_test.go | 17 +++++++++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 table_struct_test.go diff --git a/.gitignore b/.gitignore index cf1eb91..12fb050 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ main *.log log goproto +.rocksdb diff --git a/go.mod b/go.mod index edac122..9e65921 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,9 @@ go 1.14 require ( github.com/golang/protobuf v1.3.4 + github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c + github.com/tidwall/gjson v1.6.0 + github.com/tidwall/pretty v1.0.1 // indirect golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect golang.org/x/text v0.3.2 // indirect diff --git a/go.sum b/go.sum index d667ee6..bda8719 100644 --- a/go.sum +++ b/go.sum @@ -16,6 +16,16 @@ github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaW github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzHWCjJB1zZfXPIAaDpzXIEJ0eS6B5Ok= +github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= +github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc= +github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= +github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc= +github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= +github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/tidwall/pretty v1.0.1 h1:WE4RBSZ1x6McVVC8S/Md+Qse8YUv6HRObAx6ke00NY8= +github.com/tidwall/pretty v1.0.1/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/rocksdb.go b/rocksdb.go index 55503aa..8c5f925 100644 --- a/rocksdb.go +++ b/rocksdb.go @@ -4,7 +4,6 @@ import ( "fmt" "log" "os" - "sync/atomic" "time" "github.com/tecbot/gorocksdb" @@ -78,8 +77,8 @@ type Table struct { func CreateTable(name string, field []*Field) { if _, ok := EDB.TableDict[name]; !ok { - ntid := atomic.AddUint32(&EDB.Metadata.tidCount, 1) - table := &Table{Name: name, ID: ntid, Type: 1} + // ntid := atomic.AddUint32(&EDB.Metadata.tidCount, 1) + // table := &Table{Name: name, ID: ntid, Type: 1} } else { log.Println("table name is exists") } diff --git a/table_struct_test.go b/table_struct_test.go new file mode 100644 index 0000000..99bbd0b --- /dev/null +++ b/table_struct_test.go @@ -0,0 +1,17 @@ +package main + +import ( + "testing" + + "github.com/tidwall/gjson" +) + +func TestGjson(t *testing.T) { + // "{"name": {""}}" + content := `{"name":{"first":"int ","last":"Prichard"},"age": (47)}` + r := gjson.Parse(content) + r.ForEach(func(k, v gjson.Result) bool { + t.Error(k, v.Raw) + return true + }) +}