Skip to main content

Handle both Postgres and MongoDB queries in an interchangable manner.

Project description

mdbpq

Handle both Postgres and MongoDB queries in an interchangable manner.

pip install mdbpg

codefactor circleci codecov

import mdbpg

# create an instance for Postgres or MongoDB through mdbpg
# max_conns and use_env_vars are both optional parameters
# max_conns defaults to 10 and use_env_vars defaults to True
# if use_env_vars is False then mdbpg will try to load a toml
# config named 'database.toml' using mtoml instead
pgdb = mdbpg.postgres(max_conns=5, use_env_vars=True)
mdb = mdbpg.mongodb(max_conns=50, use_env_vars=True)

# both methods work in the same manner, you specify the
# table/collection with the first parameter and then pass
# a dict containing the parameters and values you want
# the function then returns either None if something went
# wrong or a list of dict results
result_list = pgdb.find('dogs', { 'color': 'black' })
result_list = mdb.find('dogs', { 'color': 'black' })
# the benefit of this is that you can build queries in the
# same manner for both databases and expect it to just work

# again these are equivalent, though there are differences
# between how Postgres and MongoDB will view these calls
# for MongoDB this is the entire object, where as with Postgres
# this may only be a few columns and so when setting up your
# table in Postgres it would be ideal to set default values
pgdb.insert('dogs', { 'breed': 'pitbull', 'color': 'white', 'cuteness': 9000.01 })
mdb.insert('dogs', { 'breed': 'pitbull', 'color': 'white', 'cuteness': 9000.01 })
# both Postgres and MongoDB contain the same methods:
# find, insert, update, delete
# though postgres.insert() is the only method with a gotcha like that

# Postgres has two additional methods which handle SQL queries
# both methods can be used to run any valid SQL query except that
# postgres.fetch() expects a result to be returned from the query
# where as postgres.commit() does not
result_list = pgdb.fetch("SELECT * FROM 'dogs' WHERE breed = 'hound'")
pgdb.commit("DELETE FROM 'dogs' WHERE breed = 'hound'")

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

mdbpg-0.2.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

mdbpg-0.2.1-py2.py3-none-any.whl (11.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file mdbpg-0.2.1.tar.gz.

File metadata

  • Download URL: mdbpg-0.2.1.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for mdbpg-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b0633a5e3077f625f84f486b31152fe291d9c03f60e218c7948dfc39ca5d4750
MD5 9860849f7b7dffd7c266691a60304135
BLAKE2b-256 b4a36dd97504bdf1d899b1ac15471c2d33dcc5e2c58dfe350fdca7df93ecc54b

See more details on using hashes here.

File details

Details for the file mdbpg-0.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: mdbpg-0.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for mdbpg-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 606e4719439a5598b17965de5edb55ca9f68c79a4415f1b47235f4c5f9757ddd
MD5 1c8f8c1418abfa5303f7157aaced0cdc
BLAKE2b-256 eebc165e8beb2badba814a340bb55d8e1bebf367cbb884a76c0d9e8a9162822f

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