Skip to content

Instantly share code, notes, and snippets.

@Simon-L
Created June 25, 2016 03:08
Show Gist options
  • Select an option

  • Save Simon-L/7600538c400ea050c8fbce02229b04a2 to your computer and use it in GitHub Desktop.

Select an option

Save Simon-L/7600538c400ea050c8fbce02229b04a2 to your computer and use it in GitHub Desktop.
First step at a Go frontend to Musicbrainz PostgreSQL db
package main
import (
"fmt"
"log"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
)
type Release struct {
ID int `db:"id"`
GID string `db:"gid"`
Name string `db:"name"`
ArtistID int `db:"artist_credit_id"`
ReleaseGroup int `db:"release_group"`
}
func main() {
db, err := sqlx.Open("postgres", "...")
if err != nil {
log.Fatalln(err)
}
rel := Release{}
rows, err := db.Queryx(`SELECT release.id, release.gid, release.name, release.artist_credit AS artist_credit_id,
release.release_group FROM release
WHERE gid = any('{"6a52e0ec-80c3-4d76-85c2-a759ccf6e9ce"}')`)
if err != nil {
log.Fatalln(err)
}
for rows.Next() {
err := rows.StructScan(&rel)
if err != nil {
log.Fatalln(err)
}
fmt.Printf("%#v\n", rel)
}
}
main.Release{ID:1059919, GID:"6a52e0ec-80c3-4d76-85c2-a759ccf6e9ce", Name:"3D", ArtistID:384446, ReleaseGroup:1083136}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment