Example #1
0
func CreateNewConnection(specialLabel ...string) Connection {
	log.Println("Trying to connect database...")
	//http://your_user:[email protected]/db/data/
	//	dbpath := "http://*****:*****@localhost:7474/db/data"
	dbpath := "http://*****:*****@localhost:7474/db/data"
	db, err := neoism.Connect(dbpath)
	utils.HandleError(err)

	c := NewConnectionNeo(dbpath, db, specialLabel...)
	return Connection(&c)

}
Example #2
0
func (c ConnectionNeoImpl) FindSongsByArtist(artistName string) []Song {
	songs := []Song{}
	cq := neoism.CypherQuery{
		//		 Use backticks for long statements - Cypher is whitespace indifferent
		Statement: `
        MATCH (song:Song)
        WHERE song.artist={name}
        RETURN song.title as title, song.artist as artist, song.id as id`,
		Parameters: neoism.Props{"name": artistName},
		Result:     &songs,
	}
	err := c.db.Cypher(&cq)
	utils.HandleError(err)
	utils.LOG.Info("Found %d songs", len(songs))
	return songs
}
Example #3
0
func (c ConnectionNeoImpl) FindAlbums(artist Artist) []Album {

	album := make([]Album, 0, 50)
	cq := neoism.CypherQuery{
		// Use backticks for long statements - Cypher is whitespace indifferent
		Statement: `
        MATCH (artist)-[:alb]->(album)
        WHERE artist.name={name}
        RETURN album`,
		Parameters: neoism.Props{"name": artist.Name, "rel": ARTIST_ALBUM_ARROW},
		Result:     &album,
	}
	err := c.db.Cypher(&cq)
	utils.HandleError(err)
	utils.LOG.Info("Album : ", album)
	return album
}
Example #4
0
func (c ConnectionNeoImpl) findArtistById(id string) Artist {
	utils.LOG.Info("Looking for artist id:" + id)

	artistsDb := make([]Artist, 0, 100)

	cq := neoism.CypherQuery{
		Statement:  "MATCH artist WHERE id={id} RETURN artist LIMIT 100",
		Parameters: neoism.Props{"id": id},
		Result:     &artistsDb,
	}
	err := c.db.Cypher(&cq)
	utils.HandleError(err)
	utils.LOG.Info("Result size : ", len(artistsDb), " Result : ", artistsDb)
	if len(artistsDb) != 0 {
		return artistsDb[0]
	}
	return Artist{}
	//[]Artist{"", "", "", nil, ""}
}
Example #5
0
func (c ConnectionNeoImpl) ClearDbPerLabel(label string) {
	var query string
	query = `MATCH (n:` + label + `) DELETE n`
	//	query = `MATCH (n:` + label + `) RETURN  count(*) as count`
	//	res := struct {
	//		Count string `json:"count"`
	//	}{}

	cq := neoism.CypherQuery{
		// Use backticks for long statements - Cypher is whitespace indifferent
		Statement:  query,
		Parameters: neoism.Props{"label": label},
		// Result:     &res,
		Result: nil,
	}
	err := c.db.Cypher(&cq)
	//	utils.LOG.Debug("Found %s", res)
	utils.HandleError(err)
}
Example #6
0
func (c ConnectionNeoImpl) FindArtists(name string) []Artist {
	utils.LOG.Info("Looking for artist name:" + name)
	artists := make([]Artist, 0, 100)
	// query results
	res := []Artist{}

	cq := neoism.CypherQuery{
		Statement: `
		MATCH (artist:Artist)
		WHERE artist.Name={name}
		RETURN artist
		`,
		Parameters: neoism.Props{"name": name},
		Result:     &res,
	}
	err := c.db.Cypher(&cq)

	utils.HandleError(err)
	utils.LOG.Info("Res len", len(res))
	utils.LOG.Info("Res", res)
	utils.LOG.Info("Result size : ", len(artists), " Result : ", artists)
	return artists
}