selecting

This module provide utility functions for select operation.

sqlalchemy_mate.crud.selecting.count_row(engine, table)[source]

Return number of rows in a table.

Example:

>>> count_row(engine, table_user)
3

中文文档

返回一个表中的行数。

sqlalchemy_mate.crud.selecting.select_all(engine, table)[source]

Select everything from a table.

Example:

>>> list(select_all(engine, table_user))
[(1, "Alice"), (2, "Bob"), (3, "Cathy")]

中文文档

选取所有数据。

sqlalchemy_mate.crud.selecting.select_single_column(engine, column)[source]

Select data from single column.

Example:

>>> select_single_column(engine, table_user.c.id)
[1, 2, 3]

>>> select_single_column(engine, table_user.c.name)
["Alice", "Bob", "Cathy"]
sqlalchemy_mate.crud.selecting.select_many_column(engine, *columns)[source]

Select data from multiple columns.

Example:

>>> select_many_column(engine, table_user.c.id, table_user.c.name)
Parameters:columns – list of sqlalchemy.Column instance
Returns headers:
 headers
Returns data:list of row

中文文档

返回多列中的数据。

sqlalchemy_mate.crud.selecting.select_distinct_column(engine, *columns)[source]

Select distinct column(columns).

Returns:if single column, return list, if multiple column, return matrix.

中文文档

distinct语句的语法糖函数。

sqlalchemy_mate.crud.selecting.select_random(engine, table_or_columns, limit=5)[source]

Randomly select some rows from table.