Skip to main content

CRUD interface for SQLAlchemy.

Project description

Build Status Coverage Status Stories in Progress PyPI

sacrud

SACRUD will solve your problem of CRUD interface for SQLAlchemy. Originally created for pyramid_sacrud , but then in a separate project

Look how easy it is to use:

CREATE

from .models import DBSession, Groups
from sacrud.action import CRUD

data = {'name': 'Electronics',
        'parent_id': '10',}
group_obj = CRUD(DBSession, Groups).create(data)
print(group_obj.name)

If the entry already exists, just add the option update=True.

from .models import DBSession, Groups
from sacrud.action import CRUD

data = {'id': 6,  # existing entry
        'name': 'Electronics',
        'parent_id': '10',}
group_obj = CRUD(DBSession, Groups).create(data, update=True)
print(group_obj.name)

READ

from .models import DBSession, Groups
from sacrud.action import CRUD

group_obj = CRUD(DBSession, Groups).read()
print(group_obj.name)

UPDATE

from .models import DBSession, Groups
from sacrud.action import CRUD

group_obj = CRUD(DBSession, Groups).update(1, {'name': 'Chemistry'})
print(group_obj.name)

DELETE

from .models import DBSession, Groups
from sacrud.action import CRUD

CRUD(DBSession, Groups).delete(1)

M2M and M2O data

For adding multiple data for m2m or m2o use endinng [], ex.:

from .models import DBSession, Users
from sacrud.action import CRUD

CRUD(DBSession, Users).create(
    {'name': 'Vasya', 'sex': 1,
     'groups[]': ['["id", 1]', '["id", 2]']}
)

It support composit primary key.

Wraps your SQLAlchemy session

from sqlalchemy.orm import scoped_session, sessionmaker
from sacrud import CRUDSession

Session = scoped_session(sessionmaker(class_=CRUDSession))
DBSession = Session()
DBSession.sacrud(User).delete(1)

Wraps your zope.sqlalchemy session

from sqlalchemy.orm import scoped_session, sessionmaker
from zope.sqlalchemy import ZopeTransactionExtension
from sacrud import crud_sessionmaker

DBSession = crud_sessionmaker(scoped_session(
    sessionmaker(extension=ZopeTransactionExtension())))
DBSession.sacrud(User).delete(1)

Now CRUD available from DBSession.

group_obj = DBSession.sacrud(Groups).create(data)
print(group_obj.name)

Installation

Install from github:

pip install git+http://github.com/ITCase/sacrud.git

PyPi:

pip install sacrud

Source:

python setup.py install

Contribute

Support

If you are having issues, please let me know. I have a mailing list located at sacrud@uralbash.ru and IRC channel #sacrud

License

The project is licensed under the MIT license.

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

sacrud-0.3.2.post0.tar.gz (16.1 kB view details)

Uploaded Source

File details

Details for the file sacrud-0.3.2.post0.tar.gz.

File metadata

File hashes

Hashes for sacrud-0.3.2.post0.tar.gz
Algorithm Hash digest
SHA256 b4633183c3b9231673e225dd7ff25d21aa0fe800233d4b474018aa3f969e864a
MD5 9494471ebf7345368ec4fea1456ed913
BLAKE2b-256 6d4fd414f9afb4619a4586100d4365087cb9d47f6a20f9fb5e7bfce1b69882c7

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