Project

meowdb

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A Ruby implementation of the MeowDB.js library (https://www.npmjs.com/package/meowdb).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

MeowDB.rb

MeowDB

Downloads Repository Size License Last Commit Version

Ruby implementation of the "Database" in JSON (Node.js library)!

Released v1.0.1.

Installation

  • gem install meowdb.

or

  • Add gem 'meowdb' in your Gemfile and run bundle install.

Usage

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.

"Documentation"

  • new MeowDB(options)
    • create(id, initialValue)
    • exists(id)
    • get(id)
    • set(id, value)
    • all()
    • delete(id)
    • find(callback, id?)
    • filter(callback, id?)
  • MeowDBError

new MeowDB(options)

Creates or gets a database

  • Parameters:
    • options - A hash with the options
      • options.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

Methods

all()

Returns all data stored in the database

  • Returns: MeowDBHash - All data

create(id, initialValue)

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 create
    • initialValue - The initial value of the element
  • Returns: Hash - The created element
  • Raises: MeowDBError - If the ID or initialValue is invalid

delete(id)

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

exists(id)

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

get(id)

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

set(id, value)

Sets the value of an element in the database

  • Parameters:
    • id - A string representing the ID of the element to update
    • value - The new value of the element
  • Returns: * - The value setted
  • Raises: MeowDBError - If the ID or value is invalid

find(callback, id?)

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

filter(callback, id?)

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

MeowDBError

Extends StandardError, only used for error reference.