struct BushDB::DB

Overview

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

Defined in:

bushdb/db.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def branch_mode : Int32 #

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


[View source]
def branch_mode=(branch_mode : Int32) #

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


[View source]
def clear : Nil #

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

[View source]
def db_name : String #

Database name.
Defaule by = "store"


[View source]
def db_name=(db_name : String) #

Database name.
Defaule by = "store"


[View source]
def 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

[View source]
def 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

[View source]
def 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

[View source]
def initialize #

[View source]
def leaf_mode : File::Permissions #

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


[View source]
def leaf_mode=(leaf_mode : File::Permissions) #

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


[View source]
def napalm : Nil #

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

[View source]
def root_store : Path #

Root directory for databases.
Defaule by = "BushDB"


[View source]
def root_store=(root_store : Path) #

Root directory for databases.
Defaule by = "BushDB"


[View source]
def 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")

[View source]