Exemplo n.º 1
0
    q_block(organization_id=Parameter("$1"), block_id=Parameter("$2"))
    .select(
        "deleted_on",
        q_user_can_read_vlob(
            user=q_user_internal_id(organization_id=Parameter("$1"), user_id=Parameter("$3")),
            realm=t_block.realm,
        ),
    )
    .get_sql()
)


_q_get_block_write_right_and_unicity = Query.select(
    q_user_can_write_vlob(
        user=q_user_internal_id(organization_id=Parameter("$1"), user_id=Parameter("$2")),
        realm=q_realm_internal_id(organization_id=Parameter("$1"), realm_id=Parameter("$3")),
    ),
    fn_exists(q_block(organization_id=Parameter("$1"), block_id=Parameter("$4"))),
).get_sql()


_q_insert_block = (
    Query.into(t_block)
    .columns("organization", "block_id", "realm", "author", "size", "created_on")
    .insert(
        q_organization_internal_id(Parameter("$1")),
        Parameter("$2"),
        q_realm_internal_id(organization_id=Parameter("$1"), realm_id=Parameter("$3")),
        q_device_internal_id(organization_id=Parameter("$1"), device_id=Parameter("$4")),
        Parameter("$5"),
        Parameter("$6"),
Exemplo n.º 2
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)