A website inspired by Last.fm that will keep track of your listening statistics
lastfm music statistics
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Make attaching multiple databases easier with helper, and do so for musicbrainz and app database.

oscar345 18c92c61 deff0bd6

+25 -3
+7 -3
internal/server/server.go
··· 35 35 } 36 36 37 37 func (s *Server) Start() error { 38 - musicbrainzDB := database.Open("sqlite3", s.config.MusicbrainzDatabase.Path, func(db *sql.DB) { 38 + generalDB := database.Open("sqlite3", s.config.MusicbrainzDatabase.Path, func(db *sql.DB) { 39 39 db.Exec("PRAGMA journal_mode = WAL") 40 40 db.Exec("PRAGMA synchronous = NORMAL") 41 41 }) 42 - defer musicbrainzDB.Close() 42 + defer generalDB.Close() 43 + 44 + database.AddAttachments(generalDB, map[string]string{ 45 + "app": s.config.AppDatabase.Path, 46 + }) 43 47 44 48 statisticsDB := database.Open("duckdb", s.config.StatisticsDatabase.Path, func(d *sql.DB) { 45 49 d.Exec("SET threads TO 4") 46 50 }) 47 51 defer statisticsDB.Close() 48 52 49 - services := s.services(musicbrainzDB, statisticsDB) 53 + services := s.services(generalDB, statisticsDB) 50 54 51 55 inertia := setupInertia() 52 56
+18
pkg/database/connection.go
··· 22 22 return db 23 23 } 24 24 25 + func AddAttachments(db *sql.DB, attachments map[string]string) error { 26 + for name, dbPath := range attachments { 27 + fullpath, err := filepath.Abs(dbPath) 28 + 29 + if err != nil { 30 + return err 31 + } 32 + 33 + _, err = db.Exec(fmt.Sprintf("ATTACH DATABASE '%s' AS %s", fullpath, name)) 34 + 35 + if err != nil { 36 + return err 37 + } 38 + } 39 + 40 + return nil 41 + } 42 + 25 43 // For this application, we use multiple database that do have to interact with each other. This 26 44 // function opens the databases with correct names and paths to the database. The databases will be 27 45 // opened with WAL mode and normal synchronous mode.