class Meta: # pylint: disable=missing-class-docstring database = _DATABASE legacy_table_names = False # This will become a default in peewee>=4 primary_key = peewee.CompositeKey("channel", "feed", "url") indexes = ( # (('channel', 'feed', 'url'), True), # Not needed per EXPLAIN QUERY PLAN due to sqlite_autoindex_post_1. (("channel", "url"), False), ) # True means unique.
class Meta: database = _DATABASE_V2 legacy_table_names = False # This will become a default in peewee>=4 primary_key = peewee.CompositeKey('channel', 'feed', 'url') indexes = ( # (('channel', 'feed', 'url'), True), # Not needed per EXPLAIN QUERY PLAN due to sqlite_autoindex_post_1. (('channel', 'url'), False), ) # True means unique.
class Meta: indexes = [ pv.SQL( "CREATE INDEX idx_templates_name_ntid on templates (name, ntid)" ), pv.SQL("CREATE INDEX idx_templates_usn on templates (usn)"), ] primary_key = pv.CompositeKey("ntid", "ord") without_rowid = True
class Meta: primary_key = peewee.CompositeKey( 'endpoint', 'marketplace_id', 'refresh_token', 'aws_access_key', 'path', 'data', 'params', 'method', ) database = db_proxy
def primary_key(self, name): """ Add a primary key to the model. This has some special cases, which is why it's not handled like all the other column types. :param name: Name of column. :return: None """ meta = self.model._meta pk_field = peewee.CompositeKey([name]) meta.primary_key = pk_field meta.add_field(name, pk_field) field = peewee.AutoField(column_name=name) meta.add_field(name, field)
class Meta: db_table = 'relations' primary_key = peewee.CompositeKey( 'entity_one_type', 'entity_one_id', 'entity_two_type', 'entity_two_id', 'role', ) indexes = ( (('entity_one_type', 'entity_one_id', 'entity_two_type', 'entity_two_id', 'role'), True), (('entity_two_type', 'entity_two_id', 'entity_one_type', 'entity_one_id', 'role'), True), )
class Meta: primary_key = pw.CompositeKey('source', 'is_official', 'spec') # 复合主键
class Meta: primary_key = pw.CompositeKey('section', 'order')
class Meta: primary_key = pw.CompositeKey('member', 'case')
class Meta: primary_key = pw.CompositeKey('price_range', 'brand')
class Meta: db_table = 'user_product' primary_key = pw.CompositeKey('user_id', 'product_id')
class Meta: database = db primary_key = pw.CompositeKey('project', 'pycampista')
class Meta: database = db primary_key = pw.CompositeKey('project', 'owner')
def reflect(self): """Adds fields and indexes to the model using reflection.""" meta = self._meta database = meta.database table_name = meta.table_name schema = meta.schema if not database or not database.connected: return # Lists tables in the schema. This is a bit of a hack but # faster than using database.table_exists because it's cached. database.get_fields(table_name, schema) # Force caching of _metadata. schema_tables = database._metadata[schema].keys() if table_name not in schema_tables: return for index in meta.indexes: if hasattr(index, 'reflected') and index.reflected: meta.indexes.remove(index) if not database.is_connection_usable(): raise peewee.DatabaseError('database not connected.') if hasattr(meta, 'reflection_options'): opts = meta.reflection_options skip_fks = opts.get('skip_foreign_keys', False) use_peewee_reflection = opts.get('use_peewee_reflection', True) else: skip_fks = False use_peewee_reflection = True try: if use_peewee_reflection: # Check for locks. We only need to do this if using the Peewee # reflection because one of the queries it does can be blocked # by a AccessExclusiveLock lock. locks = is_table_locked(database, table_name) if locks and 'AccessExclusiveLock' in locks: warnings.warn( f'table {schema}.{table_name} is locked and ' 'will not be reflected.', SdssdbUserWarning) return introspector = database.get_introspector(schema) reflected_model = introspector.generate_models( table_names=[table_name])[table_name] fields = reflected_model._meta.fields else: fields = database.get_fields(table_name, schema) fields = {field.column_name: field for field in fields} except KeyError as ee: warnings.warn( f'reflection failed for {table_name}: ' f'table or column {ee} not found.', SdssdbUserWarning) return except Exception as ee: warnings.warn(f'reflection failed for {table_name}: {ee}', SdssdbUserWarning) return for field_name, field in fields.items(): if field_name in keyword.kwlist: field_name += '_' if field_name in meta.fields: meta_field = meta.fields[field_name] if not getattr(meta_field, 'reflected', False): continue if isinstance(field, peewee.ForeignKeyField) and skip_fks: continue if field.primary_key: meta.set_primary_key(field_name, field) else: meta.add_field(field_name, field) meta.fields[field_name].reflected = True # Composite keys are not a normal column so if the pk has not been # set already, check if it exists in the reflected model. We avoid # adding pks that are foreign keys. if not meta.primary_key: if use_peewee_reflection and reflected_model._meta.primary_key: pk = reflected_model._meta.primary_key if not isinstance(pk, peewee.ForeignKeyField) or not skip_fks: meta.set_primary_key(pk.name, pk) elif not use_peewee_reflection: pk = database.get_primary_keys(table_name, schema) if len(pk) > 1: pk = peewee.CompositeKey(*pk) meta.set_primary_key('__composite_key__', pk)
class Meta: primary_key = peewee.CompositeKey("multicloud_stack", "cloud_name")
class Meta: database = db primary_key = pw.CompositeKey('url', 'group')
class Meta: db_table = "karma_user" primary_key = pw.CompositeKey("userid", "chatid")
class Meta: database = data_db primary_key = peewee.CompositeKey('address', 'perm_type')
class Meta: primary_key = pw.CompositeKey('party', 'case')
class Meta: db_table = 'user_task' primary_key = pw.CompositeKey('user_id', 'task_id')
class Meta: primary_key = pw.CompositeKey('brand', 'model')
class Meta: db_table = 'weather' primary_key = peewee.CompositeKey('city_id', 'wdate')
class Meta: primary_key = pw.CompositeKey('entity', 'element', 'start', 'end')
class Meta: primary_key = pw.CompositeKey('image', 'tag')
class Meta: database = proxy primary_key = peewee.CompositeKey('serie_id', 'indice_tiempo')
class Meta: """This class defines a composite key as the primary key.""" logger.info( "Set primary key to combo of person_employed & start_date fields.\n" ) primary_key = pw.CompositeKey('person_employed', 'start_date')
class Meta(S.BaseMeta): database = db primary_key = pw.CompositeKey('subject_id', 'text')
class Meta: ''' Metaclass to assign the primary key ''' primary_key = pw.CompositeKey('party', 'case')
class Meta: primary_key = pw.CompositeKey('shop_code', 'sku')
class Meta: database = db primary_key = peewee.CompositeKey('chat_id', 'link')