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.

The example above shows a unittest test suite for the various methods provided by the daba library.

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.

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.

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-0.0.3.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

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

daba-0.0.3-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: daba-0.0.3.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for daba-0.0.3.tar.gz
Algorithm Hash digest
SHA256 713fac4e8b3b972621e629d9ce8535c290c9365c30f04214af36ce6ee245664e
MD5 6911b030ce9e0545f02490cb3342fc81
BLAKE2b-256 385f7a1b2129e43256599923188cb2034cfe184608f376e99a8bc631cf4798a1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: daba-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for daba-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 930bc0c77421c6942a66664d83c1b5d884ef337dd05c28b924c856814f839423
MD5 302845a652da9df1c974134980cf873c
BLAKE2b-256 17de7f27ca498faccb71fc1ea3c91ffb2b60c8e3b8c1b21d55b8c85934a90890

See more details on using hashes here.

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