gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitbf5167dabf5167dajukebox: index keys without commas (mpackdb loses them after a reopen), comma fixture and gate checksmrebf5167da/lib/db.hl

2.8 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. // scans one record per finished scan (the numbers the stats show)
  7. // Everything else asks this file; switching the mpackdb version (README "mpackdb version") means looking only here.
  8. import { MPackDB } from 'hl:mpackdb'
  9. import { storageDir } from './util.hl'
  10. static songsTable = new MPackDB(file = storageDir + '/songs.db', primaryKey = '@id', indexes = ['albumKey', 'artistKey', 'sortArtist', 'sortAlbum', 'sortTitle', 'playCount'])
  11. static albumsTable = new MPackDB(file = storageDir + '/albums.db', primaryKey = 'id', indexes = ['!key', 'artistKey', 'sortName'])
  12. static artistsTable = new MPackDB(file = storageDir + '/artists.db', primaryKey = 'id', indexes = ['!key', 'sortName'])
  13. static coversTable = new MPackDB(file = storageDir + '/covers.db', primaryKey = 'hash')
  14. static scansTable = new MPackDB(file = storageDir + '/scans.db', primaryKey = '@id', indexes = ['at'])
  15. // ---- songs -------------------------------------------------------------------------------------------------
  16. static songById = (id) => { return songsTable.fetch(id) }
  17. // the record is built field by field by the caller (hybriel#23: put() keeps an id the object carries)
  18. static addSong = (rec) => { return songsTable.put(rec) }
  19. static replaceSong = (id, rec) => { return songsTable.update(id, rec) }
  20. static removeSong = (id) => { return songsTable.delete(id) }
  21. static songCount = () => { return songsTable.count() }
  22. static countOfRows = (rows) => {
  23. if (rows == null) { return 0 }
  24. n = rows.length
  25. return n == null ? 0 : n
  26. }
  27. // ---- covers ------------------------------------------------------------------------------------------------
  28. static coverByHash = (hash) => { return coversTable.fetch(hash) }
  29. static addCover = (hash, ext, mime, size) => { return coversTable.put({ hash = hash ext = ext mime = mime size = size }) }
  30. static coverCount = () => { return coversTable.count() }
  31. // ---- scans -------------------------------------------------------------------------------------------------
  32. static addScan = (rec) => { return scansTable.put(rec) }
  33. static lastScan = () => {
  34. rows = scansTable.range('at', null, null)
  35. n = countOfRows(rows)
  36. return n > 0 ? rows[n - 1] : null
  37. }

Branches

Latest commits

  • bf5167dajukebox: index keys without commas (mpackdb loses them after a reopen), comma fixture and gate checksmre
  • 28a82fa2jukebox: README, STATUS, LOG, DECISIONSmre
  • d13987dfjukebox: library scanner, ID3 reader, mpackdb database and JSON API, with fixtures and a gatemre