Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(2)  |  Call(0)  |  Derive(0)  |  Import(2)
Looks up an object with the given kwargs, creating one if necessary.
Returns a tuple of (object, created), where created is a boolean
specifying whether an object was created.

        def get_or_create(klass, session, **kwargs):
    """ 
    Looks up an object with the given kwargs, creating one if necessary.
    Returns a tuple of (object, created), where created is a boolean
    specifying whether an object was created.
    """
    assert kwargs, \
            'get_or_create() must be passed at least one keyword argument'
    try:
        return session.query(klass).filter_by(**kwargs).one(), False
    except NoResultFound:
        try:
            obj = klass(**kwargs)
            session.add(obj)
            session.flush()
            return obj, True
        except IntegrityError:
            return session.query(klass).filter_by(**kwargs).one(), False
        


src/f/p/fpdb-grindi-HEAD/pyfpdb/AlchemyMappings.py   fpdb-grindi(Download)
 
from AlchemyTables import *
from AlchemyFacilities import get_or_create, MappedBase
from DerivedStats import DerivedStats
from Exceptions import IncompleteHandError, FpdbError

src/f/p/fpdb-sql-HEAD/pyfpdb/AlchemyMappings.py   fpdb-sql(Download)
 
from AlchemyTables import *
from AlchemyFacilities import get_or_create, MappedBase
from DerivedStats import DerivedStats
from Exceptions import IncompleteHandError, FpdbError