def __init__(self): self.db = Database('website_history') self.createTables()
from pattern.db import Database, SQLITE, MYSQL from pattern.db import field, pk, STRING, INTEGER, DATE, NOW from pattern.db import rel # In this example, we'll build a mini-store: # with products, customers and orders. # We can combine the data from the three tables in an invoice query. # Create a new database. # Once it is created, you can use Database(name) to access it. # SQLite will create the database file in the current folder. # MySQL databases require a username and a password. # MySQL also requires that you install MySQLdb, see the installation instructions at: # http://www.clips.ua.ac.be/pages/pattern-db db = Database("store.db", type=SQLITE) #db._delete() # PRODUCTS # Create the products table if it doesn't exist yet. # An error will be raised if the table already exists. # Add sample data. if not "products" in db: # Note: in SQLite, the STRING type is mapped to TEXT (unlimited length). # In MySQL, the length matters. Smaller fields have faster lookup. db.create( "products", fields=( pk(), # Auto-incremental id. field("description", STRING(50)), field("price", INTEGER)))
from pattern.db import field, pk, STRING, INTEGER, DATE, NOW from pattern.db import assoc from pattern.db import rel from pattern.db import pd # pd() = parent directory of current script. # In this example, we'll build a mini-store: # with products, customers and orders. # We can combine the data from the three tables in an invoice query. # Create a new database. # Once it is created, you can use Database(name) to access it. # SQLite will create the database file in the current folder. # MySQL databases require a username and a password. # MySQL also requires that you install MySQLdb, see the installation instructions at: # http://www.clips.ua.ac.be/pages/pattern-db db = Database(pd("store.db"), type=SQLITE) # db._delete() # PRODUCTS # Create the products table if it doesn't exist yet. # An error will be raised if the table already exists. # Add sample data. if not "products" in db: # Note: in SQLite, the STRING type is mapped to TEXT (unlimited length). # In MySQL, the length matters. Smaller fields have faster lookup. schema = ( pk(), # Auto-incremental id. field("description", STRING(50)), field("price", INTEGER)) db.create("products", schema) db.products.append(description="pizza", price=15)
from pattern.db import Database, field, pk, STRING, BOOLEAN, DATE, NOW, date,\ MYSQL db = Database(name='hootguy_tweetgraph', host='50.87.144.127', port=3306, username='******', password='******' #, type = MYSQL ) print 'tables = ', db.tables print 'relations = ', db.relations print 'query = ', db.query #db.create('chows', fields=[ # pk() # , field('manufacturer', STRING(80)) # , field('brand', STRING(80), index=True) # , field('price', STRING(15)) #]) # db.create('pets', fields=[ # pk(), # field('name', STRING(80), index=True), # field('type', STRING(20)), # field('tail', BOOLEAN), # field('date_birth', DATE, default=None), # field('date_created', DATE, default=NOW) # ])
from pattern.db import Database, SQLITE, MYSQL from pattern.db import field, pk, STRING, INTEGER, DATE, NOW from pattern.db import relation # In this example, we'll build a mini-store: # with products, customers and orders. # We can combine the data from the three tables in an invoice query. # Create a new database. # Once it is created, you can use Database(name) to access it. # SQLite will create the database file in the current folder. # MySQL databases require a username and a password. # MySQL also requires that you install MySQLdb, see the installation instructions at: # http://www.clips.ua.ac.be/pages/pattern-db db = Database("store", type=MYSQL, user="******", password="******") #db._delete() # PRODUCTS # Create the products table if it doesn't exist yet. # An error will be raised if the table already exists. # Add sample data. if not "products" in db: # Note: in SQLite, the STRING type is mapped to TEXT (unlimited length). # In MySQL, the length matters. Smaller fields have faster lookup. db.create( "products", fields=( pk(), # Auto-incremental id. field("description", STRING(50)), field("price", INTEGER)))