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


Python peewee.IntegerField方法代碼示例

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


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

示例1: _create_model

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import IntegerField [as 別名]
def _create_model(self, db, table_prefix):
        """
        創建數據model
        """
        meta_dict = {
            "database": db,
            "table_name": table_prefix + "_" + "Report"
        }
        meta = type("Meta", (object, ), meta_dict)
        model_dict = {
            "id": peewee.AutoField(),
            "plugin_name": peewee.CharField(max_length=63),
            "description": peewee.TextField(),
            "rasp_result_list": self.LongTextField(),
            "payload_seq": peewee.CharField(unique=True, max_length=63),
            "message": peewee.TextField(),
            "time": peewee.IntegerField(default=common.get_timestamp),
            "upload": peewee.IntegerField(default=0),
            "Meta": meta
        }
        self.Report = type("Report", (peewee.Model, ), model_dict)
        return self.Report 
開發者ID:baidu-security,項目名稱:openrasp-iast,代碼行數:24,代碼來源:report_model.py

示例2: _create_model

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import IntegerField [as 別名]
def _create_model(self, db, table_prefix):
        """
        創建數據model
        """
        meta_dict = {
            "database": db,
            "table_name": table_prefix + "_" + "ResultList"
        }

        meta = type("Meta", (object, ), meta_dict)
        model_dict = {
            "id": peewee.AutoField(),
            "data": self.LongTextField(),
            # utf8mb4 編碼下 1 char = 4 bytes,會導致peewee創建過長的列導致MariaDB產生 1071, Specified key was too long; 錯誤, max_length不使用255
            "data_hash": peewee.CharField(unique=True, max_length=63),
            # scan_status含義: 未掃描:0, 已掃描:1, 正在掃描:2, 掃描中出現錯誤: 3
            "scan_status": peewee.IntegerField(default=0),
            "time": peewee.IntegerField(default=common.get_timestamp),
            "Meta": meta
        }
        self.ResultList = type("ResultList", (peewee.Model, ), model_dict)
        return self.ResultList 
開發者ID:baidu-security,項目名稱:openrasp-iast,代碼行數:24,代碼來源:new_request_model.py

示例3: test_has_index

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import IntegerField [as 別名]
def test_has_index(self):
        """Check method returns False and True when either table or index
        does not exist"""
        from taxadb.schema import BaseModel
        import peewee as pw

        class FooBar(BaseModel):
            id = pw.IntegerField(null=False)
            name = pw.CharField()

        idx = FooBar.index(FooBar.name, name='name')
        FooBar.add_index(idx)
        obj = self._buildTaxaDBObject(TaxaDB)
        # Test returns False
        self.assertFalse(FooBar.has_index(name='foo'))
        FooBar.create_table(fail_silently=True)
        self.assertFalse(FooBar.has_index(name='foo'))
        self.assertFalse(FooBar.has_index())
        self.assertFalse(FooBar.has_index(columns=10))
        # Test returns True
        self.assertTrue(FooBar.has_index(name='name'))
        FooBar.drop_table() 
開發者ID:HadrienG,項目名稱:taxadb,代碼行數:24,代碼來源:test_taxadb.py

示例4: test_order_by_inheritance

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import IntegerField [as 別名]
def test_order_by_inheritance():
    class Base(TestModel):
        created = DateTimeField()

        class Meta:
            order_by = ('-created',)

    class Foo(Base):
        data = CharField()

    class Bar(Base):
        val = IntegerField()
        class Meta:
            order_by = ('-val',)

    foo_order_by = Foo._meta.order_by[0]
    assert isinstance(foo_order_by, Field)
    assert foo_order_by.model_class is Foo
    assert foo_order_by.name == 'created'

    bar_order_by = Bar._meta.order_by[0]
    assert isinstance(bar_order_by, Field)
    assert bar_order_by.model_class is Bar
    assert bar_order_by.name == 'val' 
開發者ID:kszucs,項目名稱:aiopeewee,代碼行數:26,代碼來源:test_models.py

示例5: test_change_int_column_to_fk

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import IntegerField [as 別名]
def test_change_int_column_to_fk(self):
    class Person(pw.Model):
      class Meta:
        database = self.db
    class Car(pw.Model):
      owner_id = pw.IntegerField(null=False)
      class Meta:
        database = self.db
    self.evolve_and_check_noop()
    person = Person.create()
    car = Car.create(owner_id=person.id)
    peeweedbevolve.unregister(Car)
    class Car(pw.Model):
      owner = foreign_key(Person, null=False)
      class Meta:
        database = self.db
    self.evolve_and_check_noop()
    self.assertEqual(Car.select().first().owner_id, person.id)
    self.assertRaises(Exception, lambda: Car.create(owner=-1)) 
開發者ID:keredson,項目名稱:peewee-db-evolve,代碼行數:21,代碼來源:test.py

示例6: test_change_fk_column_to_int

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import IntegerField [as 別名]
def test_change_fk_column_to_int(self):
    class Person(pw.Model):
      class Meta:
        database = self.db
    class Car(pw.Model):
      owner = foreign_key(Person, null=False)
      class Meta:
        database = self.db
    self.evolve_and_check_noop()
    person = Person.create()
    car = Car.create(owner=person)
    peeweedbevolve.unregister(Car)
    class Car(pw.Model):
      owner_id = pw.IntegerField(null=False)
      class Meta:
        database = self.db
    self.evolve_and_check_noop()
    self.assertEqual(Car.select().first().owner_id, person.id)
    Car.create(owner_id=-1) # this should not fail 
開發者ID:keredson,項目名稱:peewee-db-evolve,代碼行數:21,代碼來源:test.py

示例7: test_change_integer_to_fake_fk_column

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import IntegerField [as 別名]
def test_change_integer_to_fake_fk_column(self):
    class Person(pw.Model):
      class Meta:
        database = self.db
    class Car(pw.Model):
      owner_id = pw.IntegerField(null=False)
      class Meta:
        database = self.db
    self.evolve_and_check_noop()
    car = Car.create(owner_id=-1)
    peeweedbevolve.unregister(Car)
    class Car(pw.Model):
      owner = foreign_key(Person, null=False, fake=True)
      class Meta:
        database = self.db
    self.evolve_and_check_noop()
    person = Person.create()
    car = Car.create(owner=-2)
    self.assertEqual(Car.select().count(), 2) 
開發者ID:keredson,項目名稱:peewee-db-evolve,代碼行數:21,代碼來源:test.py

示例8: test_table_exists_failed

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import IntegerField [as 別名]
def test_table_exists_failed(self):
        """Check the method throws SystemExit if a table does not exist"""
        from taxadb.schema import BaseModel
        import peewee as pw

        class NotFound(BaseModel):
            id = pw.IntegerField(null=False)
            name = pw.CharField()
        obj = self._buildTaxaDBObject(TaxaDB)
        with self.assertRaises(SystemExit):
            obj.check_table_exists(NotFound) 
開發者ID:HadrienG,項目名稱:taxadb,代碼行數:13,代碼來源:test_taxadb.py

示例9: field_class_to_schematics_field

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import IntegerField [as 別名]
def field_class_to_schematics_field(field: peewee.Field) -> BaseType:
    if isinstance(field, peewee.ForeignKeyField):
        field = field.rel_field

    kwargs = {}

    # 檢查是否 require
    if not ((field.default is not None) or field.null or field.sequence or isinstance(field, peewee.AutoField)):
        kwargs['required'] = True

    if field.help_text:
        kwargs['metadata'] = {'description': field.help_text}

    if isinstance(field, peewee.IntegerField):
        return IntType(**kwargs)
    elif isinstance(field, peewee.FloatField):
        return FloatType(**kwargs)
    elif isinstance(field, (PG_JSONField, PG_BinaryJSONField, SQLITE_JSONField)):
        # 注意 SQLITE_JSONField 是一個 _StringField 所以要提前
        return JSONType(**kwargs)
        # HStore 貌似才應該對應 dict,json可以對應任意類型
        # return JSONDictType(StringType, **kwargs)
    elif isinstance(field, peewee.DateTimeField):
        return DateTimeType(**kwargs)
    elif isinstance(field, peewee.DateField):
        return DateType(**kwargs)
    elif isinstance(field, peewee._StringField):
        return StringType(**kwargs)
    elif isinstance(field, peewee.BooleanField):
        return BooleanType(**kwargs)
    elif isinstance(field, peewee.BlobField):
        return BlobType(**kwargs)
    elif isinstance(field, PG_ArrayField):
        field: PG_ArrayField
        return JSONListType(field_class_to_schematics_field(field._ArrayField__field), **kwargs)


# noinspection PyProtectedMember 
開發者ID:fy0,項目名稱:slim,代碼行數:40,代碼來源:validate.py

示例10: test_composite_key_no_change

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import IntegerField [as 別名]
def test_composite_key_no_change(self):
    class SomeModel(pw.Model):
      x = pw.IntegerField()
      y = pw.IntegerField()
      class Meta:
        primary_key = pw.CompositeKey('x', 'y')
        database = self.db
    self.evolve_and_check_noop() 
開發者ID:keredson,項目名稱:peewee-db-evolve,代碼行數:10,代碼來源:test.py

示例11: app

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import IntegerField [as 別名]
def app(request):
    from peewee import SqliteDatabase, Model, CharField, IntegerField, ForeignKeyField
    from sanic import Sanic
    from sanic.log import log

    from sanic_crud import generate_crud

    db = SqliteDatabase('tests/test.db')

    class BaseModel(Model):
        class Meta:
            database = db

    class Job(BaseModel):
        name = CharField()
        description = CharField()
        base_pay = IntegerField()

    class Person(BaseModel):
        name = CharField()
        job = ForeignKeyField(Job, related_name='person_job', null=True)
        email = CharField()

    db.create_tables([Person, Job])
    job = Job(name='Space garbage man', description='Collects garbage in space', base_pay=15)
    person = Person(name='Sanic the Hedgehog', email='gottagofeast@fast.com', job=1)
    job.save()
    person.save()

    test_app = Sanic(__name__)

    test_app.log = log
    generate_crud(test_app, [Person, Job])

    def final():
        db.drop_tables([Person, Job])

    request.addfinalizer(final)
    return test_app 
開發者ID:Typhon66,項目名稱:sanic_crud,代碼行數:41,代碼來源:conftest.py

示例12: app

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import IntegerField [as 別名]
def app(request):
    from peewee import SqliteDatabase, Model, CharField, IntegerField, ForeignKeyField
    from sanic import Sanic
    from sanic.log import log

    from sanic_crud import generate_crud
    from sanic_crud.config import CrudConfig, ResponseMessages

    db = SqliteDatabase('tests/test.db')

    class BaseModel(Model):
        class Meta:
            database = db

    class Job(BaseModel):
        name = CharField()
        description = CharField()
        base_pay = IntegerField()

    class Person(BaseModel):
        name = CharField()
        job = ForeignKeyField(Job, related_name='person_job', null=True)
        email = CharField()

    db.create_tables([Person, Job])
    job = Job(name='Space garbage man', description='Collects garbage in space', base_pay=15)
    job2 = Job(name='Space Trucker', description='Transfers things... in space', base_pay=25)
    person = Person(name='Sanic the Hedgehog', email='gottagofeast@fast.com', job=1)
    job.save()
    job2.save()
    person.save()

    test_app = Sanic(__name__)
    test_app.log = log
    config = CrudConfig
    response_messages = ResponseMessages
    response_messages.SuccessOk = "Cool Brah"
    config.response_messages = response_messages
    config.COLLECTION_MAX_RESULTS_PER_PAGE = 1
    generate_crud(test_app, [Person, Job])

    def final():
        db.drop_tables([Person, Job])

    request.addfinalizer(final)
    return test_app 
開發者ID:Typhon66,項目名稱:sanic_crud,代碼行數:48,代碼來源:conftest.py

示例13: build_features_tree

# 需要導入模塊: import peewee [as 別名]
# 或者: from peewee import IntegerField [as 別名]
def build_features_tree(self):
        from peewee import SqliteDatabase, Model, IntegerField, CharField, BooleanField

        # built or connect database
        sqlite_path = {
                "memory" : ":memory:",
                "disk"   : self.sqlite3db_path(),
        }[self.link_to_detdup.storage_type]
        sqlite_database = SqliteDatabase(sqlite_path, check_same_thread=False)

        class BaseFeaturesTree(Model):
            uniq_chars__len     = IntegerField(default=0)
            sqrt_chars__len     = IntegerField(default=0)
            sorted_freq_chars   = CharField()
# TODO support item_id as int or str type
            item_id             = CharField()

            class Meta:
                database = sqlite_database
        self.features_tree = BaseFeaturesTree

        tablename = "_".join(self.custom_features).capitalize() or "DefaultFeaturesTree"

        # If customize more features
        if self.custom_features:
            self.features_tree = type(tablename, (BaseFeaturesTree,), dict())
            for feature_k1 in self.custom_features:
                # http://stackoverflow.com/questions/22358489/dynamically-define-fields-in-a-peewee-model
                feature_v1 = self.custom_features[feature_k1]
                # Compact with (int) instance
                if type(feature_v1) is int: feature_v1 = int
                field1 = {int: IntegerField, str: CharField}[feature_v1]()
                field1.add_to_class(self.features_tree, feature_k1)

        self.features_tree._meta.db_table = tablename

        # create table and indexes
        if not self.features_tree.table_exists():
            self.features_tree.create_table()
            sqlite_database.create_index(self.features_tree, "item_id".split(" "))

# TODO 讓大str在前麵,加快索引搜索速度
            index_columns = self.default_features.keys() + self.custom_features.keys()
            sqlite_database.create_index(self.features_tree, index_columns)

        print "[build_features_tree]", self.features_tree, "self.default_features :", self.default_features, "self.custom_features :", self.custom_features
        print 
開發者ID:17zuoye,項目名稱:detdup,代碼行數:49,代碼來源:default.py


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