Namespace: joker.bolt
v1.0Contents
Summary
Provides a small string-oriented API for the Bolt embedded key/value database.
Example:
user=> (def db (joker.bolt/open "bolt.db" 0600))
#'user/db
user=> (joker.bolt/create-bucket db "users")
nil
user=> (def id (joker.bolt/next-sequence db "users"))
#'user/id
user=> id
1
user=> (joker.bolt/put db "users" (str id) (joker.json/write-string {:id id :name "Joe Black"}))
nil
user=> (joker.json/read-string (joker.bolt/get db "users" (str id)))
{"id" 1, "name" "Joe Black"}
Index
- by-prefix
- close
- create-bucket
- create-bucket-if-not-exists
- delete
- delete-bucket
- get
- next-sequence
- open
- put
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
(None.)
Functions, Macros, and Special Forms
-
by-prefix
Function v1.0(by-prefix db bucket prefix)Returns key/value pairs from bucket whose keys start with prefix.
Results are returned as a vector of [key value] vectors in Bolt key order.
Passing the empty string returns all key/value pairs in the bucket. Throws
Error when bucket does not exist or the transaction fails. -
close
Function v1.0(close db)Closes db and releases its database resources.
Blocks until open transactions finish, then releases the file lock. Throws
Error if closing fails. -
create-bucket
Function v1.0(create-bucket db name)Creates bucket name and returns nil.
Throws Error if the bucket already exists, if name is blank or too long, or
if the transaction fails. -
create-bucket-if-not-exists
Function v1.0(create-bucket-if-not-exists db name)Creates bucket name when needed and returns nil.
Does nothing when the bucket already exists. Throws Error if name is blank or
too long, or if the transaction fails. -
delete
Function v1.0(delete db bucket key)Removes key from bucket and returns nil.
Missing keys are ignored. Throws Error when bucket does not exist or the
transaction fails. -
delete-bucket
Function v1.0(delete-bucket db name)Deletes bucket name and returns nil.
Throws Error when the bucket does not exist or the transaction fails. -
get
Function v1.0(get db bucket key)Returns the string value stored at key in bucket.
Returns nil when key does not exist. Throws Error when bucket does not exist
or the transaction fails. -
next-sequence
Function v1.0(next-sequence db bucket)Returns the next auto-incrementing integer for bucket.
Each call advances the bucket sequence counter inside a write transaction.
Throws Error when bucket does not exist or the transaction fails. -
open
Function v1.0(open filename mode)Opens the database file at filename and returns a BoltDB handle.
If the file does not exist, it is created with mode before the process umask
is applied. mode is normally written as an octal literal such as 0600.
Throws Error when the database cannot be opened.
The underlying database uses an exclusive file lock; because this wrapper uses
Bolt's default options, open may wait indefinitely for another process to
release the same database file.
Example:
(def db (joker.bolt/open "app.db" 0600)) -
put
Function v1.0(put db bucket key value)Stores value at key in bucket and returns nil.
Keys and values are strings stored as raw bytes. Replaces any previous value
for key. Throws Error when bucket does not exist, when key is blank or too
large, when value is too large, or when the transaction fails.