1.5.8 Other Useful Features

##
1.5.8 Other Useful Features

This example below demonstrates some other useful methods.

    #!/usr/bin/env python

    import sys; sys.path.append('../../../') # show python where the modules are

    import web.database, web.database.object
    connection = web.database.connect(
        adapter="snakesql",
        database="database-object-others",
        autoCreate = 1,
    )
    cursor = connection.cursor()

    person = web.database.object.Table("Person")
    person.addColumn(web.database.object.String(name="firstName"))
    person.addColumn(web.database.object.String(name="surname"))

    database = web.database.object.Database()
    database.addTable(person)
    database.init(cursor)

    if not database.tablesExist():
        database.createTables()
        print "Created Table"

    john = database['Person'].insert(firstName="John", surname="Smith")
    owen = database['Person'].insert(firstName="Owen", surname="Jones")

    print database['Person'].max('rowid')
    print database['Person'].max('firstName')
    print database['Person'].min('surname')

    print database.output()

    connection.close() # Close the connection without saving changes

The output is:

    Created Table
    2
    Owen
    Jones
    +---------------------+
    | Database 'Database' |
    +---------------------+
    | Person              |
    +---------------------+