Core

A file that containing the main implementation of the LightDB database management system

class lightdb.core.LightDB(location: str)[source]

Bases: dict

Light Database

A lightweight database implemented as a dictionary with JSON file storage.

This class extends the built-in Python dict class to provide a simple and easy-to-use key-value store that persists its data in a JSON file. The class provides methods to set, get, and remove individual key-value pairs.

classmethod current() LightDB[source]

Returns the current instance of the LightDB class

Returns:

LightDB: An initialized instance of the LightDB

get(key: str) _VT | _T[source]
get(key: str, default: _VT | _T) _VT | _T

Get the value associated with a key from the database

Params:

key (str): The key to retrieve

default (Any, optional): The default value to return if the key doesn`t exist

Returns:

_VT | _T: The value associated with the key, or the default value if the key doesn`t exist

pop(key: str) Any[source]

Remove a key-value pair from the database

Params:

key (str): The key to remove

Returns:

Any: The removed key-value pair

reset() None[source]

Reset the database

save() None[source]

Save the current state of the database to a JSON file

set(key: str, value: Any) None[source]

Set a key-value pair in the database

Params:

key (str): The key to set

value (Any): The value to associate with the key