dblite  1.3.0
Simple query interface for SQL databases
dblite.api.Queryable Class Reference

Abstract base for Database and Transaction. More...

Inheritance diagram for dblite.api.Queryable:
Inheritance graph

Public Member Functions

def delete (self, table, where=(), **kwargs)
 Convenience wrapper for database DELETE, returns affected row count. More...
 
def execute (self, sql, args=())
 Executes the SQL statement and returns database cursor. More...
 
def executemany (self, sql, args)
 Executes the SQL statement against all parameter sequences. More...
 
def executescript (self, sql)
 Executes the SQL as script of any number of statements. More...
 
def fetchall (self, table, cols="*", where=(), group=(), order=(), limit=(), **kwargs)
 Convenience wrapper for database SELECT and fetch all. More...
 
def fetchone (self, table, cols="*", where=(), group=(), order=(), limit=(), **kwargs)
 Convenience wrapper for database SELECT and fetch one. More...
 
def insert (self, table, values=(), **kwargs)
 Convenience wrapper for database INSERT, returns inserted row ID. More...
 
def insertmany (self, table, rows=(), **kwargs)
 Convenience wrapper for database multiple INSERTs, returns list of inserted row IDs. More...
 
def makeSQL (self, action, table, cols="*", where=(), group=(), order=(), limit=(), values=(), kwargs=None)
 Returns (SQL statement string, parameter dict). More...
 
def quote (cls, value, force=False)
 Returns identifier in quotes and proper-escaped for queries, if value needs quoting (has non-alphanumerics, starts with number, or is reserved). More...
 
def select (self, table, cols="*", where=(), group=(), order=(), limit=(), **kwargs)
 Convenience wrapper for database SELECT, returns database cursor. More...
 
def update (self, table, values, where=(), **kwargs)
 Convenience wrapper for database UPDATE, returns affected row count. More...
 

Static Public Attributes

 ENGINE = None
 Underlying database engine, "sqlite" for SQLite3 and "postgres" for PostgreSQL. More...
 

Properties

 closed = property
 Whether currently not open. More...
 
 cursor = property
 Database engine cursor object, or `None` if closed. More...
 

Detailed Description

Abstract base for Database and Transaction.

Definition at line 237 of file api.py.

Member Function Documentation

◆ delete()

def dblite.api.Queryable.delete (   self,
  table,
  where = (),
**  kwargs 
)

Convenience wrapper for database DELETE, returns affected row count.

Keyword arguments are added to WHERE.

Definition at line 300 of file api.py.

◆ execute()

def dblite.api.Queryable.execute (   self,
  sql,
  args = () 
)

Executes the SQL statement and returns database cursor.

Parameters
sqlSQL statement to execute, with engine-specific parameter bindings, if any
argsquery parameters, as tuple or dictionary

Reimplemented in dblite.engines.postgres.Transaction, dblite.engines.sqlite.Transaction, dblite.engines.postgres.Database, and dblite.engines.sqlite.Database.

Definition at line 311 of file api.py.

◆ executemany()

def dblite.api.Queryable.executemany (   self,
  sql,
  args 
)

Executes the SQL statement against all parameter sequences.

Parameters
sqlSQL statement to execute, with engine-specific parameter bindings
argsiterable of query parameters, as dictionaries for named placeholders or sequences for positional placeholders

Reimplemented in dblite.engines.postgres.Transaction, dblite.engines.sqlite.Transaction, dblite.engines.postgres.Database, and dblite.engines.sqlite.Database.

Definition at line 321 of file api.py.

◆ executescript()

def dblite.api.Queryable.executescript (   self,
  sql 
)

Executes the SQL as script of any number of statements.

Note that in SQLite, the statements are executed outside of transaction, and any pending transaction will be committed first.

Parameters
sqlscript with one or more SQL statements

Reimplemented in dblite.engines.postgres.Transaction, dblite.engines.sqlite.Transaction, dblite.engines.postgres.Database, and dblite.engines.sqlite.Database.

Definition at line 333 of file api.py.

◆ fetchall()

def dblite.api.Queryable.fetchall (   self,
  table,
  cols = "*",
  where = (),
  group = (),
  order = (),
  limit = (),
**  kwargs 
)

Convenience wrapper for database SELECT and fetch all.

Keyword arguments are added to WHERE.

Definition at line 248 of file api.py.

◆ fetchone()

def dblite.api.Queryable.fetchone (   self,
  table,
  cols = "*",
  where = (),
  group = (),
  order = (),
  limit = (),
**  kwargs 
)

Convenience wrapper for database SELECT and fetch one.

Keyword arguments are added to WHERE.

Definition at line 256 of file api.py.

◆ insert()

def dblite.api.Queryable.insert (   self,
  table,
  values = (),
**  kwargs 
)

Convenience wrapper for database INSERT, returns inserted row ID.

Keyword arguments are added to VALUES.

Reimplemented in dblite.engines.postgres.Queryable, and dblite.engines.sqlite.Queryable.

Definition at line 265 of file api.py.

◆ insertmany()

def dblite.api.Queryable.insertmany (   self,
  table,
  rows = (),
**  kwargs 
)

Convenience wrapper for database multiple INSERTs, returns list of inserted row IDs.

Keyword arguments are added to VALUES of every single row, overriding individual row values.

Reimplemented in dblite.engines.postgres.Queryable, and dblite.engines.sqlite.Queryable.

Definition at line 273 of file api.py.

◆ makeSQL()

def dblite.api.Queryable.makeSQL (   self,
  action,
  table,
  cols = "*",
  where = (),
  group = (),
  order = (),
  limit = (),
  values = (),
  kwargs = None 
)

Returns (SQL statement string, parameter dict).

Reimplemented in dblite.engines.postgres.Queryable, and dblite.engines.sqlite.Queryable.

Definition at line 337 of file api.py.

◆ quote()

def dblite.api.Queryable.quote (   cls,
  value,
  force = False 
)

Returns identifier in quotes and proper-escaped for queries, if value needs quoting (has non-alphanumerics, starts with number, or is reserved).

Parameters
valuethe value to quote, returned as-is if not string
forcewhether to quote value even if not required

Reimplemented in dblite.engines.postgres.Queryable, and dblite.engines.sqlite.Queryable.

Definition at line 367 of file api.py.

◆ select()

def dblite.api.Queryable.select (   self,
  table,
  cols = "*",
  where = (),
  group = (),
  order = (),
  limit = (),
**  kwargs 
)

Convenience wrapper for database SELECT, returns database cursor.

Keyword arguments are added to WHERE.

Definition at line 281 of file api.py.

◆ update()

def dblite.api.Queryable.update (   self,
  table,
  values,
  where = (),
**  kwargs 
)

Convenience wrapper for database UPDATE, returns affected row count.

Keyword arguments are added to WHERE.

Definition at line 291 of file api.py.

Member Data Documentation

◆ ENGINE

dblite.api.Queryable.ENGINE = None
static

Underlying database engine, "sqlite" for SQLite3 and "postgres" for PostgreSQL.

Definition at line 241 of file api.py.

Property Documentation

◆ closed

dblite.api.Queryable.closed = property
static

Whether currently not open.

Definition at line 345 of file api.py.

◆ cursor

dblite.api.Queryable.cursor = property
static

Database engine cursor object, or `None` if closed.

Definition at line 353 of file api.py.


The documentation for this class was generated from the following file: