zhihu / norm Goto Github PK
View Code? Open in Web Editor NEWAn orm library support nGQL for Golang
License: MIT License
An orm library support nGQL for Golang
License: MIT License
Could we consider a donation of the norm to Nebula-Contrib org? Thus we could have more maintainers doing governance and contributing for the norm?
@everywan what do you think?
Thanks!
BR//Wey
报错 Invalid data length
下面是debug的结果
("github.com/zhihu/norm.VModel")(3203334144) =function calls not supported by this version of Go
麻烦问下norm使用的go版本
对返回的点和边能解析成一个嵌套的结构体并返回吗?
例如
{
"school":{
"name":"xxx",
"students":[
{
"id":1,
"name":"xx1"
},
{
"id":1,
"name":"xx1"
}
}
nebula官方的客户端获取数据非常麻烦,我看norm特性里有一条Parse Nebula execute result to struct / map,这个有具体的示例么,在样例里没有这块儿的具体体现
As I tested with both nightly versions of Nebula Graph and console, the bug stated in here has been fixed in vesoft-inc/nebula-graph#1165.
Also, nebula.pool.IdleTime
has been used to clean idle connections, as you can find the usage in the tests
When I used norm to generate insert statements, it generated the wrong statement, The following code:
`
package main
import (
"fmt"
"log"
"time"
"github.com/zhihu/norm"
"github.com/zhihu/norm/constants"
"github.com/zhihu/norm/dialectors"
)
func main() {
db := newGdb()
prepare(db)
insertData(db)
}
func newGdb() *norm.DB {
dalector := dialectors.MustNewNebulaDialector(dialectors.DialectorConfig{
Addresses: []string{"127.0.0.1:9669"},
Timeout: time.Second * 5,
Space: "test_data",
Username: "root",
Password: "test",
})
db := norm.MustOpen(dalector, norm.Config{})
return db
}
func prepare(db *norm.DB) {
// 创建 tag
createSchema := "" +
"CREATE TAG IF NOT EXISTS User(id int, name string, lastTime timestamp);" +
"CREATE TAG IF NOT EXISTS Game(id int, name string, userCount int, createTime timestamp);" +
"CREATE EDGE IF NOT EXISTS play(channel string, lastTime timestamp, createTime timestamp);"
_, err := db.Execute(createSchema)
if err != nil {
log.Fatalf("exec %s error: %v", createSchema, err)
panic(err)
}
}
type VUser struct {
norm.VModel
Id int64 norm:"id"
Name string norm:"name"
LastTime int64 norm:"lastTime"
}
func (*VUser) TagName() string {
return "User"
}
func (a *VUser) GetVid() interface{} {
return fmt.Sprintf("u:%d", a.Id)
}
func insertData(db *norm.DB) {
now := time.Now().Unix()
for i := 1; i <= 10; i++ {
err := db.Debug().InsertVertex(&VUser{
VModel: norm.VModel{
Policy: constants.PolicyNothing,
},
Id: int64(i),
LastTime: now,
})
if err != nil {
panic(err)
}
}
}
`
console output:
2021/12/13 21:07:16 [INFO] connection pool is initialized successfully
2021/12/13 21:07:16 [INFO] insert vertex User(id,lastTime) values '':(1,1639400836)
2021/12/13 21:07:16 [INFO] insert vertex User(lastTime,id) values '':(1639400836,2)
2021/12/13 21:07:16 [INFO] insert vertex User(id,lastTime) values '':(3,1639400836)
2021/12/13 21:07:16 [INFO] insert vertex User(id,lastTime) values '':(4,1639400836)
2021/12/13 21:07:16 [INFO] insert vertex User(id,lastTime) values '':(5,1639400836)
2021/12/13 21:07:16 [INFO] insert vertex User(id,lastTime) values '':(6,1639400836)
2021/12/13 21:07:16 [INFO] insert vertex User(id,lastTime) values '':(7,1639400836)
2021/12/13 21:07:16 [INFO] insert vertex User(id,lastTime) values '':(8,1639400836)
2021/12/13 21:07:16 [INFO] insert vertex User(id,lastTime) values '':(9,1639400836)
2021/12/13 21:07:16 [INFO] insert vertex User(id,lastTime) values '':(10,1639400836)
Here, values '' should not appear. I think the method GetVidWithPolicy
don't be forced implement.
When I use v3, I get an error on the function norm.MustOpen
import (
"time"
"github.com/zhihu/norm/v3"
"github.com/zhihu/norm/v3/dialectors"
)
func TestNew(t *testing.T) {
dalector := dialectors.MustNewNebulaDialector(dialectors.DialectorConfig{
Addresses: []string{"127.0.0.1:9669"},
Timeout: time.Second * 5,
Space: "test",
Username: "test",
Password: "test",
})
norm.MustOpen(dalector, norm.Config{})
}
The first parameter of this function is dialectors.IDialector
which is imported from "github.com/zhihu/norm/dialectors"
Change all imports to "github.com/zhihu/norm/v3"
. i.e. with
diff --git a/internal/converts/query.go b/internal/converts/query.go
index 31214c6..b2162df 100644
--- a/internal/converts/query.go
+++ b/internal/converts/query.go
@@ -4,7 +4,7 @@ import (
"reflect"
"github.com/pkg/errors"
- "github.com/zhihu/norm/dialectors"
+ "github.com/zhihu/norm/v3/dialectors"
)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.