Skip to main content

daba by Klivolks.

Project description

daba by Klivolks

The daba library, developed by Klivolks, is a Python package designed to simplify the process of interacting with MongoDB databases. It provides convenient and easy-to-use methods for carrying out common database operations such as querying, inserting, updating, and deleting data.

Installation

This package can be installed using pip:

pip install daba

Environment Variables

Two environment variables need to be set:

  • MONGO_URL: This is the URL of the MongoDB server.
  • MONGO_DB: This is the name of the MongoDB database to interact with.

And optional variables are

  • MONGO_POOL_SIZE: This is the default pool size of the MongoDB database.

These can be set in an .env file that can be loaded with python-dotenv. Remember not to commit sensitive data (like your database URLs) to version control!

Example usage

In this example, the collection class from the daba.Mongo module is being used to interact with a MongoDB collection.

You can create a collection object using the collection method:

db_obj = collection('test')

The collection object has several methods to interact with the MongoDB collection.

Methods

Below are the methods available in the daba library's collection class, along with brief descriptions of what they do:

  • init_db(): Initializes the MongoDB database.
  • close_db(): Closes the MongoDB database connection.
  • get(query): Returns documents that match the query.
  • put(data): Inserts a single document into the collection.
  • putMany(data): Inserts multiple documents into the collection.
  • set(query, new_data): Updates a single document that matches the query.
  • inc(query, data_to_increment): Increments the value of specific fields in a document that matches the query.
  • setMany(query, new_data): Updates multiple documents that match the query.
  • getOne(query): Returns a single document that matches the query.
  • getAfterCount(query, field): Returns a document after incrementing the value of a specific field.
  • deleteOne(query): Deletes a single document that matches the query.
  • deleteMany(query): Deletes multiple documents that match the query.
  • removeElement(query, element): Removes an element from an array in the documents that match the query.
  • count(query): Counts the documents that match the query.
  • createIndex(field, options): Creates index to the current table. Can use list of tuple of indexes or a single string.

Running Tests

This library includes a suite of unit tests. To run the tests, execute the script with a Python interpreter. Ensure the .env file is in the same directory as the script.

python test_daba.py

Note

This README is not exhaustive, and is intended to be a brief introduction to the functionality provided by the daba library. For a full list of functionality and options, please refer to the official documentation.

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

daba-1.0.1.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

daba-1.0.1-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file daba-1.0.1.tar.gz.

File metadata

  • Download URL: daba-1.0.1.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for daba-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c773a481d2ca9017921a71e48a63d2d83a82b6da95130a453beb40192dc5ad64
MD5 8c4d72254e66ccb97be510f0d775e702
BLAKE2b-256 28039db2d99e530596d9ab99baf2cd2c2c4f93a5e84f25e7b10aa7fe377d2c2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for daba-1.0.1.tar.gz:

Publisher: release.yml on klivolks/DaBa

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file daba-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: daba-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for daba-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 805501492888cab122c3e743481e721edcab8b1172b873098a09fb9972aeffb1
MD5 9fb66d8dc651f25a52646212ca2a9cd1
BLAKE2b-256 6abf2bb0af5c0e09d7ef5709adbbc94b0614a268be83717270be63436f3bf906

See more details on using hashes here.

Provenance

The following attestation bundles were made for daba-1.0.1-py3-none-any.whl:

Publisher: release.yml on klivolks/DaBa

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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