Skip to main content

# About HydroDB

Project description

About HydroDB

HydroDB can be a non-relational or a relational database library for Python, designed to be easy to use and agile. It allows you to create JSON files and store data in them with desired keys. Additionally, it enables searching, updating, and deleting data within the JSON file.

Why HydroDB exists?

The idea for HydroDB emerged during my college days when I had to use TinyDB in one of my classes. While TinyDB is a good library for non-relational databases, I felt that something was missing. After studying the subject, I decided to create my own non-relational database library.

Setting Up

Requirements (for versions 1.#.#)

pip install hydrodb

Data structure

On HydroDB all JSON files has an shered base struct:

{
  "TABLE NAME": "tables-name",
  "META DATA": "tables-meta-data",
  "TABLE COLUMNS": [
    "columns_1",
    "columns_2",
    "...",
  ],
  "PK": "tables-primary-key",
  "ROWS": [
        {
          "id": 1,
          "values": {
              "column_1": "x",
              "columns_2": null,
          }
        }
  ]
}
  • "TABLE TABME": string -> Is the name of the table.

  • "META DATA": string -> Here goes the descriptions of the data tha goes into the table.

  • "TABLE COLUMNS":array/list -> The columns tha goes into the table.

  • "PK": string -> Is the columns that represents the primary key of the table.

  • "ROWS": array/list of dictionaries -> Here goes the rows of the table. Is important to remember that every single row has an id and the values of the row associeted with the table's columns.

Observable functions

Those functions are made to lookup the table, for general porpose

Get Started

Here is a simple guide on how to use the HydroDB module.

Calling HydroDB in the program

Default creation

To use the module, simply use:

from hydrodb import HydroDB

hydro = HydroDB()

In this case, a directory db/ will be created at your project folder level:

your-project-folder
    |--> db/ 
    |--> hydrodb/
    |--> main.py

Optional dirpath

HydroDB allows you to choose a folder to create the database directory.

To do that, use:

from hydrodb import HydroDB

hydro = HydroDB(optional_path='any_dir_name')

In this case, a directory db/ will be created at your project folder level:

your-project-folder
    |--> any_dir_name
        |--> db/
    |--> hydrodb/
    |--> main.py

Commands list

Designed to be a very user-friendly module, HydroDB only has 6 operational functions and 3 observable functions to be called.

Operational Functions

The opearional functions are thesigned to execute the CRUD

  • C : create
  • R : read
  • U : update
  • D : delete

1 of them are to create, 1 for reade, 3 for update and 1 for delete.

create_table() --> create

The create() function is designed for the creation of tables, along with the columns that each table possesses.

hydro.create_table(
    tables="Table_1", 
    columns=["name", "age"],
    pk="name"
)
// Expected table structure
{
  "TABLE NAME": "TABLE_1",
  "META DATA": null,
  "TABLE COLUMNS": [
    "name",
    "age"
  ],
  "PK": "name",
  "ROWS": []
}
  • tables: str --> Na name of the table to be created. (Learn more about strings)

  • columns: Lists --> The columns for the table. (Learn more about lists)

  • pk: str --> Defines the primary key of the table. If no values are passed, the primary-key will be the id

add_row() --> update

To add values to table's columns, uses the add() function.

hydro.add_rows(
    table_name="Table_1",
    into_columns=["name", "age"],
    values=["James", 34]
)
// Expected result
{
  "TABLE NAME": "TABLE_1",
  "META DATA": null,
  "TABLE COLUMNS": [
    "name",
    "age"
  ],
  "PK": "name",
  "ROWS": [
    {
        "id": 1,
        "values":{
            "name": "James",
            "age": 34
        }
    }
  ]
}
  • tables_names: str --> Receives the table that you want to add values.

  • into: list --> These are the columns of the table that will have a value added.

  • values: list --> These are the values for each column selected.

query() --> search

This function is used to get values from a table.

hydro.query(
    from_="Table_1",
    columns=["name", "age"],
    where="age = 34"
)
# expected output: [{"id" : 1, "values" :{"name":"James", "age":34}}]

NOTE: A string is returned

  • table_name: str --> Is the name of the table to be querried.

  • columns: list --> Here, is the values you want to receve. If None, the entire row is returned.

  • filter: str --> Is the parameter to querry a specific group of elements or a single element. If non filter parameter is passed, the entire table will be returned.

update() --> update

The update funcions serves to update values from rows, or a single row. If you want to update a single row, uses the element id as the filter parameter.

hydro.update(
    from_="Table_1",
    columns=["name", "age"],
    where="name = James",
    with_values=["Caio", 19],
)
// Expectd result
{
  "TABLE NAME": "TABLE_1",
  "META DATA": null,
  "TABLE COLUMNS": [
    "name",
    "age"
  ],
  "PK": "name",
  "ROWS": [
    {
        "id": 1,
        "values":{
            "name": "Caio",
            "age": 19
        }
    }
  ]
}
  • table_name:str --> Is the table to update a row, or a group of rows.

  • columns:list --> These are the list you want to change of each row querried.

  • where:str --> Specifies the groupe of elements or a single element to be updated.

  • with_values:list --> The values to be updated to the current row data.

delete() --> delete

This function removes an entire row from the table that has the specified value passed in.

hydro.delete(
    from_="Table_1",
    where="id = 1"
)
// Expected result
{
  "TABLE NAME": "TABLE_1",
  "META DATA": null,
  "TABLE COLUMNS": [
    "name",
    "age"
  ],
  "PK": "name",
  "ROWS": []
}
  • from_: str --> Is the table to search the row.

  • where: str --> pecifies the groupe of elements or a single element to be updated.

Observable Functions

Those are mede to access general data fro the table, like the entire table structure, or the table's rows

read_table()

This function returns the entire table structure. To use this functions just pass the table name.

hydro.read_table(table_name="TABLE_1")
#Expected output

'{"TABLE NAME": "TABLE_1", "META DATA": null, "TABLE COLUMNS": ["name", "age"], "PK": "name", "ROWS": [{"id": 1, "values":{ "name": "Caio","age": 19}}]}'
  • table_name:str -->Inte the table's name to me readed

read_rows()

This function returns the entire list of rows in the table, to use, just pass the table's name.

hydro.read_rows(table_name="TABLE_1")
# Expected output as the 'TABLE_1' only has this row
'[{"id": 1, "values":{"name": "Caio","age": 19}}]'
  • table_name:str -->Inte the table's name to me readed

read_columns()

Used to get the columns in the table. Important to say that ir does not returns data from the rows, just the name of the columns in the table.

hydro.read_columns(table_name="TABLE_1")
# Expected output as the 'TABLE_1' only has those columns
'["name", "age"]'
  • table_name:str -->Inte the table's name to me readed

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hydrodb-1.0.9.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

hydrodb-1.0.9-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file hydrodb-1.0.9.tar.gz.

File metadata

  • Download URL: hydrodb-1.0.9.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for hydrodb-1.0.9.tar.gz
Algorithm Hash digest
SHA256 7f32ff52a935eefadb76a809439cc50ee8fd301b88bc9959d17defd842dbc43c
MD5 37ce9b76f691a8d74ed8cd387c5b4db0
BLAKE2b-256 87f107c164c2ea40f34b403411e60dca3c6e13f04131aefa8311c540452bc805

See more details on using hashes here.

File details

Details for the file hydrodb-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: hydrodb-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for hydrodb-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 e96943d9584f9e9980c2d2f4f7f42d4d3fcd40ea021cce6c6cd050859c714535
MD5 eceabd29ac5d1b6ab93f6d3da2491ae7
BLAKE2b-256 eac1af645b9979d8375e7557ce705b91332bba49cda8cbda4917e8949301b6ac

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page