lundi 28 décembre 2015

How to use SQL databases in python without writing SQL?

I'm looking for a way to use a SQL database (such as MySQL, SQLite) in python without actually writing SQL. Example would be something like this (pseudocode):

# INSERT INTO table (firstname, lastname) VALUES ('John', 'Smith')
table.insert({'firstname':'John', 'lastname':'Smith'})

# SELECT * FROM table WHERE name='John'
results = table.select({'firstname': 'John'})
print results
# [ {'firstname':'John', 'lastname':'Smith'} ]

A light wrapper around python's DB-API, or possibly a very lightweight ORM, would do the job for this. If it's an ORM, it should allow mapping namedtuples to the DB, since that's pretty much the only kind of object I'd want to use in this case. I'm sure something like this already exists, but I have trouble finding it :)

Aucun commentaire:

Enregistrer un commentaire