Tutorial¶
Connection to a Database¶
TODO
Examining the Database Schema¶
TODO
Modifying the Database Schema¶
Example:
>>> import dbschema
>>> op = dbschema.operation.SchemaOperation(dbschema.BACKEND_POSTGRESQL)
>>> table = dbschema.objects.Table('foo')
>>> op += table
>>> table += dbschema.objects.Column('val1', int)
>>> table += dbschema.objects.Column('val2', str, comment='val2 is a string value')
>>> table.comment = 'An example table.'
>>> print(op.as_sql())
CREATE TABLE "foo" (
val1 integer,
val2 text
);
COMMENT ON TABLE "foo" IS 'An example table';
COMMENT ON COLUMN "foo"."val2" IS 'val2 is a string value';
>>> conn = psycopg2.connect(dbname='demo', user='john', password='doe')
>>> op.backend.set_connection(conn)
>>> op.execute() # perform operation on database
>>>