本文整理匯總了Golang中github.com/jmcvetta/neoism.Database.Cypher方法的典型用法代碼示例。如果您正苦於以下問題:Golang Database.Cypher方法的具體用法?Golang Database.Cypher怎麽用?Golang Database.Cypher使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/jmcvetta/neoism.Database
的用法示例。
在下文中一共展示了Database.Cypher方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例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)
}
}
}
}
示例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)
}
}
示例4: 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)
}
}
}
示例5: 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
}
示例6: 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
}
示例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)
}
}
}
示例8: 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
}
示例9: 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
}
示例10: 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
}
示例11: 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)
}
示例12: 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)
}
}
示例13: GetNewsItem
/*
GetNewsItem returns the new with that id
*/
func GetNewsItem(db *neoism.Database, id int) (*NewsItem, error) {
var news []NewsItem
if err := db.Cypher(&neoism.CypherQuery{
Statement: `MATCH (new:NewsItem)<-[r]-(k:NewsProvider)
WHERE ID(new) = {id}
RETURN DISTINCT ID(new) as id, new.title as title, new.url as url,new.image as image, new.body as body, new.language as language, k.name as source`,
Parameters: neoism.Props{"id": id},
Result: &news,
}); err != nil {
return nil, err
} else if len(news) == 0 {
return nil, errors.New("not found")
} else {
return &news[0], nil
}
}
示例14: CreateOrIncRelationship
// CreateOrIncRelationship creates a relationship or increments a property if it
// already exists
func CreateOrIncRelationship(db *neoism.Database, r *model.Relationship) error {
cq := neoism.CypherQuery{
Statement: fmt.Sprintf(
`
MATCH (a:%s), (b:%s)
WHERE a.id = {subjectId} AND b.id = {objectId}
CREATE UNIQUE (a)-[r:%s]->(b)
SET r.frequency = COALESCE(r.frequency, 0) + 1
`,
util.UpperCaseFirst(r.Subject), util.UpperCaseFirst(r.Object),
strings.ToUpper(r.Relationship),
),
Parameters: neoism.Props{
"subjectId": r.SubjectID, "objectId": r.ObjectID,
},
}
return db.Cypher(&cq)
}
示例15: cypher
func cypher(db *neoism.Database) {
cq := neoism.CypherQuery{
Statement: `
START n=node(*)
MATCH (n)-[r:outranks]->(m)
WHERE n.shirt = {color}
RETURN n.name, type(r), m.name
`,
Parameters: neoism.Props{"color": "blue"},
Result: &[]struct {
N string `json:"n.name"`
Rel string `json:"type(r)"`
M string `json:"m.name"`
}{},
}
// db.Session.Log = true
db.Cypher(&cq)
fmt.Println(cq.Result)
// &[{Spock outranks McCoy} {Spock outranks Scottie} {McCoy outranks Scottie}]
}