Database and Queries¶
Example:
res = await User.get(User.mail == Unsafe(usermail)).exec(db)
u = res.single()
Shorter example:
u = await User.get(User.mail == Unsafe(usermail)).single(db)
For preprocessing a query, you can translate it into RawSql
, this is faster:
users_query = User.get(User.mail == Field("mail")).to_raw()
users = await users_query.with_data(mail = usermail).all(db)
Raw requests are also possible:
query = User.raw("SELECT * FROM table_User WHERE UID = %(name)s")
Or if you don’t like pyformat:
query = User.raw("SELECT * FROM table_User WHERE UID = {}".format(Field("name")))
u = await query.with_data(name = "evert").single(db)
You don’t have to mention a class:
query = RawSql("SELECT * FROM users WHERE name = 'Evert'")
More general and safer example:
query = RawSql("SELECT * FROM users WHERE name = %(name)s", {"name": some_user_data})
Reference¶
-
class
sparrow.sql.
And
(*conds)[source]¶ Bases:
sparrow.sql.MultiCondition
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶ Compile this to a RawSql instance for more performance!
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
ClassedSql
(cls: type, data={})[source]¶ Bases:
sparrow.sql.Sql
Version of Sql that also saves a given class. SqlResult will later try to parse its result as instances of this class.
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
Command
(cls: type, data={})[source]¶ Bases:
sparrow.sql.ClassedSql
For INSERT, DELETE, UPDATE, CREATE TABLE, DROP TABLE, ... statements.
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
Condition
(data={})[source]¶ Bases:
sparrow.sql.Sql
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶ Compile this to a RawSql instance for more performance!
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
CreateTable
(cls)[source]¶ Bases:
sparrow.sql.Command
For CREATE TABLE statements.
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
Database
(ioloop, dbname, user='postgres', password='postgres', host='localhost', port=5432, momoko_poolsize=5)[source]¶ Bases:
object
Class for Postgres database.
-
class
sparrow.sql.
Delete
(what)[source]¶ Bases:
sparrow.sql.Command
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
DropTable
(cls)[source]¶ Bases:
sparrow.sql.Command
For DROP TABLE statements.
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
EntityCommand
(cls: type, data={})[source]¶ Bases:
sparrow.sql.Command
Class for commands that work for both classes (will require inserting data later on) as objects.
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
Field
(name)[source]¶ Bases:
object
Wrapper for data that is to be inserted into the query (with Sql.with_data) later on.
-
class
sparrow.sql.
Insert
(what, returning=None, replace=False)[source]¶ Bases:
sparrow.sql.EntityCommand
For INSERT statements.
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
MultiCondition
(*conds)[source]¶ Bases:
sparrow.sql.Condition
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶ Compile this to a RawSql instance for more performance!
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
Not
(cond)[source]¶ Bases:
sparrow.sql.Condition
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶ Compile this to a RawSql instance for more performance!
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
exception
sparrow.sql.
NotSingle
[source]¶ Bases:
sparrow.util.Error
-
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
class
sparrow.sql.
Or
(*conds)[source]¶ Bases:
sparrow.sql.MultiCondition
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶ Compile this to a RawSql instance for more performance!
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
Order
(field, op: str, data={})[source]¶ Bases:
sparrow.sql.Sql
Encodes an ‘ORDER BY’ clause.
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶ Compile this to a RawSql instance for more performance!
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
RawClassedSql
(cls, text, data={})[source]¶ Bases:
sparrow.sql.RawSql
,sparrow.sql.ClassedSql
Version of RawSql that also saves a given class like ClassedSql.
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶ Already raw, just return self.
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
RawSql
(text, data={})[source]¶ Bases:
sparrow.sql.Sql
Simply saves a string, and also some data. This is in contrast with Sql, which may save the query in a more abstract way.
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
Select
(cls, where_clauses=[], order: sparrow.sql.Order=None, offset=None, limit=None)[source]¶ Bases:
sparrow.sql.ClassedSql
Encodes a ‘SELECT’ query.
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶
-
where
(*clauses)[source]¶ ‘OFFSET’ the query. Can be used for chaining.
Parameters: a number of Where clauses.
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
Sql
(data={})[source]¶ Bases:
object
Main class to save a given SQL query/command. Do not use directly, use the subclasses.
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)[source]¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
-
exception
sparrow.sql.
SqlError
(err: psycopg2.Error, query: 'Sql', data: dict)[source]¶ Bases:
sparrow.util.Error
Exception raised while executing a query (or command). Wraps a psycopg2 error to also include the query that went wrong.
-
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
class
sparrow.sql.
SqlResult
(cursor, query: 'Sql')[source]¶ Bases:
object
Class wrapping a database cursor. Note that most of the time, you can use the ‘easier’ methods in Sql. Instead of:
>>> res = await User.get(User.name == "Evert").exec(db) >>> u = res.single()
You can do:
>>> u = await User.get(User.name == "Evert").single(db)
This doesn’t work for scrolling and getting raw data.
The methods single, all and amount will try to interpret the result as object(s) of the given class in self.query.cls, don’t try them if it that class is None.
-
class
sparrow.sql.
Unsafe
(value)[source]¶ Bases:
object
Wrapper for unsafe data. (For data that needs to inserted later, use Field.)
-
class
sparrow.sql.
Update
(what)[source]¶ Bases:
sparrow.sql.EntityCommand
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-
-
class
sparrow.sql.
Where
(lfield, op: str, rfield, data={})[source]¶ Bases:
sparrow.sql.Condition
Encodes a single ‘WHERE’ clause.
-
all
()¶ Returns all objects in the query.
Wrapped version, first argument is the database.
-
amount
(i: int)¶ Returns a given number of objects in the query.
Wrapped version, first argument is the database.
-
check
(what)¶ Helper function to parse parts of a query and insert their data in self.data. Handles Unsafe, Field, other Sql instances and tuples. It will simply return all others types.
-
cls
= None¶
-
copy
()¶ Create a copy of the statement, by default uses copy.deepcopy.
-
count
()¶ Return the number of rows found in the query.
Wrapped version, first argument is the database.
-
exec
(db: sparrow.sql.Database=None)¶ Execute the SQL statement on the given database.
-
raw
()¶ - Returns the raw (single) result, without any interpreting. If you want to do more than getting a single raw value, consider accessing self.cursor directly.
Wrapped version, first argument is the database.
-
raw_all
()¶ Returns all raw values.
Wrapped version, first argument is the database.
-
single
()¶ Returns a single object (and raises NotSingle if there is not only one.
Wrapped version, first argument is the database.
-
to_raw
()¶ Compile this to a RawSql instance for more performance!
-
with_data
(**kwargs)¶ This function creates a copy of the statement with added data, passed as keyword arguments.
-