dblite  1.3.0
Simple query interface for SQL databases
dblite.engines.postgres Namespace Reference

Classes

class  Database
 Convenience wrapper around psycopg2.ConnectionPool and Cursor. More...
 
class  Identifier
 Wrapper for table and column names from data objects. More...
 
class  Queryable
 
class  RowFactoryCursor
 A cursor that generates result rows via given factory callable. More...
 
class  Transaction
 Transaction context manager, provides convenience methods for queries. More...
 

Functions

def autodetect (opts)
 Returns true if input is recognizable as Postgres connection options. More...
 
def make_db_url (opts)
 Returns Postgres connection options as URL, like `"postgresql://host/dbname"`. More...
 
def query_schema (queryable, keys=False, views=False, inheritance=False)
 Returns database table structure populated from given database. More...
 
def quote (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 register_adapter (transformer, typeclasses)
 Registers function to auto-adapt given Python types to Postgres types in query parameters. More...
 
def register_converter (transformer, typenames)
 Registers function to auto-convert given Postgres types to Python types in query results. More...
 
def register_row_factory (row_factory)
 Registers custom row factory, as or `None` to reset to default. More...
 

Variables

list RESERVED_KEYWORDS
 Postgres reserved keywords, needing quotes in SQL queries. More...
 

Function Documentation

◆ autodetect()

def dblite.engines.postgres.autodetect (   opts)

Returns true if input is recognizable as Postgres connection options.

Parameters
optsexpected as URL string `"postgresql://user@localhost/mydb"` or keyword=value format string like `"host=localhost dbname=.."` or a dictionary of `dict(host="localhost", dbname=..)`

Definition at line 825 of file postgres.py.

◆ make_db_url()

def dblite.engines.postgres.make_db_url (   opts)

Returns Postgres connection options as URL, like `"postgresql://host/dbname"`.

Definition at line 834 of file postgres.py.

◆ query_schema()

def dblite.engines.postgres.query_schema (   queryable,
  keys = False,
  views = False,
  inheritance = False 
)

Returns database table structure populated from given database.

Parameters
queryableDatabase or Transaction instance
viewswhether to include views
keyswhether to include primary and foreign key information
inheritancewhether to include parent-child table information and populate inherited foreign keys
Returns
```{table or view name: { "fields": OrderedDict({ column { "name": column name, "type": column type name, ?"pk": True, ?"fk": foreign table name, } }), ?"key": primary key column name, ?"parent": parent table name, ?"children": [child table name, ], "type": "table" or "view", } }```

Definition at line 875 of file postgres.py.

◆ quote()

def dblite.engines.postgres.quote (   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

Definition at line 943 of file postgres.py.

◆ register_adapter()

def dblite.engines.postgres.register_adapter (   transformer,
  typeclasses 
)

Registers function to auto-adapt given Python types to Postgres types in query parameters.

Definition at line 957 of file postgres.py.

◆ register_converter()

def dblite.engines.postgres.register_converter (   transformer,
  typenames 
)

Registers function to auto-convert given Postgres types to Python types in query results.

Definition at line 969 of file postgres.py.

◆ register_row_factory()

def dblite.engines.postgres.register_row_factory (   row_factory)

Registers custom row factory, as or `None` to reset to default.

Definition at line 979 of file postgres.py.

Variable Documentation

◆ RESERVED_KEYWORDS

list dblite.engines.postgres.RESERVED_KEYWORDS
Initial value:
1 = [
2  "ALL", "ANALYSE", "ANALYZE", "AND", "ANY", "ARRAY", "AS", "ASC", "ASYMMETRIC", "AUTHORIZATION",
3  "BINARY", "BOTH", "CASE", "CAST", "CHECK", "COLLATE", "COLLATION", "COLUMN", "CONCURRENTLY",
4  "CONSTRAINT", "CREATE", "CROSS", "CURRENT_CATALOG", "CURRENT_DATE", "CURRENT_ROLE",
5  "CURRENT_SCHEMA", "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURRENT_USER", "DEFAULT", "DEFERRABLE",
6  "DESC", "DISTINCT", "DO", "ELSE", "END", "EXCEPT", "FALSE", "FETCH", "FOR", "FOREIGN", "FREEZE",
7  "FROM", "FULL", "GRANT", "GROUP", "HAVING", "ILIKE", "IN", "INITIALLY", "INNER", "INTERSECT",
8  "INTO", "IS", "ISNULL", "JOIN", "LATERAL", "LEADING", "LEFT", "LIKE", "LIMIT", "LOCALTIME",
9  "LOCALTIMESTAMP", "NATURAL", "NOT", "NOTNULL", "NULL", "OFFSET", "ON", "ONLY", "OR", "ORDER",
10  "OUTER", "OVERLAPS", "PLACING", "PRIMARY", "REFERENCES", "RETURNING", "RIGHT", "SELECT",
11  "SESSION_USER", "SIMILAR", "SOME", "SYMMETRIC", "TABLE", "TABLESAMPLE", "THEN", "TO",
12  "TRAILING", "TRUE", "UNION", "UNIQUE", "USER", "USING", "VARIADIC", "VERBOSE",
13  "WHEN", "WHERE", "WINDOW", "WITH"
14 ]

Postgres reserved keywords, needing quotes in SQL queries.

Definition at line 38 of file postgres.py.