当前位置: 首页>>代码示例>>Python>>正文


Python peewee.SqliteDatabase方法代码示例

本文整理汇总了Python中peewee.SqliteDatabase方法的典型用法代码示例。如果您正苦于以下问题:Python peewee.SqliteDatabase方法的具体用法?Python peewee.SqliteDatabase怎么用?Python peewee.SqliteDatabase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在peewee的用法示例。


在下文中一共展示了peewee.SqliteDatabase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: apply_migration

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def apply_migration(step):
    import peewee
    import playhouse.migrate
    from hotline.database import models

    migrations_module = importlib.import_module(
        f".{step}", package="hotline.database.migrations"
    )

    if isinstance(models.db.obj, peewee.SqliteDatabase):
        migrator = playhouse.migrate.SqliteMigrator(models.db)
    else:
        migrator = playhouse.migrate.PostgresqlMigrator(models.db)

    migrations = migrations_module.migrate(migrator)

    print(f"The following migrations are about to be applied to {models.db.obj}:")
    for migration in migrations:
        print(" * ", migration.method, migration.args)

    input("Press enter to continue.")

    playhouse.migrate.migrate(*migrations)

    print("Done.") 
开发者ID:theacodes,项目名称:conducthotline.com,代码行数:27,代码来源:app.py

示例2: create_db_connection

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def create_db_connection():
    """ Creates a database connection with the postgres db"""

    is_test_env = os.getenv('MQTT_PWN_TESTING_ENV')

    if is_test_env:
        db = SqliteDatabase(':memory:')
    else:
        db = PostgresqlDatabase(
            config.DB_NAME,
            user=config.DB_USER,
            password=config.DB_PASSWORD,
            host=config.DB_HOST,
            port=config.DB_PORT
        )

    database_proxy.initialize(db)

    return db 
开发者ID:akamai-threat-research,项目名称:mqtt-pwn,代码行数:21,代码来源:database.py

示例3: change_license_field_type

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def change_license_field_type(migrator, db):
    if isinstance(db, peewee.SqliteDatabase):
        # SQLite has not length
        return

    try:
        migrate(migrator.drop_column('packageversion', 'license_old'))
    except:
        pass

    with db.transaction():
        migrate(
            migrator.rename_column('packageversion', 'license', 'license_old'),
            migrator.add_column("packageversion", 'license', PackageVersion.license),
        )

        db.execute_sql("UPDATE packageversion SET license = license_old")
        migrate(migrator.drop_column('packageversion', 'license_old')) 
开发者ID:mosquito,项目名称:pypi-server,代码行数:20,代码来源:006_packageversion_license_textfield.py

示例4: __init__

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def __init__(self, data_model):
        self.data_model = data_model
        self.data_model.fake_item_ids_store = self

        assert self.data_model.cache_dir, "FakeItemIds need cache_dir from data_model!"
        sqlite_path = os.path.join(self.data_model.cache_dir, "fake_item_ids_store.db")

        sqlite_database = SqliteDatabase(sqlite_path, check_same_thread=False)

        class FakeItemIdsStore(Model):
            is_deleted = BooleanField(default=False)  # mark processed or duplicated items
            item_id = CharField()
            item_content_json = TextField()
            created_at = TimeField(default=datetime.datetime.now)

            class Meta:
                database = sqlite_database
        self.storage = FakeItemIdsStore

        if not self.storage.table_exists():
            self.storage.create_table()
            sqlite_database.create_index(self.storage, "is_deleted item_id".split(" ")) 
开发者ID:17zuoye,项目名称:detdup,代码行数:24,代码来源:fake_item_ids.py

示例5: db

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def db():
    return pw.SqliteDatabase(':memory:') 
开发者ID:f213,项目名称:selfmailbot,代码行数:4,代码来源:conftest.py

示例6: __init__

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def __init__(self):
        self.path = None
        self.db = SqliteDatabase(None) 
开发者ID:maxking,项目名称:paper-to-git,代码行数:5,代码来源:database.py

示例7: main

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def main():

    # Init database
    dbpath = os.path.join(SETTINGS_DIR, "settings.db")
    print("Using database " + dbpath)
    sqlite_db = peewee.SqliteDatabase(dbpath)
    init_db(sqlite_db)

    app = RestaticApp(sys.argv, single_app=True)
    app.updater = get_updater()
    sys.exit(app.exec_()) 
开发者ID:Mebus,项目名称:restatic,代码行数:13,代码来源:__main__.py

示例8: app

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def app(tmpdir, qtbot):
    tmp_db = tmpdir.join("settings.sqlite")
    mock_db = peewee.SqliteDatabase(str(tmp_db))
    restatic.models.init_db(mock_db)
    app = RestaticApp([])
    qtbot.addWidget(app.main_window)
    return app 
开发者ID:Mebus,项目名称:restatic,代码行数:9,代码来源:conftest.py

示例9: get_db_conn

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def get_db_conn():
    import peewee
    env = os.environ.get('SENTINEL_ENV', 'production')

    # default values should be used unless you need a different config for development
    db_host = sentinel_cfg.get('db_host', '127.0.0.1')
    db_port = sentinel_cfg.get('db_port', None)
    db_name = sentinel_cfg.get('db_name', 'sentinel')
    db_user = sentinel_cfg.get('db_user', 'sentinel')
    db_password = sentinel_cfg.get('db_password', 'sentinel')
    db_charset = sentinel_cfg.get('db_charset', 'utf8mb4')
    db_driver = sentinel_cfg.get('db_driver', 'sqlite')

    if (env == 'test'):
        if db_driver == 'sqlite':
            db_name = sqlite_test_db_name(db_name)
        else:
            db_name = "%s_test" % db_name

    peewee_drivers = {
        'mysql': peewee.MySQLDatabase,
        'postgres': peewee.PostgresqlDatabase,
        'sqlite': peewee.SqliteDatabase,
    }
    driver = peewee_drivers.get(db_driver)

    dbpfn = 'passwd' if db_driver == 'mysql' else 'password'
    db_conn = {
        'host': db_host,
        'user': db_user,
        dbpfn: db_password,
    }
    if db_port:
        db_conn['port'] = int(db_port)

    if driver == peewee.SqliteDatabase:
        db_conn = {}

    db = driver(db_name, **db_conn)

    return db 
开发者ID:dashpay,项目名称:sentinel,代码行数:43,代码来源:config.py

示例10: __init__

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def __init__(self, *_, **__):
        super(SqliteDatabase, self).__init__(*_, **__) 
开发者ID:ga4gh,项目名称:ga4gh-server,代码行数:4,代码来源:models.py

示例11: _create_database

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def _create_database(self):
        return SqliteDatabase(
            self.database_path, pragmas={"foreign_keys": 1, "secure_delete": 1}
        ) 
开发者ID:matrix-org,项目名称:pantalaimon,代码行数:6,代码来源:store.py

示例12: init_sqlite

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def init_sqlite(url):
    global DB

    dbfile = os.path.join("/", *url.path.split("/"))
    dirname = os.path.dirname(dbfile)

    log.info('Opening sqlite database: %s', dbfile)

    if not os.path.exists(dirname):
        os.makedirs(dirname)

    DB.initialize(SqliteDatabase(dbfile))
    log.info("Database initialized as '%s'. Checking migrations...", dbfile)
    return DB, SqliteMigrator(DB) 
开发者ID:mosquito,项目名称:pypi-server,代码行数:16,代码来源:__init__.py

示例13: main

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def main():
    args = parse_args()
    signal.signal(signal.SIGINT, signal.SIG_DFL)  # catch ctrl-c and exit

    want_version = getattr(args, 'version', False)
    want_background = getattr(args, 'daemonize', False)

    if want_version:
        print(f"Vorta {__version__}")
        sys.exit()

    if want_background:
        if os.fork():
            sys.exit()

    init_logger(background=want_background)

    # Init database
    sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db'))
    init_db(sqlite_db)

    # Init app after database is available
    from vorta.application import VortaApp
    app = VortaApp(sys.argv, single_app=True)
    app.updater = get_updater()

    sys.exit(app.exec_()) 
开发者ID:borgbase,项目名称:vorta,代码行数:29,代码来源:__main__.py

示例14: qapp

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def qapp(tmpdir_factory, local_en):
    tmp_db = tmpdir_factory.mktemp('Vorta').join('settings.sqlite')
    mock_db = peewee.SqliteDatabase(str(tmp_db))
    vorta.models.init_db(mock_db)

    from vorta.application import VortaApp
    VortaApp.set_borg_details_action = MagicMock()  # Can't use pytest-mock in session scope
    VortaApp.scheduler = MagicMock()

    qapp = VortaApp([])  # Only init QApplication once to avoid segfaults while testing.

    yield qapp 
开发者ID:borgbase,项目名称:vorta,代码行数:14,代码来源:conftest.py

示例15: get_database

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SqliteDatabase [as 别名]
def get_database(self):
        """Returns the correct database driver

        Returns:
            :obj:`pw.Database`
        Raises:
            AttributeError: if `--username` or `--password` not passed
                (if `--dbtype [postgres|mysql]`)

        """
        if self.get('dbtype') == 'sqlite':
            return pw.SqliteDatabase(self.get('dbname'),
                                     pragmas={'journal_mode': 'wal',
                                              'cache_size': -1 * 64000})
        else:
            if self.get('username') is None or self.get('password') is None:
                raise AttributeError('[ERROR] dbtype %s requires username and'
                                     ' password.\n' % str(self.get('dbtype')))
            if self.get('hostname') is None:
                self.set('hostname', 'localhost')
            if self.get('dbtype') == 'mysql':
                if self.get('port') is None or self.get('port') == '':
                    self.set('port', str(3306))
                return pw.MySQLDatabase(
                    self.get('dbname'),
                    user=self.get('username'),
                    password=self.get('password'),
                    host=self.get('hostname'),
                    port=int(self.get('port')))
            elif self.get('dbtype') == 'postgres':
                if self.get('port') is None or self.get('port') == '':
                    self.set('port', str(5432))
                return pw.PostgresqlDatabase(
                    self.get('dbname'),
                    user=self.get('username'),
                    password=self.get('password'),
                    host=self.get('hostname'),
                    port=int(self.get('port'))) 
开发者ID:HadrienG,项目名称:taxadb,代码行数:40,代码来源:schema.py


注:本文中的peewee.SqliteDatabase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。