
The power of SQL mixed with the smartness of object-relational mapping
Introduction
I have used SQLObject and I constantly ran into problems that needed to be hacked away. Then I tried SQLAlchemy, but it was the same limitations. I needed expressiveness badly and control over my queries. Then I thought, I will build something that has the power of SQL and the smartness of object-relational mapping... And that's when I coded AmiDB!
Requirements
- Python 2.3+
- MySQLdb 1+ (1.2.1 recommended)
- PyGreSQL
- SQLAlchemy (used as an engine)
Tutorials
Configuration
dbinfo = amidb.AmiDBInfo(user='myuser', password='mypwd', db='testdb')
db_pool = amidb.ConnectionPool(dbinfo)
con = db_pool.getConnection()
#print con.select('table', id=5)
db_pool.releaseConnection(con)
Example of use
Here is how queries look like using AmiDB:
Inserting a person into the table person:
amir_id = db.insert("person", name="Amir Salihefendic", age=20)
Selecting a person from the table person:
amir = db.select("person", name="Amir Salihefendic", as_one=True)
print amir.name
Selecting all persons from the table person and printing them out:
all_persons = db.select("person")
for person in all_persons:
print "%s is %i old" % (person.name, person.age)
Decorating a person with one extra method:
class Person:
def getName(self):
return "My name is %s" % self.name
amir = db.select("person", id=amir_id, obj_deco=Person, as_one=True)
print amir.getName()
Download
Change log
-
Version 1.7 - 23. September 2006
- PostgreSQL support (thanks to Simon Pamies)
- Bug fixes
- FreshPool
- For configuration use AmiDBInfo instead of global scope
-
Version 1.5 - 14. August 2006
- Moved to using SQLAlchemy as the engine [for maintenance issues].
- Bug fixes
- select("person", order_by="name", reversed=True) added
-
Version 1.3 - 1. August 2006
- No functionality added, but fixed a number of UTF8 issues.
-
Version 1.1 - 20. May 2006
- A bunch of bug fixes. The most critical is the escape function that made cross site scripting possible. Now MySQLdb.escape is used...
-
Version 1.0 - 3. May 2006
- Initial release