def createTables(self): errMsg = ',ommitting...' try: self.db.create('websites', fields=(pk('id'), field('address', index=UNIQUE), field('domain_id'), field('connected', BOOLEAN, default=True), field('lastVisited', DATE, default=NOW))) except TableError as err: print err, errMsg try: self.db.create('links', fields=(pk('id'), field('website', INTEGER, optional=False), field('reference', INTEGER, optional=False))) except TableError as err: print err, errMsg try: self.db.create('domains', fields=(pk('id'), field('name', STRING(80), index=UNIQUE))) except TableError as err: print err, errMsg try: self.db.create('session', fields=(pk('id'), field('website_id', INTEGER, optional=False, index=UNIQUE), field('depth', INTEGER, optional=False))) except TableError as err: print err, errMsg self.db.link(self.db.domains, 'domains.id', self.db.websites, 'websites.domain_id') self.db.link(self.db.session, 'session.website_id', self.db.websites, 'websites.id')
# 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))) db.products.append(description="pizza", price=15) db.products.append(description="garlic bread", price=3) # CUSTOMERS # Create the customers table and add data. if not "customers" in db: db.create("customers", fields=(pk(), field("name", STRING(50)), field("address", STRING(200)))) db.customers.append(name=u"Schrödinger") # Unicode is supported. db.customers.append(name=u"Hofstadter") # ORDERS # Create the orders table if it doesn't exist yet and add data.
# 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. schema = ( pk(), # Auto-incremental id. field("description", STRING(50)), field("price", INTEGER)) db.create("products", schema) db.products.append(description="pizza", price=15) db.products.append(description="garlic bread", price=3) #db.products.append({"description": "garlic bread", "price": 3}) # CUSTOMERS # Create the customers table and add data. if not "customers" in db: schema = (pk(), field("name", STRING(50)), field("address", STRING(200))) db.create("customers", schema) db.customers.append(name=u"Schrödinger") # Unicode is supported. db.customers.append(name=u"Hofstadter") # ORDERS