Coder Social home page Coder Social logo

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/sacrud/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 [email protected] and IRC channel #sacrud

License

The project is licensed under the MIT license.

sacrud's Projects

ps_crud icon ps_crud

Extension for pyramid_sacrud which provides a templates for CRUD.

ps_tree icon ps_tree

ps_tree is extension for pyramid_sacrud which displays a list of records as tree. This works fine with models from sqlalchemy_mptt.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.