5.2. Query classes¶
- class simplesqlite.query.Table(value: str)[source]¶
- Parameters:
name (str) – Table name.
- Returns:
String that suitable for table name of a SQLite query.
- Examples:
>>> from simplesqlite.query import Table >>> Table("length") 'length' >>> Table("length(cm)") '[length(cm)]' >>> Table("string length") "'string length'"
- class simplesqlite.query.Attr(name: str, operation: str = '')[source]¶
- Parameters:
- Returns:
String that suitable for attribute name of a SQLite query.
- Return type:
- Examples:
>>> from simplesqlite.query import Attr >>> Attr("key") 'key' >>> Attr("a+b") '[a+b]' >>> Attr("key", operation="SUM") 'SUM(key)'
- class simplesqlite.query.AttrList(names: Sequence[str], operation: str = '')[source]¶
- Parameters:
names (list/tuple) – Attribute names.
operation (str) – Used as a SQLite function if the value is not empty.
- Examples:
>>> from simplesqlite.query import AttrList >>> AttrList(["key", "a+b"])) ['key', '[a+b]'] >>> AttrList(["key", "a+b"], operation="AVG") ['AVG(key)', 'AVG([a+b])']
See also
- class simplesqlite.query.Value(value: Any)[source]¶
- class simplesqlite.query.Where(key: str | Column, value: Any, cmp_operator: str = '=')[source]¶
WHERE
query clause.- Parameters:
- Raises:
simplesqlite.SqlSyntaxError – If a)
cmp_operator
is invalid operator. Valid operators are as follows:"="
,"=="
,"!="
,"<>"
,">"
,">="
,"<"
,"<="
. b) thevalue
isNone
and thecmp_operator
is not"="
/"!="
.- Examples:
>>> from simplesqlite.query import Where >>> Where("key", "hoge") "key = 'hoge'" >>> Where("value", 1, cmp_operator=">") 'value > 1'
- class simplesqlite.query.Select(select: str | AttrList, table: str, where: str | Where | And | Or | None = None, extra: str | None = None)[source]¶
SELECT
query clause.- Parameters:
- Raises:
ValueError –
select
is empty string.simplesqlite.NameValidationError – If the name is invalid for a SQLite table name.
- Examples:
>>> from simplesqlite.query import Select, Where >>> Select(select="value", table="example") 'SELECT value FROM example' >>> Select(select="value", table="example", where=Where("key", 1)) 'SELECT value FROM example WHERE key = 1' >>> Select(select="value", table="example", where=Where("key", 1), extra="ORDER BY value") 'SELECT value FROM example WHERE key = 1 ORDER BY value'