def drop(self, bind=None, checkfirst=False): from sqlalchemy.schema import _bind_or_error if bind is None: bind = _bind_or_error(self) t = self.dialect_impl(bind.dialect) if t is not self: t.drop(bind=bind, checkfirst=checkfirst)
def execute(self, bind=None, schema_item=None): """ Exécute la requête ou la série de requêtes associées à cet objet. @param bind: Connexion à la base de données maître. @type bind: C{Connectable} @param schema_item: Élément du modèle sur lequel porte la modification. @type schema_item: C{Table} @return: Résultat de l'exécution de la requête sur le nœud maître. @rtype: C{ResultProxy} """ if bind is None: bind = _bind_or_error(self) if self._should_execute(None, schema_item, bind): if hasattr(self, '_expand'): # SQLAlchemy 0.5. statement = self._expand(schema_item, bind) res = bind.execute(expression.text(statement)) else: # SQLAlchemy 0.6. res = bind.execute(self.against(schema_item)) return res
def __new__(cls, *args, **kwargs): fdw_server = fdw_server = kwargs.pop('fdw_server', None) fdw_options = kwargs.pop('fdw_options', {}) table = super(ForeignTable, cls).__new__(cls, *args, **kwargs) 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) table._prefixes.append('FOREIGN') if fdw_server: table.fdw_server = fdw_server if fdw_options: table.fdw_options = fdw_options return table
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', unicode(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())