concept BigDB { S name; } concept BigEntry { new Ref db; S globalID; long fileNr, headerStart, start, length; S text() { ret bigDB_getText(this); } void setText(S text) { bigDB_newStringEntry(text, this); } toString { ret "BigEntry " + globalID; } } sbool bigDB_inited; svoid bigDB() { lock dbLock(); if (bigDB_inited) ret; bigDB_inited = true; dbIndexing(BigEntry, 'globalID); bigDB_standardDB(); } static BigDB bigDB_standardDB() { ret uniq(BigDB, name := ""); } static BigEntry bigDB_newStringEntry(S text) { ret bigDB_newStringEntry(text, null); } static BigEntry bigDB_newStringEntry(S text, BigEntry entry) { lock dbLock(); BigDB db = entry != null ? entry.db! : bigDB_standardDB(); long fileNr = bigDB_fileNrToAppendTo(); S globalID = entry != null ? entry.globalID : aGlobalID(); File file = bigDB_file(db, fileNr); long length = fileSize(file); long l = lUtf8(text); S header = globalID + " " + l + "\n"; long start = length + lUtf8(header); appendToTextFile(file, header + text + "\n"); if (entry == null) entry = cnew(BigEntry, +db, +globalID); cset(entry, +fileNr, headerStart := length, +start, length := l); ret entry; } static long bigDB_fileNrToAppendTo() { ret 1; } static File bigDB_file(BigDB db, long nr) { ret getProgramFile("db." + urlencode(appendIfNempty(unnull(db.name), ".")) + nr); } static S bigDB_getText(BigEntry entry) { File f = bigDB_file(entry.db!, entry.fileNr); ret fromUtf8(loadBinaryFilePart(f, entry.start, entry.start+entry.length)); }