[go: up one dir, main page]

Menu

Tree [0ab2d1] mssql /
 History

HTTPS access


File Date Author Commit
 .github 2022-11-24 Oleg Broytman Oleg Broytman [c3ca3d] WIP: Limit OS, Python versions, backends
 debian 2016-08-09 Oleg Broytman Oleg Broytman [e17be4] Rename reStructuredText file from *.txt to *.rst
 devscripts 2022-11-24 Oleg Broytman Oleg Broytman [4988fd] CI: Run tests with MS SQL at GH Actions
 docs 2022-11-24 Oleg Broytman Oleg Broytman [4988fd] CI: Run tests with MS SQL at GH Actions
 scripts 2015-03-02 Neil Neil [c8b19c] Update scripts to user print function
 sqlobject 2022-11-24 Oleg Broytman Oleg Broytman [57213a] Feat(MSSQL): Use driver `pytds`
 .gitignore 2018-04-01 Oleg Broytman Oleg Broytman [6e1705] Build(.gitignore): Ignore `.pytest_cache`
 ANNOUNCE.rst 2022-09-25 Oleg Broytman Oleg Broytman [780cc5] It's free, open-source (MIT), Python
 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 2022-11-24 Oleg Broytman Oleg Broytman [57213a] Feat(MSSQL): Use driver `pytds`
 setup.cfg 2019-02-02 Oleg Broytman Oleg Broytman [1bb8e3] Prepare for the next release
 setup.py 2022-11-24 Oleg Broytman Oleg Broytman [57213a] Feat(MSSQL): Use driver `pytds`
 tox.ini 2022-12-02 Oleg Broytman Oleg Broytman [0ab2d1] WIP: Tests(MSSQL): Run only two test files; set...

Read Me

SQLObject 3.10.1a0

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 (psycopg2, PyGreSQL, partially pg8000 and py-postgresql), SQLite (builtin sqlite, pysqlite, partially supersqlite); MSSQL Server (pymssql or pytds); connections to other backends - Firebird, Sybase 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