[go: up one dir, main page]

Menu

Tree [57839a] master /
 History

HTTPS access


File Date Author Commit
 .github 2025-07-24 Oleg Broytman Oleg Broytman [49a726] Tested with Python 3.14
 debian 2016-08-09 Oleg Broytman Oleg Broytman [e17be4] Rename reStructuredText file from *.txt to *.rst
 devscripts 2025-04-11 Oleg Broytman Oleg Broytman [affe99] Build(release): Rename both sdist and wheel fil...
 docs 2025-08-16 Oleg Broytman Oleg Broytman [4cc7da] Tests(tox): Run tests with non-binary `psycopg`...
 scripts 2015-03-02 Neil Neil [c8b19c] Update scripts to user print function
 sqlobject 2025-07-24 Oleg Broytman Oleg Broytman [eb3fab] Style(cmp): Fix `flake8` warning F824
 .gitignore 2018-04-01 Oleg Broytman Oleg Broytman [6e1705] Build(.gitignore): Ignore `.pytest_cache`
 ANNOUNCE.rst 2025-03-07 Oleg Broytman Oleg Broytman [27b78f] Build: Prepare for the next release
 LICENSE 2016-10-05 Oleg Broytman Oleg Broytman [1aab65] Move docs/LICENSE to the top-level directory so...
 MANIFEST.in 2021-09-27 Oleg Broytman Oleg Broytman [d2921e] Tests(tox): Stop collecting test coverage
 README.rst 2025-03-07 Oleg Broytman Oleg Broytman [0217eb] Release 3.13.0
 setup.cfg 2025-02-01 Oleg Broytman Oleg Broytman [d13705] Build: Prepare for the next release
 setup.py 2025-07-24 Oleg Broytman Oleg Broytman [49a726] Tested with Python 3.14
 tox.ini 2025-08-16 Oleg Broytman Oleg Broytman [57839a] Tests(tox): Run default flake8 tests under Py 3.14

Read Me

SQLObject 3.13.0

SQLObject is a free and open-source (LGPL) Python object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL/MariaDB (with a number of DB API drivers: MySQLdb, mysqlclient, mysql-connector, PyMySQL, mariadb), PostgreSQL (psycopg, psycopg2, PyGreSQL, partially pg8000), SQLite (builtin sqlite3); connections to other backends - Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB) - are less debugged).

Python 2.7 or 3.4+ is required.

Example

Install:

$ pip install sqlobject

Create a simple class that wraps a table:

>>> from sqlobject import *
>>>
>>> sqlhub.processConnection = connectionForURI('sqlite:/:memory:')
>>>
>>> class Person(SQLObject):
...     fname = StringCol()
...     mi = StringCol(length=1, default=None)
...     lname = StringCol()
...
>>> Person.createTable()

Use the object:

>>> p = Person(fname="John", lname="Doe")
>>> p
<Person 1 fname='John' mi=None lname='Doe'>
>>> p.fname
'John'
>>> p.mi = 'Q'
>>> p2 = Person.get(1)
>>> p2
<Person 1 fname='John' mi='Q' lname='Doe'>
>>> p is p2
True

Queries:

>>> p3 = Person.selectBy(lname="Doe")[0]
>>> p3
<Person 1 fname='John' mi='Q' lname='Doe'>
>>> pc = Person.select(Person.q.lname=="Doe").count()
>>> pc
1