Exemplo n.º 1
0
    def test__function_between(self):
        c1 = fn.Coalesce(Field('foo'), 0)[0:1]
        c2 = fn.Coalesce(Field('foo', table=self.t), 0)[0:1]
        c3 = fn.Coalesce(Field('foo', table=self.t), 0).between(0, 1)

        self.assertEqual('COALESCE("foo",0) BETWEEN 0 AND 1', str(c1))
        self.assertEqual('COALESCE("btw"."foo",0) BETWEEN 0 AND 1', str(c2))
Exemplo n.º 2
0
    def test_coalesce(self):
        q = Q.from_('abc').select(fn.Coalesce(F('foo'), 0))

        self.assertEqual('SELECT COALESCE(\"foo\",0) FROM \"abc\"', str(q))
Exemplo n.º 3
0
    def test__function_notin(self):
        c1 = fn.Coalesce(Field('foo'), 0).notin([0, 1])
        c2 = fn.Coalesce(Field('foo', table=self.t), 0).notin([0, 1])

        self.assertEqual('COALESCE("foo",0) NOT IN (0,1)', str(c1))
        self.assertEqual('COALESCE("notin"."foo",0) NOT IN (0,1)', str(c2))
Exemplo n.º 4
0
    def test_coalesce(self):
        q = Q.from_("abc").select(fn.Coalesce(F("foo"), 0))

        self.assertEqual('SELECT COALESCE("foo",0) FROM "abc"', str(q))
Exemplo n.º 5
0
    def test__function_isin(self):
        c1 = fn.Coalesce(Field("foo"), 0).isin([0, 1])
        c2 = fn.Coalesce(Field("foo", table=self.t), 0).isin([0, 1])

        self.assertEqual('COALESCE("foo",0) IN (0,1)', str(c1))
        self.assertEqual('COALESCE("isin"."foo",0) IN (0,1)', str(c2))
Exemplo n.º 6
0
 def test_is_aggregate_None_for_non_aggregate_function_or_function_with_no_aggregate_functions(
         self):
     self.assertIsNone(fn.Coalesce('a', 0).is_aggregate)
     self.assertIsNone(fn.Coalesce(fn.NullIf('a', 0), 0).is_aggregate)
Exemplo n.º 7
0
 def test_is_aggregate_True_for_aggregate_function_or_function_with_aggregate_functions(
         self):
     self.assertTrue(fn.Sum('a').is_aggregate)
     self.assertTrue(fn.Coalesce(fn.Avg('a'), 0).is_aggregate)
     self.assertTrue(fn.Coalesce(fn.NullIf(fn.Sum('a'), 0), 0).is_aggregate)
Exemplo n.º 8
0
 def _default_dimension_definition(self, key):
     return fn.Coalesce(self.slicer.table.field(key), 'None')
Exemplo n.º 9
0
 def avg(self):
     return fn.Coalesce(fn.Avg(self.field.sql), 0, alias=self.alias)
Exemplo n.º 10
0
 def count(self):
     return fn.Coalesce(fn.Count(self.field.sql), 0, alias=self.alias)
Exemplo n.º 11
0
 def sum(self):
     return fn.Coalesce(fn.Sum(self.field.sql), 0, alias=self.alias)
Exemplo n.º 12
0
_q_get_organization = (q_organization(Parameter("$1")).select(
    "bootstrap_token", "root_verify_key", "expiration_date").get_sql())

_q_bootstrap_organization = (Query.update(t_organization).where(
    (t_organization.organization_id == Parameter("$1"))
    & (t_organization.bootstrap_token == Parameter("$2"))
    & (t_organization.root_verify_key.isnull())).set(
        t_organization.root_verify_key, Parameter("$3")).get_sql())

_q_get_stats = Query.select(
    Query.from_(t_user).where(
        t_user.organization == q_organization_internal_id(Parameter(
            "$1"))).select(fn.Count("*")).as_("users"),
    Query.from_(t_vlob_atom).where(
        t_vlob_atom.organization == q_organization_internal_id(Parameter(
            "$1"))).select(fn.Coalesce(fn.Sum(t_vlob_atom.size),
                                       0)).as_("metadata_size"),
    Query.from_(t_block).where(
        t_block.organization == q_organization_internal_id(Parameter(
            "$1"))).select(fn.Coalesce(fn.Sum(t_block.size),
                                       0)).as_("data_size"),
).get_sql()

_q_update_organisation_expiration_date = (Query.update(t_organization).where(
    (t_organization.organization_id == Parameter("$1"))).set(
        t_organization.expiration_date, Parameter("$2")).get_sql())


class PGOrganizationComponent(BaseOrganizationComponent):
    def __init__(self, dbh: PGHandler, **kwargs):
        super().__init__(**kwargs)
        self.dbh = dbh