Questions tagged [sqlobject]

SQLObject is a free and open-source (LGPL) Python object-relational mapper. SQLObject supports a number of backends: MySQL/MariaDB (with a number of DB API drivers: MySQLdb, mysqlclient, mysql-connector, PyMySQL, mariadb), PostgreSQL (psycopg2, PyGreSQL), SQLite (builtin sqlite, pysqlite). Works under Python 2.7 and 3.4+.

What is SQLObject

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); connections to other backends

  • Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB) - are less debugged).

Python 2.7 or 3.4+ is required.

Where is SQLObject

Site: http://sqlobject.org

Download: https://pypi.org/project/SQLObject/

News and changes: http://sqlobject.org/News.html

Mailing lists: https://sourceforge.net/p/sqlobject/mailman/

Development: http://sqlobject.org/devel/

Developer Guide: http://sqlobject.org/DeveloperGuide.html

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
73 questions
47
votes
9 answers

Remove duplicates in list of object with Python

I've got a list of objects and I've got a db table full of records. My list of objects has a title attribute and I want to remove any objects with duplicate titles from the list (leaving the original). Then I want to check if my list of objects…
imns
  • 4,996
  • 11
  • 57
  • 80
14
votes
4 answers

How to make mysql connection that requires CA-CERT with sqlalchemy or SQLObject

I would like to connect to a MySQL database that requires ca-cert. I can do it with MySQLdb like below: MySQLdb.connect(host = self.host, port = self.port, unix_socket = self.unix_socket, user =…
cfpete
  • 4,143
  • 8
  • 27
  • 23
14
votes
3 answers

Any reasons not to use SQLObject over SQLAlchemy?

I don't expect to need much more than basic CRUD type functionality. I know that SQLAlchemy is more flexible, but the syntax etc of sqlobject just seem to be a bit easier to get up and going with.
mike
13
votes
3 answers

Dynamic Order in JDBI SQL Object Queries

How do you do ordering with SQL Object Queries in JDBI? I want to do something like: @SqlQuery( "SELECT * FROM users " + "WHERE something = :something " + "ORDER BY :orderBy :orderDir" ) List getUsers( @Bind("something")…
sclausen
  • 1,720
  • 3
  • 15
  • 22
12
votes
1 answer

Should I be using SQLObject, SQLAlchemy, or SQLAlchemy + Elixir?

I've been using SQLObject for a long while, but noticed that SQLAlchemy has become a lot more popular in the last couple years: http://www.google.com/trends?q=sqlobject,+sqlalchemy Are there compelling reasons to switch to SQLAlchemy? How is its…
mote
  • 190
  • 1
  • 9
7
votes
3 answers

python raw string assignment

Given a file contains lines such as: (?i:\bsys\.user_catalog\b) While reading those line, I want the value to be a raw string (unescaped), meaning, in memory, line should be r'(?i:\bsys\.user_catalog\b)' instead of…
Tzury Bar Yochay
  • 8,798
  • 5
  • 49
  • 73
6
votes
4 answers

How to install and use sqlobject+mysql on iron python?

Is it possible to use sqlobject to connect to a mysql database from iron python? If so, how? What must I install? I have sqlobject installed for cpython and it works fine, but if I use that same package in ironpython I get "ImportError: No module…
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
5
votes
2 answers

python: Why does SQLObject fail in conn.autocommit(1)?

In my server code, there is a call to _SO_fetchAlternateID (nested in some value call), which ultimately calls makeConnection in pgconnection.py. This call fails on conn.autocommit(1), with the error TypeError: 'bool' object is not callable Here…
Ovesh
  • 5,209
  • 11
  • 53
  • 73
4
votes
2 answers

Django: Store Hierarchical Data

I'm trying to store sections of a document in a Django app. The model looks like: class Section(models.Model): project = models.ForeignKey(Project) parent_section = models.ForeignKey('Section', blank=True, null=True, related_name='child_set') …
Max
  • 345
  • 1
  • 3
  • 10
4
votes
4 answers

sql select from a large number of IDs

I have a table, Foo. I run a query on Foo to get the ids from a subset of Foo. I then want to run a more complicated set of queries, but only on those IDs. Is there an efficient way to do this? The best I can think of is creating a query such…
Claudiu
  • 224,032
  • 165
  • 485
  • 680
3
votes
1 answer

Migrating data from one sqlite database to multiple SQLite databases using SQLObject

Till now our application has been using one SQLite database with SQLObject as the ORM. Obviously at some point we knew we had to face the SQLite concurrency problem and so we did. We ended up splitting the current database into multiple databases.…
user866937
  • 203
  • 2
  • 9
3
votes
1 answer

sqlobject thread safety

My python script reads and increments a row attribute. I call this function from 4 different threads. def update_row(): row = myTable.select(myTable.q.id==1, forUpdate=True)[0] row.count += 1 print "thread %s updated count to %s"…
Sachin Khot
  • 1,412
  • 2
  • 14
  • 18
3
votes
3 answers

Is this a good approach to avoid using SQLAlchemy/SQLObject?

Rather than use an ORM, I am considering the following approach in Python and MySQL with no ORM (SQLObject/SQLAlchemy). I would like to get some feedback on whether this seems likely to have any negative long-term consequences since in the…
tirus
  • 33
  • 2
3
votes
2 answers

How to do create_or_update in sqlobject?

I'm using SQLobject and so far was not able to find a elegant solution for "update row in the db or create a new one if it doesn't exist. Currently I use following somewhat convoluted code: args = dict(artnr=artnr, name=name, hersteller='?',…
max
  • 29,122
  • 12
  • 52
  • 79
2
votes
1 answer

Filter "value in list" with SQLObject ORM

I wanted to use SQLObject to allow my co-workers to get some data from my MySQL database. Now I need to use filter "value in list" but I don't know how can I do that. I choosed SQLObject because it looks simpler than for example Django ORM, but is…
Vether
  • 65
  • 1
  • 8
1
2 3 4 5