rds-data-dao

RDS Data API Wrapper


License
MIT
Install
pip install rds-data-dao==0.1.4

Documentation

RdsDataDao

A wrapper around the RDS Data API offering query escaping and automatic parameterization.

Warning

Not an AWS endorsed project - used at Stavvy for managing database queries for some services.

Installation

    pip install rds-data-dao

Example usages.

  1. Provide cmd and data arguments to the crud methods on the RdsDataDao object. It will automatically cast and convert the arguments to parameterized form.

  2. Use %s in the cmd format string for any parameterized argument (except arrays).

  3. Use %s::type to cast arguments, for example %s::json, will cast the argument to json.

ex usage:

    cmd = "select * from banks where id = %s"
    data = [bank_id]
    bank = dao.get_single_result(cmd, data)
    return bank

For arrays, make_list from db_util should be used as arrays are not natively parameterizable as of this writing in the RDS Data API.

    cmd = "select bank_id from files where id in {}".format(make_list(ids)) # ids is list of integers here.
    banks = dao.get(cmd)
    return banks

Example Response

The RdsDataDao translates responses into dict format using returned column definitions in the data api:

{
    "numberOfRecordsUpdated": 0,
    "columnMetadata": [
        {
            "name": "id"
        },
        {
            "name": "name"
        }],
    "records": [
        [
            {
                "longValue": 1
            },
            {
                "stringValue": "John"
            }
        ],
        [
            {
                "longValue": 2
            },
            {
                "stringValue": "Joe"
            }
        ]
    ]
}

maps to:

[
    {"id": 1, "name": "John"}, 
    {"id": 2, "name": "Joe"}
]

References

Publishing (internal)

  • python setup.py sdist
  • twine upload dist/*