Skip to main content

PyMongoose enable you to validate your SChema and setting them default values it Give you Schema Object that give you easier accesbility of pymongo collection

Project description

Powerful python library like Mongoose

PyDbSchema Features

The library enable one to create Schema validates the Schema.

The Library will also insert the Default values when one provided and it in schema but didn't provide during insertation.

The library is very hand and it's objects are directly Pymongo collection Object do one configuration the all of the.

Schema can access pymongo Object method the Shema are Collection Level, Let Bring the Mongoose Flavour.

Requirements || dependecies

pymongo >= 3.0

Usage

Configuration

Create a folder with the database configuration then pass database name and url or name only

    # import the module
    import PyDbSchema
    PyDbSchema.connect(<DatabaseName: str>)
    # Test if the database if connected
    if PyDbSchema.connection.connected:
        print("Connected")

So by this one folder all the database Configuration are ready Note: This code mostly should be at the top so as to enable Schema to access conection

Models Creation

Create a folder and insert all of your model Rules here

    # For Example here
    import PyDbSchema
    User = {
    'Attributes':[{ "Name": {
    "dtype": str,
    "req": True,
    "default": None
    }},
    { "email": {
    "dtype": str,
    "req": True,
    "default": None
    }},
    }

    ## Creating the Schema
    User = PyDbSchema.Schema(<Skelrton:dict>, <NameSchema: str>)
    # The Schema object is Collection Object by nature and pymongo methods can be used in itds

Using the Schema Object Method

The Schema Object perform all of the methods like how pymongo Object will perform but Crud( Create Read Update Delete) operation are easier as follows

Creating

Note: Advantages of PyDbSchema is that it's Schema are validated and default value are passed if not there

Methods

Model.insertOne(data) -> # Insert One object passed into the collection Used

Model.bulkInsert(data

    Example
    # Inserting Document
    # Create a folder and database configuration
    # Create the Models  Folder
    # Inside creates Schema Objects
    Example 
    from Models.User import User # We were having a folder with py file having User Object of the class of Schema
    mydata = {
    "Name": "Jack",
    'email': 'yosiaLukumai@gmail.com',
    }
    response = User.insertOne(credentials)
    print(response) #Return pymongo result object

    # Inserting Many Objects 
    ListOfData [
    {
            "Name": "Jack",
            'email': 'yosiaLukumai@gmail.com'
    },
    {
            "Name": "Onisa",
            'email': 'jr@gmail.com'
    }      
    ]

    response = User.bulkInsert(credentials)

Finding

Note: The Schema skeleton will be used for all of this methods

Methods

Model.find(credential) -> # find the Documents required and return list according to the credential passed

Model.findOne(data) -> # Find and return only one document if credentials passed

    # Find One Result
    # Import the Schema Objects
    # Example 
    from Models.User import User # We were having a folder with py file having User Object of the class of Schema
    credentials = {"Name": 'Yosia'}
    response = User.findOne(credentials)
    print(response) # Check the Response

    # To find many Use the findMany
    credentials = {"Name": 'Yosia'}
    response = User.find(credentials) # Return multiple of the instance found

Updating

Note: The Schema skeleton will be used for all of this methods

Methods

Model.updateOne(credentialForSearching, newdata,dict>) -> # update one according to credentil passed and new data to be inserted

Model.updateMany(credentialForSearching, newdata,dict>) -> # update Many according to credentil passed and new data to be inserted

    # Find One Result
    # Import the Schema Objects
    Example 
    
    from Models.User import User # We were having a folder with py file having User Object of the class of Schema
    myquery = { "Name": "Yosia" }
    newvalues = {"Name": "Shadrack" }
    response = User.updateOne(myquery, newvalues)
    print(response) # Check the Response

    # To updateMany  Use the <Model>.updateMany(dataForSearching<dict>, newData<dict>)
    response = User.updateMany(dataForSearching<dict>, newData<dic>)
    # check response like how pymongo insert method does like
    print(response.matched_count)

Deleting

Note: The Schema skeleton will be used for all of this methods

Methods

Model.deleteOne(credential) -> # delete one according to credentil passed

Model.deleteMany(credential) -> # delete Many according to credentil passed

    # Find One Result
    # Import the Schema Objects
    Example 
    
    from Models.User import User # We were having a folder with py file having User Object of the class of Schema
    response = User.deleteMany(myquery, newvalues)
    print(response) # Check the Response
    credentials = {"Name": 'Yosia'}
    # To updateMany  Use the <Model>.deleteMany(credentials:dict)
    credentials = {"Name": 'Yosia'}
    response = User.deleteOne(credentials<dict>)
    # check response like how pymongo insert method does like

FindById

Just pass the id and model will give you the back whole document

    # Example
    from Models.User import User # We were having a folder with py file having User Object of the class of Schema
    response = User.findById(id)
    print(response) # Check the Response

Using Schema as Object as Pymongo Collection

Just Use the attribute inside the Schema the collection attribute example

    # Example
    from Models.User import User # We were having a folder with py file having User Object of the class of Schema
    # collection
    collection = User.collection
    type(User.collection) # Return <class 'pymongo.collection.Collection'>
    # so all of the pymongo collection methods can be used
    # like
    collection.create_index,  next, watch

Powered By: Yosia Lukumai

Github Account: https://github.com/yosiaLukumai

Email me trough: yosiadev@gmail.com

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

PyDbSchema-0.0.5.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

PyDbSchema-0.0.5-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file PyDbSchema-0.0.5.tar.gz.

File metadata

  • Download URL: PyDbSchema-0.0.5.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.2

File hashes

Hashes for PyDbSchema-0.0.5.tar.gz
Algorithm Hash digest
SHA256 4055bd1ce013e06c8ce8c7b877f1e0d4a730f782d0112c4e7221b7eb4a7f2eee
MD5 0ee11417f24c8fc13bb9c4b382628373
BLAKE2b-256 e00560829e6f9076992ba23fcef24c96b0a403ff8c8ffef687f664e7457e2f01

See more details on using hashes here.

File details

Details for the file PyDbSchema-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: PyDbSchema-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.2

File hashes

Hashes for PyDbSchema-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 eab131a91046055d3a1e0d5053c1aca70a76be07cadbed024c1313643e2a106e
MD5 abfb7a5c519f712aa9c696175e6227c2
BLAKE2b-256 0c05d37457cd3612f602eb09a401173f6158ac4360f8b5c1fed4bb445c063193

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