Ruby implementation of the "Database" in JSON (Node.js library)!
Released v1.0.1.
gem install meowdb.
or
- Add
gem 'meowdb'in yourGemfileand runbundle install.
require "meowdb"
my_database = MeowDB.new(dir: __dir__, name: "database")
# Object creation (only if it doesn't exist)
puts(my_database.create("0001", {
"name" => "David",
"country" => "CO",
"info" => "Nothing to show"
}))
# Obtaining an object
object = my_database.get("0001")
puts(object)
# Modifying an object and saving it
object["name"] = "Deivid"
object.save()
puts(object)
# Setting directly the value of an element
puts(my_databse.set("0001.info", "Just a person"))
# List of objects
temp = ""
my_database.all().each do |k, v|
temp += " - #{v["name"]} (#{k})\n"
end
puts(temp)
# Deleting an object
puts(my_database.delete("0001"))
# Average time of execution: 41.5ms.new MeowDB(options)create(id, initialValue)exists(id)get(id)set(id, value)all()delete(id)find(callback, id?)filter(callback, id?)
MeowDBError
Creates or gets a database
- Parameters:
options- A hash with the optionsoptions.dir- A string indicating the directory that will have the database (must be an absolute path - the folder should be created)options.name- A string with the name of the database
- Raises:
MeowDBError- If any option is invalid
Returns all data stored in the database
- Returns:
MeowDBHash- All data
Creates an element in the database with the specified ID and sets it's value
- Parameters:
id- A string representing the ID of the element to createinitialValue- The initial value of the element
- Returns:
Hash- The created element - Raises:
MeowDBError- If the ID or initialValue is invalid
Deletes an element from the database
- Parameters:
id- A string representing the ID of the element to delete
- Returns:
Hash- The deleted element - Raises:
MeowDBError- If the ID is invalid
Checks if an element exists in the database
- Parameters:
id- A string representing the ID of the element to check
- Returns:
TrueClass/FalseClass- If it exists - Raises:
MeowDBError- If the ID is invalid
Gets an element of the database
- Parameters:
id- A string representing the ID of the element to get
- Returns:
*- The element - Raises:
MeowDBError- If the ID is invalid
Sets the value of an element in the database
- Parameters:
id- A string representing the ID of the element to updatevalue- The new value of the element
- Returns:
*- The value setted - Raises:
MeowDBError- If the ID or value is invalid
Finds an element in the database. You should only use this function if you're finding for objects
- Parameters:
id- A string representing the ID of the root element to find another elements
- Returns:
*- The element - Raises:
MeowDBError- If the ID or callback is invalid
Filters elements in the database. You should only use this function if you're filtering for objects
- Parameters:
id- A string representing the ID of the root element to find another elements
- Returns:
*- The elements (MeowDBObject[] if they're objects, array with ID and value if not) - Raises:
MeowDBError- If the ID or callback is invalid
Extends StandardError, only used for error reference.