コード例 #1
0
        
        return False
    return True

def sa_create(class_, **kw):
    try:
        obj = class_(**kw)
    except TypeError:
        obj = class_()
    sa_update(obj, **kw) # update takes care of save/flush
    return obj
sa_create = create.when(class_test)(sa_create)

def sa_retrieve(class_, **kw):
    return session.query(class_).filter_by(**kw).all()
sa_retrieve = retrieve.when(class_test)(sa_retrieve)

def sa_retrieve_one(class_, **kw):
    query = session.query(class_).filter_by(**kw)
    count = query.count()
    if count == 0:
        return None
    elif count == 1:
        return query[0]
    else:
        raise LookupError, 'Received %d results.' % count
sa_retreive_one = retrieve_one.when(class_test)(sa_retrieve_one)
    
def sa_update(obj, **kw):
    [setattr(obj, key, value) for key, value in kw.iteritems()]
    push_to_db(obj)
コード例 #2
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from api import create, retrieve, retrieve_one, update, delete, count
import sqlobject as so


def so_create(class_, **kw):
    return class_(**kw)
so_create = create.when('issubclass(class_, so.SQLObject)')(so_create)

def so_retrieve(class_, **kw):
    return list(select_from_kw(class_, **kw))
so_retrieve = retrieve.when('issubclass(class_, so.SQLObject)') \
                (so_retrieve)

def so_retrieve_one(class_, **kw):
    results = so_retrieve(class_, **kw)
    count = len(results)
    if count == 0:
        return None
    elif count == 1:
        return results[0]
    else:
        raise LookupError, 'Received %d results.' % count
so_retrieve_one = retrieve_one.when(
            'issubclass(class_, so.SQLObject)')(so_retrieve_one)

def so_update(obj, **kw):
    obj.set(**kw)