gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit43b564db43b564dbMerge branch 'records-1124b' into mainJukebox43b564db/lib/db.hl

3.4 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 = (String id) => { return songsTable.fetch(id) }
  19. // Reads preserve the database iterator, index ordering and empty-result semantics.
  20. static allSongs = () => { return songsTable.iterate(null, null) }
  21. static songsInOrder = (String field) => { return songsTable.range(field, null, null) }
  22. static songsMatching = (String field, String value) => { return songsTable.find(field, value) }
  23. // the record is built field by field by the caller (hybriel#23: put() keeps an id the object carries)
  24. static addSong = (Hybrid rec) => { return songsTable.put(rec) }
  25. static replaceSong = (String id, Hybrid rec) => { return songsTable.update(id, rec) }
  26. static removeSong = (String id) => { return songsTable.delete(id) }
  27. static songCount = () => { return songsTable.count() }
  28. static countOfRows = (rows) => {
  29. if (rows == null) { return 0 }
  30. n = rows.length
  31. return n == null ? 0 : n
  32. }
  33. // ---- covers ------------------------------------------------------------------------------------------------
  34. static coverByHash = (hash) => { return coversTable.fetch(hash) }
  35. static addCover = (hash, ext, mime, size) => { return coversTable.put({ hash = hash ext = ext mime = mime size = size }) }
  36. static coverCount = () => { return coversTable.count() }
  37. // ---- scans -------------------------------------------------------------------------------------------------
  38. static addScan = (rec) => { return scansTable.put(rec) }
  39. static lastScan = () => {
  40. rows = scansTable.range('at', null, null)
  41. n = countOfRows(rows)
  42. return n > 0 ? rows[n - 1] : null
  43. }

Branches

Latest commits

  • 43b564dbMerge branch 'records-1124b' into mainJukebox
  • fa86b08c|||PR Records 2026-11-24: LOG, STATUS, missions 020-023mre
  • 0a2ae3daMerge remote-tracking branch 'origin/records-1123' into records-1124mre
  • 9a48cfcaMerge branch 'vendor-theme' into mainJukebox
  • 170d3735Merge branch 'code-order-2' into mainJukebox
  • 3f1918a7|||PR Re-sync layouts theme 4099e64 with Segoe UI firstmre
  • 2e7f6a43Vendor virtual-list 489afcf from components.hybrielmre
  • 0ba85799Merge branch 'reset-classes' into mainJukebox
  • 502eeed5jukebox#20: vendor virtual-list initial resetKey baseline fixmre
  • 6d5ce287|||PR jukebox#9 Centralize songs table reads and writes in db.hlmre
  • dcca21abjukebox#8 Move copies and queue logic into their topicsmre
  • 3b76651cjukebox#20: update virtual-list README pin and resetKey optionsmre
  • bc09e1e8|||PR jukebox#20: reset virtual lists through resetKey (partial validation)mre
  • a3796dc5Records: live step waits for idlemre
  • 3b158e16Records: merges of #9 and #11mre
  • 27204167Merge main into records-1123mre
  • 10f8a8c8Merge branch 'code-order' into mainJukebox
  • 204fc828Merge branch 'day72' into mainJukebox
  • 8e8d0e2b|||PR Records: PROCEDURES.md, missions 016-019, GO 2026-11-23mre
  • 95f5faae|||PR jukebox#7 Drop needless let declarationsmre