cdb(1)

πŸ“¦ in nixpkgs unstable

cdbmake(1) β€” create a constant database πŸ’…πŸŒΈ

okay so bestie, listen up: cdbmake is literally the tool you need if you're trying to build a constant database from encoded records. it's giving main character energy, and the way it handles atomic updates? iconic. no cap.


✨ SYNOPSIS ✨

cdbmake f ftmp

πŸ’– DESCRIPTION πŸ’–

cdbmake reads a series of encoded records from its standard input and writes a constant database to a file named f, replacing any previous contents of f. yes, it fully replaces whatever was there before. periodt. πŸ’…

the way it does this is so slay: cdbmake ensures that f is updated atomically, so programs reading f never have to wait for cdbmake to finish. it does this by first writing the database to ftmp and then moving ftmp on top of f. if ftmp already exists, it is destroyed. rip but make it fashion. 🫢

the directories containing ftmp and f must be writable to cdbmake; they must also be on the same filesystem. no exceptions. ✨

cdbmake always makes sure that ftmp is safely written to disk before it replaces f. so if the input is in a bad format or if cdbmake has any trouble writing ftmp to disk, cdbmake complains and leaves f alone. it said not today. πŸ’€

there is also a cdb64make that uses cdb64 format instead of cdb format. choose your fighter. πŸ‘‘


πŸŽ€ RECORD FORMAT πŸŽ€

records are indexed by keys. a key is a string. the file f is structured so that another program, starting from a key, can quickly find the relevant record. it's giving efficient. πŸ¦‹

now here's the tea: cdbmake allows several records with the same key, although:

  • most readers take only the first record πŸ‘€
  • cdbmake slows down somewhat if there are many records with the same key. lowkey a warning. 🐌

cdbmake preserves the order of records. periodt. πŸ’–

for the input provided to cdbmake, each record is encoded as +klen,dlen:key->data followed by a newline. here klen is the number of bytes in key and dlen is the number of bytes in data. the end of all records is indicated by an extra newline. iykyk.

for example, here are two records:

+3,5:one->Hello
+3,7:two->Goodbye

key and data may contain any characters, including colons, dashes, newlines, and nulls. literally anything. 🌈

keys and data do not have to fit into memory, but cdbmake needs roughly 16 bytes of memory per record. also a database cannot exceed 4 gigabytes (or 1 exabyte for cdb64make). big yikes if you try. 😭

f is portable across machines. slay. ✨


🌈 SEE ALSO 🌈


that's the whole vibe, bestie. signed, sealed, delivered by cdb(1) β€” no date given but you know it's cute. πŸ’ŒπŸ«Ά

πŸ“¦ where this page comes from