Skip to main content

Simple package to check schema of NoSQL database (MongoDB).

Project description

NoSQL-Schema-Check

pip install NoSQL_Schema_Check

from nosql_schema_check.model import Model

class Model_Class(Model):

    Schema={field: value}

    Validations={field: function -> True/False}

    Default={field: function -> Default value}

    Required=[keys, ...]

  Optional variable -

    collection=Collection object.

Model_Class.generate()


Schema = {

    "key": 'type', -> change 'type' with type string.

    "key1": {key: value, ...},

    "key2": ('list', 'type') -> change 'type' with type string. ([value1, value2, ...])

}


Validations = {

    "key": validate function for value,

    ...

    validation for 'type' only.

}


Default = {

    "key": function that returns default value,

    ...

    default value for field only.

}


functions -

   Model_Class.check_data

   Model_Class.print_schema

   Model_Class.compare_records

   Model_Class.compare_record

   Model_Class.update_records

   Model_Class.update_record

   Model_Class.collection


Example:

class Test(Model):
    Schema={
        "integer": "int",
        "string": "str",
        "list": ('list', "int"),
        "dict": {
            "key": "int", 
            "key1": ('list', {
                "integer": "int", 
                "list": ('list', 'str')
            })
        },
        "list_in_list": ('list', ('list', "str")),
        "dict_in_dict": {
            "a": 'int',
            "b": {
                "a": 'str'
            }
        }
    }
    Validations={
        "integer": lambda i:True if i < 10 else print("Integer must be less than 10."),
        "string": lambda s: len(s) < 10,
        "list": (lambda l: len(l) < 4, lambda i: i < 10),
        "dict":(lambda d: len(d) < 3,
            {
                "key": lambda i: i < 10,
                "key1": (lambda l: len(l) < 2,)
            }),
        "list_in_list": lambda s: len(s) < 10,
        "dict_in_dict": {
            "b": {
                "a": lambda s: len(s) < 20,
            },
            "a":lambda i: i < 20
        }
    }
    Required=["integer", "list", ('dict', ["key", ("key1", ["integer"])])]
    Default={"string":lambda:"Default_String"[:9]}
    name="test"

Test.generate()

try:
    data = Test.compare_record({"integer": 9, "list": [2,3,5], "dict": {"key": 9, "key1": [{"integer": 20, "list": ["asdd", "sfd"]}]}, "list_in_list": [["string1", "string2", "string3"]], "Something": "Extra_Thing"}, True)
    print(data)
    data.pop("Something")
    print(Test.compare_records([data]))
    print(Test.update_record({"integer": 5, "list": [10,20,30]}, data))
    print(Test.update_records([{"integer": 5, "list": [10,20,30]},], [data,]))
except:
    pass

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

nosql_schema_check-0.0.8.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

nosql_schema_check-0.0.8-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file nosql_schema_check-0.0.8.tar.gz.

File metadata

  • Download URL: nosql_schema_check-0.0.8.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for nosql_schema_check-0.0.8.tar.gz
Algorithm Hash digest
SHA256 9792ee3922c2c7ed99c695bb9856e9c1a79d22742179965632d2cbadafbacedf
MD5 6bb542305d9fac91cc375ee72ef2e2aa
BLAKE2b-256 69d5dac0e82561cfae4a4e07e60c4afa94597ed03911d41711beb2d48f03c3f9

See more details on using hashes here.

File details

Details for the file nosql_schema_check-0.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for nosql_schema_check-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 e0e395dd7870c1a769e037c67a35a59a393e555a9ff7786e4489022d1508b83c
MD5 0affa28f44d62a92dc29f8131bd752f3
BLAKE2b-256 e19077eeb423e092bae0e8c09ebd13bf52d28be24bec636e7373775170dbe489

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