jukebox
All repositories: gitoria
3.0 KB
// lib/db.hl — THE DATABASE: the one place that knows hl:mpackdb. Five tables in storage/mpackdb/:// 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)// 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// artists derived: primary key = a digest of the artist key; one per artist, rebuilt the same way// covers the cover cache index: primary key = the content hash, the file is storage/covers/<hash>.<ext>// 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)// scans one record per finished scan (the numbers the stats show)// Everything else asks this file; switching the mpackdb version (README "mpackdb version") means looking only here.import { MPackDB } from 'hl:mpackdb'import { storageDir } from './util.hl'static songsTable = new MPackDB(file = storageDir + '/songs.db', primaryKey = '@id', indexes = ['albumKey', 'artistKey', 'sortArtist', 'sortAlbum', 'sortTitle', 'playCount'])static albumsTable = new MPackDB(file = storageDir + '/albums.db', primaryKey = 'id', indexes = ['!key', 'artistKey', 'sortName'])static artistsTable = new MPackDB(file = storageDir + '/artists.db', primaryKey = 'id', indexes = ['!key', 'sortName'])static coversTable = new MPackDB(file = storageDir + '/covers.db', primaryKey = 'hash')static playsTable = new MPackDB(file = storageDir + '/plays.db', primaryKey = 'id')static scansTable = new MPackDB(file = storageDir + '/scans.db', primaryKey = '@id', indexes = ['at'])// ---- songs -------------------------------------------------------------------------------------------------static songById = (id) => { return songsTable.fetch(id) }// the record is built field by field by the caller (hybriel#23: put() keeps an id the object carries)static addSong = (rec) => { return songsTable.put(rec) }static replaceSong = (id, rec) => { return songsTable.update(id, rec) }static removeSong = (id) => { return songsTable.delete(id) }static songCount = () => { return songsTable.count() }static countOfRows = (rows) => {if (rows == null) { return 0 }n = rows.lengthreturn n == null ? 0 : n}// ---- covers ------------------------------------------------------------------------------------------------static coverByHash = (hash) => { return coversTable.fetch(hash) }static addCover = (hash, ext, mime, size) => { return coversTable.put({ hash = hash ext = ext mime = mime size = size }) }static coverCount = () => { return coversTable.count() }// ---- scans -------------------------------------------------------------------------------------------------static addScan = (rec) => { return scansTable.put(rec) }static lastScan = () => {rows = scansTable.range('at', null, null)n = countOfRows(rows)return n > 0 ? rows[n - 1] : null}
Branches
Latest commits
- d105d8a9Records: mpackdb integrity check cleanmre
- 6e980c53Records: mpackdb rule refinementmre
- 6d335ac4Records: storage copy rulingmre
- 7eb2898dRecords: mpackdb second-opener rule until day38mre
- b011f98eRecords: style form live on day35mre
- 60d90cb2Records: L1 woken for the restartmre
- 75ae544fRecords: restart waits for the connection to closemre
- e0b75951Records: L1 merged and pushed, restart waits for an open connectionmre
- f2b5db98styles: format styles with nested rules and bare queriesmre
- f036bab4search: format styles with nested rules and bare queriesmre
- ef9a9d4asongs: format styles with nested rules and bare queriesmre
- f22f9aacmain: format styles with nested rules and bare queriesmre
- f56cd7c7Sync icons from 8176eb1 and verify mixed component sourcesmre
- d56e5054Sync theme and shared tokens from layouts 17e0f03mre
- b1362547Re-vendor to Hybriel set day35mre
- 89e10f08Records: mission 002 rollback wordingmre
- 9485dee7Records: mission 002 brief (live step)mre
- 9ba68fe7Records: S1b reviewedmre
- 193dfff1Records: S1 result, S1b startedmre
- 028ed776Records: mission 001 continuation S1bmre