示例#1
0
    def __new__(cls, *args, **kwargs):
        if not args:
            # python3k pickle seems to call this
            return object.__new__(cls)

        table = super(ForeignTable, cls).__new__(cls, *args, **kwargs)
        metadata = args[1]
        table.pgfdw_server = kwargs.pop('pgfdw_server', None)
        table.pgfdw_options = kwargs.pop('pgfdw_options', None) or {}
        if 'FOREIGN' not in table._prefixes:
            table._prefixes.append('FOREIGN')

        if not hasattr(metadata, '_foreign_tables'):
            metadata._foreign_tables = {}

        metadata._foreign_tables[table.key] = table

        autoload = kwargs.get('autoload', False)
        autoload_with = kwargs.get('autoload_with', None)
        if autoload:
            if autoload_with:
                autoload_with.run_callable(
                    autoload_with.dialect.get_foreign_table_options, table)
            else:
                bind = _bind_or_error(
                    table.metadata,
                    msg="No engine is bound to this ForeignTable's MetaData. "
                    "Pass an engine to the Table via "
                    "autoload_with=<someengine>, "
                    "or associate the MetaData with an engine via "
                    "metadata.bind=<someengine>")
                bind.run_callable(bind.dialect.get_foreign_table_options,
                                  table)
        return table
示例#2
0
 def create(self, bind=None, checkfirst=False, if_not_exists=False):
     if bind is None:
         bind = _bind_or_error(self)
     bind._run_ddl_visitor(ddl.SchemaGenerator,
                           self,
                           checkfirst=checkfirst,
                           if_not_exists=if_not_exists)
示例#3
0
    def __new__(cls, *args, **kwargs):
        if not args:
            # python3k pickle seems to call this
            return object.__new__(cls)

        table = super(ForeignTable, cls).__new__(cls, *args, **kwargs)
        metadata = args[1]
        table.pgfdw_server = kwargs.pop('pgfdw_server', None)
        table.pgfdw_options = kwargs.pop('pgfdw_options', None) or {}
        table._prefixes.append('FOREIGN')

        if not hasattr(metadata, '_foreign_tables'):
            metadata._foreign_tables = {}

        metadata._foreign_tables[table.key] = table

        autoload = kwargs.get('autoload', False)
        autoload_with = kwargs.get('autoload_with', None)
        if autoload:
            if autoload_with:
                autoload_with.run_callable(
                    autoload_with.dialect.get_foreign_table_options,
                    table)
            else:
                bind = _bind_or_error(
                    table.metadata,
                    msg="No engine is bound to this ForeignTable's MetaData. "
                    "Pass an engine to the Table via "
                    "autoload_with=<someengine>, "
                    "or associate the MetaData with an engine via "
                    "metadata.bind=<someengine>")
                bind.run_callable(
                    bind.dialect.get_foreign_table_options, table)
        return table
示例#4
0
 def drop(self, bind=None, checkfirst=False, if_exists=False):
     if bind is None:
         bind = _bind_or_error(self)
     bind._run_visitor(ddl.SchemaDropper,
                       self,
                       checkfirst=checkfirst,
                       if_exists=if_exists)
示例#5
0
    def exists(self, bind=None):
        """Return True if this table exists."""
        if bind is None:
            bind = _bind_or_error(self)

        return bind.run_callable(bind.dialect.has_table,
                                 self.name,
                                 schema=self.schema)
示例#6
0
    def drop(self, bind=None, checkfirst=False, cascade=False):
        """Drop the server

        :param: bind: (optional) The bind to use instead of the instance one
        :param: checkfirst: Check if the server exists before dropping it.
        :param: cascade: appends the CASCADE keyword to the drop statement.

        """
        if bind is None:
            bind = _bind_or_error(self)
        if not checkfirst or self.check_existence(bind):
            DropForeignDataWrapper(
                self.name, self.extension_name, bind=bind, cascade=cascade
            ).execute()
示例#7
0
    def create(self, bind=None, checkfirst=False):
        """Create the server.

        :param: bind: (optional) The bind to use instead of the instance one
        :param: checkfirst: Check if the server exists before creating it.

        """

        if bind is None:
            bind = _bind_or_error(self)
        if not checkfirst or not self.check_existence(bind):
            CreateForeignDataWrapper(
                self.name, self.extension_name, bind=bind, options=self.options
            ).execute()
示例#8
0
    def check_existence(self, bind=None):
        """Checks if a server with the same name already exists.

        :param: bind: (optional) if not bind is supplied, the current binding
                      (from the metatadata) will be used.

        """
        if bind is None:
            bind = _bind_or_error(self)
        bindparams = [
            sql.bindparam('name', str(self.name), type_=types.Unicode)]
        cursor = bind.execute(sql.text("select srvname from pg_foreign_server "
                                       "where srvname = :name",
                              bindparams=bindparams))
        return bool(cursor.first())
示例#9
0
    def drop(self, bind=None, checkfirst=False, cascade=False):
        """Drop the server

        :param: bind: (optional) The bind to use instead of the instance one
        :param: checkfirst: Check if the server exists before dropping it.
        :param: cascade: appends the CASCADE keyword to the drop statement.

        """
        if bind is None:
            bind = _bind_or_error(self)
        if not checkfirst or self.check_existence(bind):
            DropForeignDataWrapper(self.name,
                                   self.extension_name,
                                   bind=bind,
                                   cascade=cascade).execute()
示例#10
0
    def create(self, bind=None, checkfirst=False):
        """Create the server.

        :param: bind: (optional) The bind to use instead of the instance one
        :param: checkfirst: Check if the server exists before creating it.

        """

        if bind is None:
            bind = _bind_or_error(self)
        if not checkfirst or not self.check_existence(bind):
            CreateForeignDataWrapper(self.name,
                                     self.extension_name,
                                     bind=bind,
                                     options=self.options).execute()
示例#11
0
    def check_existence(self, bind=None):
        """Checks if a server with the same name already exists.

        :param: bind: (optional) if not bind is supplied, the current binding
                      (from the metatadata) will be used.

        """
        if bind is None:
            bind = _bind_or_error(self)
        bindparams = [
            sql.bindparam('name', str(self.name), type_=types.Unicode)
        ]
        cursor = bind.execute(
            sql.text(
                "select srvname from pg_foreign_server "
                "where srvname = :name",
                bindparams=bindparams))
        return bool(cursor.first())
示例#12
0
 def drop(self, bind=None, checkfirst=False):
     if bind is None:
         bind = _bind_or_error(self)
     bind._run_visitor(SchemaDropperWithTextIndex,
                       self,
                       checkfirst=checkfirst)
示例#13
0
 async def create(self, bind=None, *args, **kwargs):
     if bind is None:
         bind = _bind_or_error(self._item)
     await getattr(bind, "_run_visitor")(AsyncSchemaGenerator, self._item,
                                         *args, **kwargs)
     return self._item
示例#14
0
 def create(self, bind=None):
     if bind is None:
         bind = _bind_or_error(self)
     bind._run_visitor(SchemaGeneratorWithTextIndex, self)
     return self
示例#15
0
 def create(self, bind=None, checkfirst=False):
     if bind is None:
         bind = _bind_or_error(self)
     bind._run_visitor(SchemaGeneratorWithTextIndex,
                       self,
                       checkfirst=checkfirst)
示例#16
0
 def drop(self, bind=None, checkfirst=False):
     if bind is None:
         bind = _bind_or_error(self)
     bind._run_visitor(SchemaDropperWithTextIndex,
                       self,
                       checkfirst=checkfirst)
示例#17
0
 async def drop(self, bind=None, *args, **kwargs):
     if bind is None:
         bind = _bind_or_error(self._item)
     await getattr(bind, "_run_visitor")(AsyncSchemaDropper, self._item,
                                         *args, **kwargs)
示例#18
0
 def create(self, bind=None):
     if bind is None:
         bind = _bind_or_error(self)
     bind._run_visitor(SchemaGeneratorWithTextIndex, self)
     return self
示例#19
0
 async def drop_async(self, bind=None, checkfirst=False):
     if bind is None:
         bind = _bind_or_error(self)
     t = self.dialect_impl(bind.dialect)
     if t.__class__ is not self.__class__ and isinstance(t, SchemaType):
         await t.drop_async(bind=bind, checkfirst=checkfirst)
示例#20
0
 def create(self, bind=None, checkfirst=False):
     if bind is None:
         bind = _bind_or_error(self)
     bind._run_visitor(SchemaGeneratorWithTextIndex,
                       self,
                       checkfirst=checkfirst)