gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitc5dbf2ecc5dbf2ecRecords: R2 resultmrec5dbf2ec/lib/db.hl

3.0 KB

  1. // lib/db.hl — THE DATABASE: the one place that knows hl:mpackdb. Five tables in storage/mpackdb/:
  2. // songs one record per file (lib/tags.hl songFrom) — primary key '@id'; path and folder are NOT indexed (the scanner keeps its own path map; an index key may hold no comma, see lib/util.hl safeKey)
  3. // albums derived: primary key = a digest of the albumKey (stable across rebuilds); one per albumKey (artist + album name + folder), rebuilt by lib/library.hl after a scan that changed anything
  4. // artists derived: primary key = a digest of the artist key; one per artist, rebuilt the same way
  5. // covers the cover cache index: primary key = the content hash, the file is storage/covers/<hash>.<ext>
  6. // plays the jukebox's OWN play counter per song id: { id, count, at } (the file's POPM count stays the starting value and is never written back)
  7. // scans one record per finished scan (the numbers the stats show)
  8. // Everything else asks this file; switching the mpackdb version (README "mpackdb version") means looking only here.
  9. import { MPackDB } from 'hl:mpackdb'
  10. import { storageDir } from './util.hl'
  11. static songsTable = new MPackDB(file = storageDir + '/songs.db', primaryKey = '@id', indexes = ['albumKey', 'artistKey', 'sortArtist', 'sortAlbum', 'sortTitle', 'playCount'])
  12. static albumsTable = new MPackDB(file = storageDir + '/albums.db', primaryKey = 'id', indexes = ['!key', 'artistKey', 'sortName'])
  13. static artistsTable = new MPackDB(file = storageDir + '/artists.db', primaryKey = 'id', indexes = ['!key', 'sortName'])
  14. static coversTable = new MPackDB(file = storageDir + '/covers.db', primaryKey = 'hash')
  15. static playsTable = new MPackDB(file = storageDir + '/plays.db', primaryKey = 'id')
  16. static scansTable = new MPackDB(file = storageDir + '/scans.db', primaryKey = '@id', indexes = ['at'])
  17. // ---- songs -------------------------------------------------------------------------------------------------
  18. static songById = (id) => { return songsTable.fetch(id) }
  19. // the record is built field by field by the caller (hybriel#23: put() keeps an id the object carries)
  20. static addSong = (rec) => { return songsTable.put(rec) }
  21. static replaceSong = (id, rec) => { return songsTable.update(id, rec) }
  22. static removeSong = (id) => { return songsTable.delete(id) }
  23. static songCount = () => { return songsTable.count() }
  24. static countOfRows = (rows) => {
  25. if (rows == null) { return 0 }
  26. n = rows.length
  27. return n == null ? 0 : n
  28. }
  29. // ---- covers ------------------------------------------------------------------------------------------------
  30. static coverByHash = (hash) => { return coversTable.fetch(hash) }
  31. static addCover = (hash, ext, mime, size) => { return coversTable.put({ hash = hash ext = ext mime = mime size = size }) }
  32. static coverCount = () => { return coversTable.count() }
  33. // ---- scans -------------------------------------------------------------------------------------------------
  34. static addScan = (rec) => { return scansTable.put(rec) }
  35. static lastScan = () => {
  36. rows = scansTable.range('at', null, null)
  37. n = countOfRows(rows)
  38. return n > 0 ? rows[n - 1] : null
  39. }

Branches

Latest commits

  • c5dbf2ecRecords: R2 resultmre
  • 956069b8Records: R1 result, mission 007mre
  • 3c8a2e12Mission 007: #20 sort scrollmre
  • deb8cef5Records: mission 006 startedmre
  • 4f0ad42fMission 006: jukebox#20mre
  • 800cae06Records: #21 planmre
  • 64bc7823Records: #21 causemre
  • 76639655Records: B1 questionmre
  • d7906b36Records: mission 005 startedmre
  • d3df773cMission 005: doc linemre
  • 6a5d840aMission 005: jukebox#22mre
  • 13e5e748Records: mission 004 startedmre
  • a8098271Mission 004: jukebox#21mre
  • df8f5205Records: jukebox#19-21, #11 closedmre
  • b7a4e692Records: hybriel#298mre
  • 9bcbb017Records: day38b waits for day39 fixmre
  • f80504e1Records: day38b repro sentmre
  • 8048258bRecords: day38b jb3 regression, L1 Chromes stoppedmre
  • 68aace7fRecords: mission 003 day38bmre
  • d105d8a9Records: mpackdb integrity check cleanmre