SQL vs SQLObject
Posted: Sat May 12, 2007 4:15 am
So SQLite was on my later post but for people that are more used to MySQL but could use postgresql too there is SQLObject which is more of a native Object oriented python form of interacting wih tthe db.
No SQL just objects and instructions, here is an example, SQL would be:
Here is what will happen using SQLObjects:
So we import the SQLObject and the datetime, that right there will enable us to forget about the querky date timestamp that MySQL has.
The next step we create a class which will hold our table creation.
Finally we create an object oriented methodology where we have variables and values and this can be easily modiied later in the game withtout rewriting all the SQL again. Just reutilizing the object.
No SQL just objects and instructions, here is an example, SQL would be:
Code: Select all
CREATE TABLE person (
id INT PRIMARY KEY AUTO_INCREMENT,
first_name VARCHAR(100) NOT NULL,
middle_initial CHAR(1),
last_name VARCHAR(100) NOT NULL,
last_contact TIMESTAMP NOT NULL
);Code: Select all
1 from sqlobject import *
2 from datetime import datetime
3
4 class Person(SQLObject):
5
6 firstName = StringCol(length=100)
7 middleInitial = StringCol(length=1, default=None)
8 lastName = StringCol(length=100)
9 lastContact = DateTimeCol(default=datetime.now)The next step we create a class which will hold our table creation.
Finally we create an object oriented methodology where we have variables and values and this can be easily modiied later in the game withtout rewriting all the SQL again. Just reutilizing the object.