Python sqlalchemy.ext.declarative.api.DeclarativeMeta() Examples
The following are 5
code examples of sqlalchemy.ext.declarative.api.DeclarativeMeta().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sqlalchemy.ext.declarative.api
, or try the search function
.
Example #1
Source File: pt.py From uszipcode-project with MIT License | 6 votes |
def from_everything(everything, engine, limit=None): """ Construct a Prettytable from any kinds of sqlalchemy query. """ if isinstance(everything, Table): return from_table(everything, engine, limit=limit) if type(everything) is DeclarativeMeta: return from_object(everything, engine, limit=limit) if isinstance(everything, Query): return from_query(everything, engine, limit=limit) if isinstance(everything, Select): return from_sql(everything, engine, limit=limit) if isinstance(everything, ResultProxy): return from_resultproxy(everything) if isinstance(everything, list): return from_data(everything)
Example #2
Source File: test_base.py From scoringengine with MIT License | 5 votes |
def test_base_class(self): assert isinstance(Base, DeclarativeMeta)
Example #3
Source File: gen.py From news_spider with MIT License | 5 votes |
def gen_items(): """ 创建 items $ python gen.py gen_items 字段规则: 去除自增主键,非自增是需要的。 """ from models import news file_path = os.path.join(BASE_DIR, 'news/items.py') model_list = [(k, v) for k, v in news.__dict__.items() if isinstance(v, DeclarativeMeta) and k != 'Base'] with open(file_path, b'w') as f: f.write(b'# -*- coding: utf-8 -*-\n\n') f.write(b'# Define here the models for your scraped items\n#\n') f.write(b'# See documentation in:\n') f.write(b'# http://doc.scrapy.org/en/latest/topics/items.html\n\n') f.write(b'import scrapy\n') for model_name, model_class in model_list: result = model_class().to_dict() table_name = model_class().__tablename__ model_pk = inspect(model_class).primary_key[0].name f.write(b'\n\nclass %sItem(scrapy.Item):\n' % model_name) f.write(b' """\n') f.write(b' table_name: %s\n' % table_name) f.write(b' primary_key: %s\n' % model_pk) f.write(b' """\n') for field_name in list(result.keys()): if field_name in [model_pk, 'create_time', 'update_time']: continue f.write(b' %s = scrapy.Field()\n' % field_name)
Example #4
Source File: base.py From asgard-api with MIT License | 5 votes |
def to_alchemy_obj( self ) -> Tuple[DeclarativeMeta, Type[DeclarativeMeta]]: raise NotImplementedError
Example #5
Source File: __init__.py From pyramid-jsonapi with GNU Affero General Public License v3.0 | 4 votes |
def create_resource(self, model, collection_name=None, expose_fields=None): """Produce a set of resource endpoints. Arguments: model: a model class derived from DeclarativeMeta. Keyword Args: collection_name: string name of collection. Passed through to ``collection_view_factory()`` expose_fields: set of field names to be exposed. Passed through to ``collection_view_factory()`` """ # Find the primary key column from the model and use as 'id_col_name' try: keycols = sqlalchemy.inspect(model).primary_key except sqlalchemy.exc.NoInspectionAvailable: # Trying to inspect the declarative_base() raises this exception. We # don't want to add it to the API. return # Only deal with one primary key column. if len(keycols) > 1: raise Exception( 'Model {} has more than one primary key.'.format( model.__name__ ) ) if not hasattr(model, '__pyramid_jsonapi__'): model.__pyramid_jsonapi__ = {} if 'id_col_name' not in model.__pyramid_jsonapi__: model.__pyramid_jsonapi__['id_col_name'] = keycols[0].name # Create a view class for use in the various add_view() calls below. view = self.collection_view_factory(model, collection_name or getattr( model, '__pyramid_jsonapi__', {} ).get('collection_name') or sqlalchemy.inspect(model).tables[-1].name, expose_fields=expose_fields) self.view_classes[model] = view view.default_limit = int(self.settings.paging_default_limit) view.max_limit = int(self.settings.paging_max_limit) self.endpoint_data.add_routes_views(view)