예제 #1
0
파일: dbobject.py 프로젝트: eallik/twistar
    def findBy(klass, **attrs):
        """
        Find all instances of the given class based on an exact match of attributes.

        For instance:
        C{User.find(first_name='Bob', last_name='Smith')}

        Will return all matches.
        """
        where = dictToWhere(attrs)
        return klass.find(where = where)
예제 #2
0
    def findBy(klass, **attrs):
        """
        Find all instances of the given class based on an exact match of attributes.

        For instance:
        C{User.find(first_name='Bob', last_name='Smith')}

        Will return all matches.
        """
        where = dictToWhere(attrs)
        return klass.find(where=where)
예제 #3
0
    def findBy(klass, **attrs):
        """
        Find all instances of the given class based on an exact match of attributes.

        For instance:
        C{User.find(first_name='Bob', last_name='Smith')}

        Will return all matches.
        """
        transaction = None
        if 'transaction' in attrs:
            transaction = attrs['transaction']
            del(attrs['transaction'])
        where = dictToWhere(attrs)
        return klass.find(where = where, transaction=transaction)
예제 #4
0
    def findBy(klass, **attrs):
        """
        Find all instances of the given class based on an exact match of attributes.

        For instance:
        C{User.find(first_name='Bob', last_name='Smith')}

        Will return all matches.
        """
        transaction = None
        if 'transaction' in attrs:
            transaction = attrs['transaction']
            del(attrs['transaction'])
        where = dictToWhere(attrs)
        return klass.find(where = where, transaction=transaction)
예제 #5
0
    def test_dictToWhere(self):
        self.assertEqual(utils.dictToWhere({}), None)

        result = utils.dictToWhere({ 'one': 'two' }, "BLAH")
        self.assertEqual(result, ["(one = ?)", "two"])

        result = utils.dictToWhere({ 'one': None }, "BLAH")
        self.assertEqual(result, ["(one is ?)", None])

        result = utils.dictToWhere({ 'one': 'two', 'three': 'four' })
        self.assertEqual(result, ["(three = ?) AND (one = ?)", "four", "two"])

        result = utils.dictToWhere({ 'one': 'two', 'three': 'four', 'five': 'six' }, "BLAH")
        self.assertEqual(result, ["(five = ?) BLAH (three = ?) BLAH (one = ?)", "six", "four", "two"])

        result = utils.dictToWhere({ 'one': 'two', 'three': None })
        self.assertEqual(result, ["(three is ?) AND (one = ?)", None, "two"])
예제 #6
0
    def test_dictToWhere(self):
        self.assertEqual(utils.dictToWhere({}), None)

        result = utils.dictToWhere({'one': 'two'}, "BLAH")
        self.assertEqual(result, ["(one = ?)", "two"])

        result = utils.dictToWhere({'one': None}, "BLAH")
        self.assertEqual(result, ["(one is ?)", None])

        result = utils.dictToWhere(OrderedDict([
            ('one', 'two'), ('three', 'four')]))
        self.assertEqual(result, ["(one = ?) AND (three = ?)", "two", "four"])

        result = utils.dictToWhere(OrderedDict([
            ('one', 'two'), ('three', 'four'), ('five', 'six')]), "BLAH")
        self.assertEqual(result, ["(one = ?) BLAH (three = ?) BLAH (five = ?)", "two", "four", "six"])

        result = utils.dictToWhere(OrderedDict([
            ('one', 'two'), ('three', None)]))
        self.assertEqual(result, ["(one = ?) AND (three is ?)", "two", None])
예제 #7
0
    def test_dictToWhere(self):
        self.assertEqual(utils.dictToWhere({}), None)

        result = utils.dictToWhere({'one': 'two'}, "BLAH")
        self.assertEqual(result, ["(one = ?)", "two"])

        result = utils.dictToWhere({'one': None}, "BLAH")
        self.assertEqual(result, ["(one is ?)", None])

        result = utils.dictToWhere(
            OrderedDict([('one', 'two'), ('three', 'four')]))
        self.assertEqual(result, ["(one = ?) AND (three = ?)", "two", "four"])

        result = utils.dictToWhere(
            OrderedDict([('one', 'two'), ('three', 'four'), ('five', 'six')]),
            "BLAH")
        self.assertEqual(result, [
            "(one = ?) BLAH (three = ?) BLAH (five = ?)", "two", "four", "six"
        ])

        result = utils.dictToWhere(
            OrderedDict([('one', 'two'), ('three', None)]))
        self.assertEqual(result, ["(one = ?) AND (three is ?)", "two", None])