Пример #1
0
    def add_privs(self):
        """Generate SQL statements to grant privileges on new column

        :return: list of SQL statements
        """
        return [add_grant(self._table, priv, self.name)
                for priv in self.privileges]
Пример #2
0
    def add_privs(self):
        """Generate SQL statements to grant privileges on new column

        :return: list of SQL statements
        """
        stmts = []
        if hasattr(self, 'privileges'):
            for priv in self.privileges:
                stmts.append(add_grant(self._table, priv, self.name))
        return stmts
Пример #3
0
    def create(self):
        """Return SQL statements to CREATE the table

        :return: SQL statements
        """
        stmts = []
        if hasattr(self, 'created'):
            return stmts
        cols = []
        colprivs = []
        for col in self.columns:
            if not (hasattr(col, 'inherited') and col.inherited):
                cols.append("    " + col.add()[0])
            colprivs.append(col.add_privs())
        unlogged = ''
        if hasattr(self, 'unlogged') and self.unlogged:
            unlogged = 'UNLOGGED '
        inhclause = ''
        if hasattr(self, 'inherits'):
            inhclause = " INHERITS (%s)" % ", ".join(t for t in self.inherits)
        opts = ''
        if hasattr(self, 'options'):
            opts = " WITH (%s)" % ', '.join(self.options)
        tblspc = ''
        if hasattr(self, 'tablespace'):
            tblspc = " TABLESPACE %s" % self.tablespace
        stmts.append("CREATE %sTABLE %s (\n%s)%s%s%s" % (
            unlogged, self.qualname(), ",\n".join(cols), inhclause, opts,
            tblspc))
        if hasattr(self, 'owner'):
            stmts.append(self.alter_owner())
        if hasattr(self, 'privileges'):
            for priv in self.privileges:
                stmts.append(add_grant(self, priv))
        if colprivs:
            stmts.append(colprivs)
        if hasattr(self, 'description'):
            stmts.append(self.comment())
        for col in self.columns:
            if hasattr(col, 'description'):
                stmts.append(col.comment())
        self.created = True
        return stmts
Пример #4
0
 def grant(obj, *args, **kwargs):
     stmts = func(obj, *args, **kwargs)
     if hasattr(obj, 'privileges'):
         for priv in obj.privileges:
             stmts.append(add_grant(obj, priv))
     return stmts
Пример #5
0
 def grant(obj, *args, **kwargs):
     stmts = func(obj, *args, **kwargs)
     for priv in obj.privileges:
         stmts.append(add_grant(obj, priv))
     return stmts