zoom.database module¶
zoom.database
a database that does less
-
class
zoom.database.Database(factory, *args, **keywords)¶ Bases:
objectdatabase object
>>> import sqlite3 >>> db = database('sqlite3', database=':memory:') >>> db('drop table if exists person') >>> db(""" ... create table if not exists person ( ... id integer primary key autoincrement, ... name varchar(100), ... age smallint, ... kids smallint, ... birthdate date, ... salary decimal(8,2) ... ) ... """)
>>> db("insert into person (name, age) values ('Joe',32)") 1
>>> db('select * from person') [(1, 'Joe', 32, None, None, None)]
>>> print(db('select * from person')) id name age kids birthdate salary -- ---- --- ---- --------- ------ 1 Joe 32 None None None
>>> create_person_table = """ ... create table if not exists person ( ... id integer primary key autoincrement, ... name varchar(100), ... age smallint, ... kids smallint, ... birthdate date, ... salary decimal(8,2) ... ) ... """ >>> insert_person = "insert into person (name, age) values (%s, %s)" >>> with database('sqlite3', database=':memory:') as db: ... db(create_person_table) ... db(insert_person, 'Joe', 32) ... db('select * from person') 1 [(1, 'Joe', 32, None, None, None)]
-
database¶ Returns an object containing database parameters
-
debug= False¶
-
execute(command, *args)¶ execute a SQL command with optional parameters
-
execute_many(command, sequence)¶ execute a SQL command with a sequence of parameters
-
classmethod
get_stats()¶ Return the stats to the caller, clearing the list of what is returned
We use a classmethod to support inheritance (over staticmethod)
-
get_tables()¶ get a list of database tables
-
paramstyle= 'pyformat'¶
-
report()¶ produce a SQL log report
-
stats= []¶
-
translate(command, *args)¶ translate sql dialects
The Python db API standard does not attempt to unify parameter passing styles for SQL arguments. This translate routine attempts to do that for each database type. For databases that use the preferred pyformat paramstyle nothing needs to be done. Databases requiring other paramstyles should override this method to translate the command to the required style.
-
use(name)¶ use another database on the same instance
-
-
exception
zoom.database.DatabaseException¶ Bases:
Exceptionexception raised when a database server error occurs
-
exception
zoom.database.EmptyDatabaseException¶ Bases:
Exceptionexception raised when a database is empty
-
class
zoom.database.MySQLDatabase(*args, **kwargs)¶ Bases:
zoom.database.DatabaseMySQL Database
-
connect_string¶ Return a string representation of the connection parameters
-
create_site_tables()¶ create the tables for a site in a mysql server
-
create_test_tables()¶ create the extra test tables
-
delete_test_tables()¶ drop the extra test tables
-
get_column_names(table)¶ return column names for a table
-
get_databases()¶ return database names
-
get_tables()¶ return table names
-
paramstyle= 'pyformat'¶
-
transaction()¶
-
-
class
zoom.database.MySQLDatabaseTransaction(db)¶ Bases:
zoom.database.Database
-
class
zoom.database.MySQLdbDatabase(*args, **kwargs)¶ Bases:
zoom.database.DatabaseMySQLdb Database
deprecated - not avaialble for Python 3.6
use MySQLDatabase instead
-
paramstyle= 'pyformat'¶
-
-
class
zoom.database.Result(cursor, array_size=1000)¶ Bases:
objectdatabase query result
-
first()¶ return first item in result
-
-
class
zoom.database.Sqlite3Database(*args, **kwargs)¶ Bases:
zoom.database.DatabaseSqlite3 Database
-
create_site_tables(filename=None)¶
-
create_test_tables()¶ create the extra test tables
-
delete_test_tables()¶ drop the extra test tables
-
get_tables()¶ return table names
-
paramstyle= 'qmark'¶
-
transaction()¶
-
-
class
zoom.database.Sqlite3DatabaseTransaction(db)¶ Bases:
zoom.database.Database
-
exception
zoom.database.UnknownDatabaseException¶ Bases:
Exceptionexception raised when the database is unknown
-
zoom.database.connect_database(config)¶ establish a database connection
-
zoom.database.database(engine, *args, **kwargs)¶ create a database object
-
zoom.database.handler(request, handler, *rest)¶ Connect a database to the site if specified
-
zoom.database.obfuscate(text)¶ obfuscate text so it is recognizable without divulging it
>>> obfuscate('12345') '1***5'
>>> obfuscate('') ''
-
zoom.database.setup_test(engine=None)¶ create a set of test tables