Skip to main content

SQLAlchemy plugin for Spotlight.

Project description

Spotlight SQLAlchemy

SQLAlchemy plugin for Spotlight.

Table of Contents

Installation

Spotlight SQLAlchemy can be installed via pip:

pip install spotlight-sqlalchemy

Dependencies

Usage

from spotlight_sqlalchemy.plugin import SQLAlchemyPlugin

Examples

from spotlight.validator import Validator
from spotlight_sqlalchemy.plugin import SQLAlchemyPlugin

rules = {
    "id": "exists:user,id",
    "email": "unique:user,email"
}

input_ = {
    "id": 1,
    "email": "john.doe@example.com"
}

validator = Validator([SQLAlchemyPlugin(session)])
errors = validator.validate(input_, rules)

Available Rules

Warning: You should never pass any user controlled input into the database rules. Otherwise, your application will be vulnerable to an SQL injection attack.

unique (database)

The field under validation must be unique in a given database table. The last 4 fields (ignore column, ignore value, where column, where value) are optional.

unique:table,column
unique:table,column,ignoreColumn,ignoreValue
unique:table,column,ignoreColumn,ignoreValue,whereColumn,whereValue
unique:table,column,null,null,whereColumn,whereValue

exists (database)

The field under validation must exist on a given database table. The last 2 fields (where column, where value) are optional.

exists:table,column
exists:table,column,whereColumn,whereValue

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

spotlight-sqlalchemy-0.1.0.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

spotlight_sqlalchemy-0.1.0-py3-none-any.whl (6.2 kB view hashes)

Uploaded Python 3

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