struct

BushDB::DB

Inherits Struct < Value < Object

A structure for database management - Set, get, has, update, delete, clear and napalm.

Example:

require "bushdb"

db = BushDB::DB.new
db.set("key name", "Some text")
db.get("key name") # => "Some text"
db.has("key name") # => true
db.delete("key name")
db.clear
db.napalm

Constructors

Instance methods

branch_mode

Directory permissions.
The linux-style permission mode can be specified, with a default of 777 (0o777).

Source
branch_mode=(branch_mode : Int32)

Directory permissions.
The linux-style permission mode can be specified, with a default of 777 (0o777).

Source
clear

Remove directory of database.
If the directory is missing, an #ErrorDirMissing exception is raised. WARNING: Be careful, this will remove all keys.

Example:

require "bushdb"

db = BushDB::DB.new
db.clear
db.clear # => DirMissing
Source
db_name

Database name.
Defaule by = "store"

Source
db_name=(db_name : String)

Database name.
Defaule by = "store"

Source
delete(key : String) : Nil

Delete the key-value from the database.
If the key is missing, an #ErrorKeyMissing exception is raised.

Example:

require "bushdb"

db = BushDB::DB.new
db.set("key name", "Some text")
db.delete("key name")
db.get("key name")    # => nil
db.delete("key name") # => KeyMissing
Source
get(key : String) : String | Nil

Get the value by key from the database.

Example:

require "bushdb"

db = BushDB::DB.new
db.set("key name", "Some text")
db.get("key name")    # => "Some text"
db.get("key missing") # => nil
Source
has?(key : String) : Bool

Check the presence of a key in the database.

Example:

require "bushdb"

db = BushDB::DB.new
db.set("key name", "Some text")
db.has?("key name")    # => true
db.has?("key missing") # => false
Source
initialize
Source
leaf_mode

File permissions.
Default by 0o666 for read-write.

Source
leaf_mode=(leaf_mode : File::Permissions)

File permissions.
Default by 0o666 for read-write.

Source
napalm

Delete the root directory.
If the directory is missing, an #ErrorDirMissing exception is raised. WARNING: Be careful, this will remove all databases. NOTE: The main purpose is tests.

Example:

require "bushdb"

db = BushDB::DB.new
db.napalm
db.napalm # => DirMissing
Source
root_store

Root directory for databases.
Defaule by = "BushDB"

Source
root_store=(root_store : Path)

Root directory for databases.
Defaule by = "BushDB"

Source
set(key : String, value : String) : Nil

Add or update key-value pair(s) to the database.

Example:

require "bushdb"

db = BushDB::DB.new
db.set("key name", "Some text")
Source