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


Python peewee.SQL属性代码示例

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


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

示例1: match_mysql

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def match_mysql(field, search_query):
    """
    Generates a full-text match query using a Match operation, which is needed for MySQL.
    """
    if field.name.find("`") >= 0:  # Just to be safe.
        raise Exception("How did field name '%s' end up containing a backtick?" % field.name)

    # Note: There is a known bug in MySQL (https://bugs.mysql.com/bug.php?id=78485) that causes
    # queries of the form `*` to raise a parsing error. If found, simply filter out.
    search_query = search_query.replace("*", "")

    # Just to be absolutely sure.
    search_query = search_query.replace("'", "")
    search_query = search_query.replace('"', "")
    search_query = search_query.replace("`", "")

    return NodeList(
        (fn.MATCH(SQL("`%s`" % field.name)), fn.AGAINST(SQL("%s", [search_query]))), parens=True
    ) 
开发者ID:quay,项目名称:quay,代码行数:21,代码来源:text.py

示例2: count

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def count(query, clear_limit=False):
    """Perform *COUNT* aggregated query asynchronously.

    :return: number of objects in ``select()`` query
    """
    clone = query.clone()
    if query._distinct or query._group_by or query._limit or query._offset:
        if clear_limit:
            clone._limit = clone._offset = None
        sql, params = clone.sql()
        wrapped = 'SELECT COUNT(1) FROM (%s) AS wrapped_select' % sql
        raw = query.model.raw(wrapped, *params)
        return (await scalar(raw)) or 0
    else:
        clone._returning = [peewee.fn.Count(peewee.SQL('*'))]
        clone._order_by = None
        return (await scalar(clone)) or 0 
开发者ID:05bit,项目名称:peewee-async,代码行数:19,代码来源:peewee_async.py

示例3: execute_sql

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def execute_sql(self, *args, **kwargs):
        """Sync execute SQL query, `allow_sync` must be set to True.
        """
        assert self._allow_sync, (
            "Error, sync query is not allowed! Call the `.set_allow_sync()` "
            "or use the `.allow_sync()` context manager.")
        if self._allow_sync in (logging.ERROR, logging.WARNING):
            logging.log(self._allow_sync,
                        "Error, sync query is not allowed: %s %s" %
                        (str(args), str(kwargs)))
        return super().execute_sql(*args, **kwargs)


##############
# PostgreSQL #
############## 
开发者ID:05bit,项目名称:peewee-async,代码行数:18,代码来源:peewee_async.py

示例4: add_not_null

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def add_not_null(db, migrator, table, column_name, field):
    cmds = []
    compiler = db.compiler()
    if field.default is not None:
      # if default is a function, turn it into a value
      # this won't work on columns requiring uniquiness, like UUIDs
      # as all columns will share the same called value
      default = field.default() if hasattr(field.default, '__call__') else field.default
      op = pw.Clause(pw.SQL('UPDATE'), pw.Entity(table), pw.SQL('SET'), field.as_entity(), pw.SQL('='), default, pw.SQL('WHERE'), field.as_entity(), pw.SQL('IS NULL'))
      cmds.append(compiler.parse_node(op))
    if is_postgres(db) or is_sqlite(db):
      junk = migrator.add_not_null(table, column_name, generate=True)
      cmds += normalize_whatever_junk_peewee_migrations_gives_you(migrator, junk)
      return cmds
    elif is_mysql(db):
      op = pw.Clause(pw.SQL('ALTER TABLE'), pw.Entity(table), pw.SQL('MODIFY'), compiler.field_definition(field))
      cmds.append(compiler.parse_node(op))
      return cmds
    raise Exception('how do i add a not null for %s?' % db) 
开发者ID:keredson,项目名称:peewee-db-evolve,代码行数:21,代码来源:peeweedbevolve.py

示例5: _execute

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def _execute(db, to_run, interactive=True, commit=True):
  if interactive: print()
  try:
    with db.atomic() as txn:
      for sql, params in to_run:
        if interactive or DEBUG: print_sql(' %s; %s' % (sql, params or ''))
        if sql.strip().startswith('--'): continue
        db.execute_sql(sql, params)
      if interactive:
        print()
        print(
          (colorama.Style.BRIGHT + 'SUCCESS!' + colorama.Style.RESET_ALL) if commit else 'TEST PASSED - ROLLING BACK',
          colorama.Style.DIM + '-',
          'https://github.com/keredson/peewee-db-evolve' + colorama.Style.RESET_ALL
        )
        print()
      if not commit:
        txn.rollback()
  except Exception as e:
    print()
    print('------------------------------------------')
    print(colorama.Style.BRIGHT + colorama.Fore.RED + ' SQL EXCEPTION - ROLLING BACK ALL CHANGES' + colorama.Style.RESET_ALL)
    print('------------------------------------------')
    print()
    raise e 
开发者ID:keredson,项目名称:peewee-db-evolve,代码行数:27,代码来源:peeweedbevolve.py

示例6: prefix_search

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def prefix_search(field, prefix_query):
    """
    Returns the wildcard match for searching for the given prefix query.
    """
    # Escape the known wildcard characters.
    prefix_query = _escape_wildcard(prefix_query)
    return Field.__pow__(field, NodeList((prefix_query + "%", SQL("ESCAPE '!'")))) 
开发者ID:quay,项目名称:quay,代码行数:9,代码来源:text.py

示例7: match_like

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def match_like(field, search_query):
    """
    Generates a full-text match query using an ILIKE operation, which is needed for SQLite and
    Postgres.
    """
    escaped_query = _escape_wildcard(search_query)
    clause = NodeList(("%" + escaped_query + "%", SQL("ESCAPE '!'")))
    return Field.__pow__(field, clause) 
开发者ID:quay,项目名称:quay,代码行数:10,代码来源:text.py

示例8: count

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def count(self, database, clear_limit=False):
        clone = self.order_by().alias('_wrapped')
        if clear_limit:
            clone._limit = clone._offset = None
        try:
            if clone._having is None and clone._windows is None and \
                            clone._distinct is None and clone._simple_distinct is not True:
                clone = clone.select(SQL('1'))
        except AttributeError:
            pass
        return Select([clone], [fn.COUNT(SQL('1'))]).scalar(database) 
开发者ID:snower,项目名称:torpeewee,代码行数:13,代码来源:query.py

示例9: exists

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def exists(self, database):
        clone = self.columns(SQL('1'))
        clone._limit = 1
        clone._offset = None
        return bool((await clone.scalar())) 
开发者ID:snower,项目名称:torpeewee,代码行数:7,代码来源:query.py

示例10: _run_sql

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def _run_sql(database, operation, *args, **kwargs):
    """Run SQL operation (query or command) against database.
    """
    __log__.debug((operation, args, kwargs))

    with peewee.__exception_wrapper__:
        cursor = await database.cursor_async()

        try:
            await cursor.execute(operation, *args, **kwargs)
        except:
            await cursor.release()
            raise

        return cursor 
开发者ID:05bit,项目名称:peewee-async,代码行数:17,代码来源:peewee_async.py

示例11: default_insert_clause

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def default_insert_clause(self, model_class):
        return SQL('DEFAULT VALUES') 
开发者ID:kszucs,项目名称:aiopeewee,代码行数:4,代码来源:database.py

示例12: test_select_all

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def test_select_all(flushdb):
    await create_users_blogs(2, 2)
    all_cols = SQL('*')
    query = Blog.select(all_cols)
    blogs = [blog async for blog in query.order_by(Blog.pk)]
    assert [b.title for b in blogs] == ['b-0-0', 'b-0-1', 'b-1-0', 'b-1-1']
    assert [(await b.user).username for b in blogs] == ['u0', 'u0', 'u1', 'u1'] 
开发者ID:kszucs,项目名称:aiopeewee,代码行数:9,代码来源:test_models.py

示例13: exists

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def exists(self):
        clone = self.paginate(1, 1)
        clone._select = [SQL('1')]
        return bool(await clone.scalar()) 
开发者ID:kszucs,项目名称:aiopeewee,代码行数:6,代码来源:query.py

示例14: set_default

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def set_default(db, migrator, table_name, column_name, field):
    default = field.default
    if callable(default): default = default()
    migration = ( migrator.make_context()
      .literal('UPDATE ').sql(pw.Entity(table_name))
      .literal(' SET ').sql(pw.Expression(pw.Entity(column_name), pw.OP.EQ, field.db_value(default), flat=True))
      .literal(' WHERE ').sql(pw.Expression(pw.Entity(column_name), pw.OP.IS, pw.SQL('NULL'), flat=True))
    )
    return extract_query_from_migration(migration) 
开发者ID:keredson,项目名称:peewee-db-evolve,代码行数:11,代码来源:peeweedbevolve.py

示例15: drop_table

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import SQL [as 别名]
def drop_table(migrator, table_name):
    compiler = migrator.database.compiler()
    return [compiler.parse_node(pw.Clause(pw.SQL('DROP TABLE'), pw.Entity(table_name)))] 
开发者ID:keredson,项目名称:peewee-db-evolve,代码行数:5,代码来源:peeweedbevolve.py


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