當前位置: 首頁>>代碼示例>>Python>>正文


Python Structure.get_foreign_key_for_table方法代碼示例

本文整理匯總了Python中structure.Structure.get_foreign_key_for_table方法的典型用法代碼示例。如果您正苦於以下問題:Python Structure.get_foreign_key_for_table方法的具體用法?Python Structure.get_foreign_key_for_table怎麽用?Python Structure.get_foreign_key_for_table使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在structure.Structure的用法示例。


在下文中一共展示了Structure.get_foreign_key_for_table方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _get_rel_data_restricted

# 需要導入模塊: from structure import Structure [as 別名]
# 或者: from structure.Structure import get_foreign_key_for_table [as 別名]
 def _get_rel_data_restricted(self, sql):
     attr, pk = self._restricted_table_attr, self._get_pk()
     relation_fk = Structure.get_foreign_key_for_table(attr, self._table_name)
     sql.add_where_condition(relation_fk, self.data[pk])
     data = Query().execute_and_fetch(**sql.build_select())
     from resultset import ResultSet
     return ResultSet(data, attr)
開發者ID:davekr,項目名稱:pypg,代碼行數:9,代碼來源:row.py

示例2: _get_rel_data_restricted

# 需要導入模塊: from structure import Structure [as 別名]
# 或者: from structure.Structure import get_foreign_key_for_table [as 別名]
 def _get_rel_data_restricted(self, sql):
     saved = self._restricted_table_call
     table_name, relation, pk, pk_value = saved['table_name'], saved['relation'], saved['pk'], saved['pk_value']
     relation_fk = Structure.get_foreign_key_for_table(relation, table_name)
     if not self._cache.relation_exists(table_name, relation):
         if sql._select_args:
             sql.add_select_arg(Column(relation, relation_fk))
         if sql._limit:
             union_sql = []
             union_parameters = []
             union_dict = {}
             for id in self._cache.get_all_keys(table_name, pk):
                 limiting_sql = copy.deepcopy(sql)
                 limiting_sql.add_where_literal(Column(relation, relation_fk) == id)
                 union_dict = limiting_sql.build_select() 
                 union_sql.append('(%s)' % union_dict['sql'])
                 union_parameters.extend(union_dict['parameters'])
             union_dict['sql'], union_dict['parameters'] = ' UNION '.join(union_sql), union_parameters
             data = Query().execute_and_fetch(**union_dict)
             self._cache.save_relation(table_name, relation, data)
         else:
             sql.add_where_literal(Column(relation, relation_fk).in_(self._cache.get_all_keys(table_name, pk)))
             data = Query().execute_and_fetch(**sql.build_select())
             self._cache.save_relation(table_name, relation, data)
     return ResultSet(self._cache.get_relation_set(relation, relation_fk, pk_value), relation, self._cache)
開發者ID:davekr,項目名稱:pypg,代碼行數:27,代碼來源:resultset.py

示例3: join

# 需要導入模塊: from structure import Structure [as 別名]
# 或者: from structure.Structure import get_foreign_key_for_table [as 別名]
 def join(self, table, on=None):
     self._check_is_instance(table, 'Table')
     if on:
         self._check_is_instance(on, 'Literal')
         self._validate_on(table, on)
     else:
         Structure.tables_related(self._table_name, table._table_name)
         try:
             fk = Structure.get_foreign_key_for_table(self._table_name, table._table_name)
         except PyPgException:
             fk = Structure.get_foreign_key_for_table(table._table_name, self._table_name)
             on = Column(table._table_name, fk) == \
                     Column(self._table_name, Structure.get_primary_key(self._table_name))
         else:
             on = Column(self._table_name, fk) == \
                     Column(table._table_name, Structure.get_primary_key(table._table_name))
     self._sql.add_join(table._table_name, on)
     return self._table_select_instance()
開發者ID:davekr,項目名稱:pypg,代碼行數:20,代碼來源:table.py


注:本文中的structure.Structure.get_foreign_key_for_table方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。