本文整理汇总了Golang中github.com/jmcvetta/neoism.Database类的典型用法代码示例。如果您正苦于以下问题:Golang Database类的具体用法?Golang Database怎么用?Golang Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Database类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: joined
// Create user node and "IS_IN" edge to room if non-existent.
func joined(msg *irc.Message, DB *neoism.Database) {
room := msg.Params[0]
user := cleanName(msg.Prefix.Name)
if users[user] == nil {
users[user] = []string{room}
}
contains := false
for _, r := range users[user] {
if r == room {
contains = true
break
}
}
if contains != true {
users[user] = append(users[user], room)
statement := fmt.Sprintf(
`MERGE (n:Room {name: "%v"})
MERGE (u:User {name: "%v"})
MERGE (n)<-[:IS_IN]-(u)`,
room, user)
// Create new room node if non-existent
query := neoism.CypherQuery{
Statement: statement,
}
err := DB.Cypher(&query)
if err != nil {
fmt.Println(err)
}
}
}
开发者ID:MDCox,项目名称:spectator,代码行数:36,代码来源:store.go
示例2: messaged
// Check if reference to a person associated with that room.
// If it is, create a "REFERENCED" edge between speaker and
// the reference. If that edge already exists, increment
// the "times" property by 1.
func messaged(msg *irc.Message, DB *neoism.Database) {
message := msg.Trailing
for name, _ := range users {
if strings.Contains(message, name) {
speaker := cleanName(msg.Prefix.Name)
reference := name
fmt.Printf("%v was referenced by %v\n", speaker, reference)
statement := fmt.Sprintf(
`MERGE (s:User {name: "%v"})
MERGE (u:User {name: "%v"})
MERGE (s)-[r:REFERENCED]->(u)
ON MATCH SET r.times = coalesce(r.times, 0) + 1`, speaker, reference)
query := neoism.CypherQuery{
Statement: statement,
}
err := DB.Cypher(&query)
if err != nil {
fmt.Println(err)
}
}
}
}
开发者ID:MDCox,项目名称:spectator,代码行数:29,代码来源:store.go
示例3: InsertUID
func InsertUID(conn *neoism.Database, key *puck_gpg.PrimaryKey, uid *puck_gpg.UserID) {
kid := key.KeyID()
app.Logger.Debugf("Inserting UID %s of %s", uid.Keywords, kid)
parsed := parseUID(uid.Keywords)
cq0 := neoism.CypherQuery{
Statement: `
MATCH
(k:Key {keyid: {keyid}})
MERGE k-[r:HasID]-(i:UserID {
keyword: {keyword},
uuid: {uuid},
name: {name},
comment: {comment},
email: {email},
domain: {domain}
})`,
Parameters: neoism.Props{
"keyid": key.KeyID(),
"keyword": uid.Keywords,
"uuid": uid.UUID,
"name": parsed.name,
"comment": parsed.comment,
"email": parsed.email,
"domain": parsed.domain,
},
}
err := conn.Cypher(&cq0)
if err != nil {
panic(err)
}
}
开发者ID:squeed,项目名称:gpg2graph,代码行数:34,代码来源:db.go
示例4: getFrequencyRelations
func getFrequencyRelations(db *neoism.Database, r *model.Relationship, t *testing.T) int {
res := []struct {
Frequency int `json:"frequency"`
}{}
cq := neoism.CypherQuery{
Statement: fmt.Sprintf(
`
MATCH (subject:%[1]s)-[r:%[2]s]->(object:%[3]s)
WHERE subject.id = {subjectId} AND object.id = {objectId}
RETURN r.frequency as frequency
`,
util.UpperCaseFirst(r.Subject), strings.ToUpper(r.Relationship),
util.UpperCaseFirst(r.Object),
),
Parameters: neoism.Props{"subjectId": r.SubjectID, "objectId": r.ObjectID},
Result: &res,
}
if err := db.Cypher(&cq); err != nil {
assert.Fail(t, "Unexpected error: "+err.Error())
return -1
}
if len(res) > 0 {
return res[0].Frequency
}
return -1
}
开发者ID:halk,项目名称:in-common,代码行数:28,代码来源:db_test.go
示例5: GetOrCreateNode
// GetOrCreateNode returns a Node, creates one if it does not exist. This method
// overrides the neoism one as there is a bug
func GetOrCreateNode(db *neoism.Database, label, key string, p neoism.Props) (n *neoism.Node, created bool, err error) {
node, created, err := db.GetOrCreateNode(util.UpperCaseFirst(label), key, p)
// due to a bug in neoism, label is not added
// see: https://github.com/jmcvetta/neoism/issues/62
if created {
node.AddLabel(util.UpperCaseFirst(label))
}
return node, created, err
}
开发者ID:halk,项目名称:in-common,代码行数:11,代码来源:db.go
示例6: cleanupConstraints
func cleanupConstraints(t *testing.T, db *neoism.Database) {
err := db.CypherBatch([]*neoism.CypherQuery{
&neoism.CypherQuery{
Statement: `DROP CONSTRAINT ON (x:NeoUtilsTest) ASSERT x.name IS UNIQUE`,
},
})
if err != nil {
t.Fatal(err)
}
}
开发者ID:Financial-Times,项目名称:neo-utils-go,代码行数:10,代码来源:neoutils_test.go
示例7: doQueries
func doQueries(conn *neoism.Database, queries []string) {
for _, s := range queries {
q := neoism.CypherQuery{
Statement: s,
}
err := conn.Cypher(&q)
if err != nil {
panic(err)
}
}
}
开发者ID:squeed,项目名称:gpg2graph,代码行数:11,代码来源:db.go
示例8: GetTags
/*
GetTags returns collection of news
*/
func GetTags(db *neoism.Database) (*[]Tag, error) {
var tags []Tag
if err := db.Cypher(&neoism.CypherQuery{
Statement: `MATCH (tag:Tag)
RETURN DISTINCT ID(tag) as id, tag.name as name`,
Result: &tags,
}); err != nil {
return nil, err
}
return &tags, nil
}
开发者ID:IIC2173-2015-2-Grupo2,项目名称:news-api,代码行数:14,代码来源:tag.go
示例9: GetNewsProviders
/*
GetNewsProviders returns collection of news
*/
func GetNewsProviders(db *neoism.Database) (*[]NewsProvider, error) {
var newsproviders []NewsProvider
if err := db.Cypher(&neoism.CypherQuery{
Statement: `MATCH (newsprovider:NewsProvider)
RETURN DISTINCT ID(newsprovider) as id, newsprovider.name as name`,
Result: &newsproviders,
}); err != nil {
return nil, err
}
return &newsproviders, nil
}
开发者ID:IIC2173-2015-2-Grupo2,项目名称:news-api,代码行数:14,代码来源:news-provider.go
示例10: cleanup
func cleanup(t *testing.T, db *neoism.Database) {
err := db.CypherBatch([]*neoism.CypherQuery{
&neoism.CypherQuery{
Statement: `MATCH (x:NeoUtilsTest) DETACH DELETE x`,
},
})
if err != nil {
t.Fatal(err)
}
}
开发者ID:Financial-Times,项目名称:neo-utils-go,代码行数:11,代码来源:neoutils_test.go
示例11: GetLocations
/*
GetLocations returns collection of news
*/
func GetLocations(db *neoism.Database) (*[]Location, error) {
var locations []Location
if err := db.Cypher(&neoism.CypherQuery{
Statement: `MATCH (location:Location)
RETURN DISTINCT ID(location) as id, location.name as name`,
Result: &locations,
}); err != nil {
return nil, err
}
return &locations, nil
}
开发者ID:IIC2173-2015-2-Grupo2,项目名称:news-api,代码行数:14,代码来源:location.go
示例12: addIndexes
func addIndexes(conn *neoism.Database) {
_, err := conn.CreateIndex("Key", "domain")
if err != nil {
app.Logger.Info("Failed to create index, probably already exists")
}
_, err = conn.CreateIndex("Key", "email")
if err != nil {
app.Logger.Info("Failed to create index, probably already exists")
}
}
开发者ID:squeed,项目名称:gpg2graph,代码行数:12,代码来源:db.go
示例13: addConstraints
func addConstraints(conn *neoism.Database) {
_, err := conn.CreateUniqueConstraint("Key", "keyid")
if err != nil {
app.Logger.Info("Failed to create constraint, probably already exists")
}
_, err = conn.CreateUniqueConstraint("UserID", "uuid")
if err != nil {
app.Logger.Info("Failed to create constraint, probably already exists")
}
}
开发者ID:squeed,项目名称:gpg2graph,代码行数:12,代码来源:db.go
示例14: GetCompanies
/*
GetCompanies returns collection of news
*/
func GetCompanies(db *neoism.Database) (*[]Company, error) {
var companies []Company
if err := db.Cypher(&neoism.CypherQuery{
Statement: `MATCH (company:Company)
RETURN DISTINCT ID(company) as id, company.name as name`,
Result: &companies,
}); err != nil {
return nil, err
}
return &companies, nil
}
开发者ID:IIC2173-2015-2-Grupo2,项目名称:news-api,代码行数:15,代码来源:company.go
示例15: GetPeople
/*
GetPeople returns collection of news
*/
func GetPeople(db *neoism.Database) (*[]Person, error) {
var people []Person
if err := db.Cypher(&neoism.CypherQuery{
Statement: `MATCH (person:Person)
RETURN DISTINCT ID(person) as id, person.name as name`,
Result: &people,
}); err != nil {
return nil, err
}
return &people, nil
}
开发者ID:IIC2173-2015-2-Grupo2,项目名称:news-api,代码行数:15,代码来源:person.go
示例16: cleanup
func cleanup(db *neoism.Database) {
qs := []*neoism.CypherQuery{
&neoism.CypherQuery{
Statement: `START r=rel(*) DELETE r`,
},
&neoism.CypherQuery{
Statement: `START n=node(*) DELETE n`,
},
}
err := db.CypherBatch(qs)
if err != nil {
log.Fatal(err)
}
}
开发者ID:zombor,项目名称:neoism,代码行数:14,代码来源:presentation.go
示例17: create
func create(db *neoism.Database) {
kirk, err := db.CreateNode(neoism.Props{"name": "Kirk", "shirt": "yellow"})
if err != nil {
log.Fatal(err)
}
fmt.Println(kirk.Properties()) // map[shirt:yellow name:Kirk] <nil>
// Ignoring subsequent errors for brevity
spock, _ := db.CreateNode(neoism.Props{"name": "Spock", "shirt": "blue"})
mccoy, _ := db.CreateNode(neoism.Props{"name": "McCoy", "shirt": "blue"})
r, _ := kirk.Relate("outranks", spock.Id(), nil) // No properties on this relationship
start, _ := r.Start()
fmt.Println(start.Properties()) // map[name:Kirk shirt:yellow] <nil>
kirk.Relate("outranks", mccoy.Id(), nil)
spock.Relate("outranks", mccoy.Id(), nil)
}
开发者ID:zombor,项目名称:neoism,代码行数:15,代码来源:presentation.go
示例18: getEntity
func (s *state) getEntity(db *neoism.Database, xid string) *neoism.Node {
p := neoism.Props{"_xid_": xid}
e, created, err := db.GetOrCreateNode("Entity", "_xid_", p)
if err != nil {
glog.Fatal(err)
}
if created {
e.AddLabel("Entity")
glog.WithFields(logrus.Fields{
"id": e.Id(),
"_xid_": xid,
}).Debug("Added new entity")
}
return e
}
开发者ID:dgraph-io,项目名称:benchmarks,代码行数:15,代码来源:loader.go
示例19: DeleteRelationship
// DeleteRelationship deletes a relationship
func DeleteRelationship(db *neoism.Database, r *model.Relationship) error {
cq := neoism.CypherQuery{
Statement: fmt.Sprintf(
`
MATCH (a:%s)-[r:%s]->(b:%s)
WHERE a.id = {subjectId} AND b.id = {objectId}
DELETE r
`,
util.UpperCaseFirst(r.Subject), strings.ToUpper(r.Relationship),
util.UpperCaseFirst(r.Object),
),
Parameters: neoism.Props{
"subjectId": r.SubjectID, "objectId": r.ObjectID,
},
}
return db.Cypher(&cq)
}
开发者ID:halk,项目名称:in-common,代码行数:18,代码来源:db.go
示例20: InsertPubKey
func InsertPubKey(conn *neoism.Database, k *puck_gpg.PrimaryKey) {
cq0 := neoism.CypherQuery{
Statement: `
MERGE (n:Key {keyid: {keyid}})
ON CREATE SET
n.fingerprint = {fingerprint}
ON MATCH SET
n.fingerprint = {fingerprint};`,
Parameters: neoism.Props{
"keyid": k.KeyID(),
"fingerprint": k.Fingerprint()}}
err := conn.Cypher(&cq0)
if err != nil {
panic(err)
}
}
开发者ID:squeed,项目名称:gpg2graph,代码行数:18,代码来源:db.go
注:本文中的github.com/jmcvetta/neoism.Database类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论