db reference
The db package: db.
db
error Unreadable
offer error UnreadableWhat a store that cannot be opened or read answers with.
class Store
offer class StoreA key-value store backed by one file.
field handle
var handle: s32 = -1field path
var path: text = ""field index
var index: List<Entry>field live
var live: int = 0field dead
var dead: int = 0field at_end
var at_end: s64 = 0method deinit
deinitmethod IsOpen
fun IsOpen() -> boolmethod Len
fun Len() -> intHow many keys there are.
method Wasted
fun Wasted() -> intHow many records the log holds that nothing points at any more.
Compact is worth calling when this is most of the file.
method Has
fun Has(key: text) -> bool uses unsafeWhether key is there.
method Get
fun Get(key: text) -> text? uses unsafeWhat key holds, or nothing.
method Put
fun Put(key: text, value: text) -> bool uses unsafePuts value under key, replacing what was there.
The record is on the disk when this answers true -- fsync, not
"the system will get to it", because a store that loses the last
write is a store nobody can use for what a store is for.
method Delete
fun Delete(key: text) -> bool uses unsafeTakes key away. True when it was there.
method Keys
fun Keys() -> List<text> uses unsafeEvery key, in order.
method Range
fun Range(from: text, to: text) -> List<text> uses unsafeEvery key from from up to but not including to, in order.
What a sorted index is for: Range("user:", "user;") is every
user, and a log-structured store usually cannot answer it.
method Compact
fun Compact() -> bool uses unsafeWrites the live records to a new file and swaps it in.
What reclaims the space a replaced or deleted record still takes. Safe to interrupt: the new file is written whole and renamed, so either the old store or the new one is there, never half of one.
method Find
fun Find(key: text) -> int uses unsafemethod LowerBound
fun LowerBound(key: text) -> int uses unsafemethod Remember
fun Remember(key: text, offset: s64, length: int, gone: bool) uses unsafemethod ReadValue
fun ReadValue(entry: Entry) -> text? uses unsafefunction Open
offer fun Open(path: text) -> Store!Unreadable uses io, unsafeOpens the store at path, making it when it is not there.
function Close
offer fun Close(store: &mut Store) uses io, unsafeCloses the store. Reading or writing after this answers nothing.