本文整理匯總了Golang中github.com/jmcvetta/neoism.Database類的典型用法代碼示例。如果您正苦於以下問題:Golang Database類的具體用法?Golang Database怎麽用?Golang Database使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Database類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
}
}
}
示例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: 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
}
示例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
}
示例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)
}
}
示例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: 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
}
示例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
}
示例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)
}
}
示例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
}
示例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")
}
}
示例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")
}
}
示例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
}
示例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
}