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
1
vote
1 answer

SQLObject: reusing my arguments list

I'm using SQLObject and I've got the following: # update foo if it exists, otherwise create a new one if self.foo_exists: Foo.get(foo_id).set(name = foo['name'], ip = foo['ip'], port = foo['port'], mode = foo['mode'], max_conn = foo['max_conn'])…
stephenmurdoch
  • 34,024
  • 29
  • 114
  • 189
1
vote
1 answer

Python ORM Library that can be used without a database connection

I need to figure out how to create a class that has optional ORM functionality, ie sometimes I will need to save it to a database, and other times I will not have to (I will have no connection). SQLObject, for example, doesn't work, because it barfs…
d0c_s4vage
  • 3,947
  • 6
  • 23
  • 32
1
vote
1 answer

sqlobject sqlmeta with composite key

I have created my sqlobject class like so and set the primary key to prm_id import sqlobject from connection import conn class tbl_episodes(sqlobject.SQLObject): class sqlmeta: idName = "prm_id" _connection = conn …
Aatish Molasi
  • 2,138
  • 3
  • 20
  • 43
1
vote
1 answer

Sorting by a field of another table referenced by a foreign key in SQLObject

Is it possible to sort results returned by SQLObject by a value of another table? I have two tables: class Foo(SQLObject): bar = ForeignKey('Bar') class Bar(SQLObject): name = StringCol() foos =…
Alex
  • 43,191
  • 44
  • 96
  • 127
1
vote
1 answer

how to do 'select in' operation in sqlobject

I want write a SQL statement like this: select * from 'table' t where t.id in (1,2,4) But I don't how to using SQLObject's grammar.
fangshi
  • 13
  • 3
1
vote
0 answers

SQLObject lazyupdate is resetting fields to default values when I read them (python 2.7, postgresql 9.1)

I'm trying to use SQLObject's lazyUpdate feature and my data is getting clobbered. Here's the class definition class T(sqlobject.SQLObject): class sqlmeta: lazyUpdate = True def __enter__(self): return self def…
Vroo
  • 1,064
  • 1
  • 11
  • 19
0
votes
2 answers

Choosing Python/SQLObject webframework

I have a regular desktop application which is written in Python/GTK and SQLObject as ORM. My goal is to create a webinterface where a user can login and sync/edit the database. My application is split up in different modules, so the database and gtk…
Timo
  • 164
  • 2
  • 12
0
votes
1 answer

How to manage db connections using webpy with SQLObject?

Web.py has its own database API, web.db. It's possible to use SQLObject instead, but I haven't been able to find documentation describing how to do this properly. I'm especially interested in managing database connections. It would be best to…
automaciej
  • 429
  • 3
  • 14
0
votes
1 answer

ManyToMany relationships on the same table in SQLObject

My google foo has been coming up short on this, so I throw this to the geniuses here. I'm writing some beer recipe creation software and I've got a class in SQLObject and I'd like to have a RelatedJoin back to itself. But it's not working. If it…
tkone
  • 22,092
  • 5
  • 54
  • 78
0
votes
0 answers

About flask ORM

I am a Django developer but recreantly started work with Flask. My problem is i want perform CRUD operation in flask using sqlite3. can i do this? Below i have put my ORM. how is work and how data will save into database? from sqlobject import…
0
votes
1 answer

SQL Alchemy or SQL Object in Bottle Python

hi i am a newbie just starting off on bottle.py framework does anyone have a sample CRUD application that we can learn from? secondly which of the two wrappers runs faster in bottle?thanks.
0
votes
1 answer

sqlobject: leak memory using selectby method

I had discovered that using selectby method with sqlobject there are leak memory. For example, when I execute this code: connection = connectionForURI('postgresql://test:test@localhost/test_sql_object') tran =…
rrobles
  • 1
  • 3
0
votes
1 answer

How to do following sql operation using Table.select() method in python sqlobject?

Sql Operation: SELECT *, CASE WHEN quota_unit = 'MB' THEN quota*1024 ELSE quota END AS data_usage FROM mapping ORDER BY data_usage; I tried like this, query = mapping.select('CASE WHEN…
SAG786
  • 11
  • 1
  • 3
0
votes
1 answer

How do I install SQLObject for use with Python?

I need to use SQLObject with Python and I downloaded SQLObject-1.0.0-py2.6.egg but I have no idea what to do next.
0
votes
2 answers

Simple multi-threading with SQLObject doesn't work

It stucks once I execute .getOne(): from sqlobject import * import threading sqlhub.processConnection = connectionForURI('mysql://user:password@localhost:3306/database') class Player(SQLObject): name = StringCol(length=64) last_login =…
Zippo
  • 15,850
  • 10
  • 60
  • 58