Database

class schemaobject.database.DatabaseSchema(name, parent)

Object representation of a single database schema (as per CREATE DATABASE Syntax). Supports equality and inequality comparison of DatabaseSchemas.

name is the database name. parent is an instance of SchemaObject

>>> for db in schema.databases:
...     print schema.databases[db].name
...
sakila
>>> schema.databases['sakila'].name
'sakila'

Note

DatabaseSchema objects are automatically created for you by DatabaseSchemaBuilder and loaded under schema.databases

alter()
Generate the SQL to alter this database
>>> schema.databases['sakila'].alter()
'ALTER DATABASE `sakila`'
create()
Generate the SQL to create this databse
>>> schema.databases['sakila'].create()
'CREATE DATABASE `sakila` CHARACTER SET=latin1 COLLATE=latin1_swedish_ci;'
drop()
Generate the SQL to drop this database
>>> schema.databases['sakila'].drop()
'DROP DATABASE `sakila`;'
options

Dictionary of the supported MySQL database options. See OptionSchema for usage.

  • CHARACTER SET == options['charset']
  • COLLATE == options['collation']
select()
Generate the SQL to select this database
>>> schema.databases['sakila'].select()
'USE `sakila`;'
tables
Lazily loaded dictionary of all the tables within this database. See TableSchema for usage
>>> len(schema.databases['sakila'].tables)
16
schemaobject.database.DatabaseSchemaBuilder(instance)

Returns a dictionary loaded with all of the databases availale on the MySQL instance. instance must be an instance SchemaObject.

Note

This function is automatically called for you and set to schema.databases when you create an instance of SchemaObject

Previous topic

Schema (MySQL Instance)

Next topic

Table

This Page