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
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)
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
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)
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)
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()
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()
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())
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()
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()
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())
def drop(self, bind=None, checkfirst=False): if bind is None: bind = _bind_or_error(self) bind._run_visitor(SchemaDropperWithTextIndex, self, checkfirst=checkfirst)
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
def create(self, bind=None): if bind is None: bind = _bind_or_error(self) bind._run_visitor(SchemaGeneratorWithTextIndex, self) return self
def create(self, bind=None, checkfirst=False): if bind is None: bind = _bind_or_error(self) bind._run_visitor(SchemaGeneratorWithTextIndex, self, checkfirst=checkfirst)
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)
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)