~fabrixxm/activist

f7c5f279e45dc452beecf5bd9a9fcf41cb80a58b — fabrixxm 7 months ago 3f2b61f
sqlbuilder: fix multiple joins
3 files changed, 16 insertions(+), 1 deletions(-)

M activist/db/sqlbuilder.py
M tests/orm.py
M tests/test_sqlbuilder.py
M activist/db/sqlbuilder.py => activist/db/sqlbuilder.py +2 -0
@@ 413,6 413,8 @@ class Query(QueryBase):
            match k:
                case "(":
                    close = " )"
                case "JOIN":
                    joiner = " JOIN "
                case "WHERE":
                    joiner = " AND "
                case "VALUES":

M tests/orm.py => tests/orm.py +9 -1
@@ 177,4 177,12 @@ class BaseTestOrm(unittest.TestCase):
        data = Data.get(2)
        self.assertIsInstance(data, Data)
        self.assertIsInstance(data.data, JSON)
        self.assertDictEqual(data.data, {"b":3})
\ No newline at end of file
        self.assertDictEqual(data.data, {"b":3})

    @with_app_context
    def test_multiple_join(self):
        q = Post.query().select()
        q.join("utente", "post.utente = utente.id")
        q.join("utente as supervisor", "post.utente = supervisor.id")
        data = q.get()
        self.assertIsInstance(data, Post)
\ No newline at end of file

M tests/test_sqlbuilder.py => tests/test_sqlbuilder.py +5 -0
@@ 321,6 321,11 @@ class Sqlbuilder:
        with self.assertRaises(SqlBuilderException):
            self.q.join("tablea", "tableb")

    def test_join_multiple(self):
        q = self.q.join("tablea", "table" , "condition = condition")
        q = q.join("tableb", "condition = condition")
        self.assertEqual(q.sql(), "JOIN tablea ON condition = condition JOIN tableb ON condition = condition")


class TestSqlbuilderSqlite(Sqlbuilder, unittest.TestCase):
    def setUp(self):