Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
bccf7a3
basic syntax changes
Mar 17, 2011
662f9af
fixed offset bug, added docs for offset
Mar 18, 2011
00d825c
Initial support for transactions.
xadhoom Apr 28, 2011
aa16e6c
Support for transactions.
xadhoom Apr 28, 2011
290f26d
add transaction support also on delete.
xadhoom Apr 29, 2011
11c8d57
Add some comments.
xadhoom Apr 29, 2011
f76c078
Transaction already tracks connection.
xadhoom May 30, 2011
c451d27
add documentations for transactions.
xadhoom May 30, 2011
deea7dd
added count method on dbobject
steeeveb Jun 15, 2011
40d6314
added count method on has_many and habtm relationships
steeeveb Jun 15, 2011
ff73d0a
added some doc to dbobject count
steeeveb Jun 15, 2011
545f42c
added some doc to relationship count
steeeveb Jun 15, 2011
896dcdc
Initial sync with upstream 1.0
xadhoom Jun 20, 2011
a3f8a80
.gitignore sync
xadhoom Jun 20, 2011
b1e9426
Real .gitignore sync
xadhoom Jun 20, 2011
e3fdcbf
Move code around
xadhoom Jun 20, 2011
23e4c47
removing temporarly my code to sync upstream
xadhoom Jun 20, 2011
d5b0993
put back my code, time to learn how to merge with git :)
xadhoom Jun 20, 2011
4fd9a54
Merge branch 'master' of https://github.com/bmuller/twistar
xadhoom Jun 20, 2011
2563950
Fixed transaction code. For some reason I lost it somewhere ?
xadhoom Jun 20, 2011
115fc76
Fix tab/spaces mixin
xadhoom Jun 20, 2011
d59a0df
More tab/spaces fixs
xadhoom Jun 20, 2011
6d80f3f
update .gitignore
xadhoom Jun 20, 2011
1a9e08c
Fix duplicate code derived from upstream merge
xadhoom Jun 20, 2011
270c5cb
More tabs/spaces fixes
xadhoom Jun 20, 2011
91f08e1
fixed issue #12: joinWheres should use parenthesis to preserve preced…
Jun 27, 2011
c2ec29a
Merge branch 'master' of https://github.com/bmuller/twistar
xadhoom Jul 25, 2011
d6693f7
added test to see if save after a count fails
Sep 9, 2011
69ceeee
Merge remote branch 'upstream/master'
xadhoom Sep 29, 2011
43f2410
Fixed relationship get with args when where is None, so we can use sa…
xadhoom Sep 29, 2011
aedf316
Add a test which does not engage schema cache which triggers 'table c…
xadhoom Oct 4, 2011
4aa2a3b
Split t.d.base.select to use an helper function to build the query st…
xadhoom Oct 4, 2011
2e1f838
Tab/spaces fixes
xadhoom Oct 4, 2011
a44cc63
Fix https://github.com/bmuller/twistar/issues/18
xadhoom Oct 4, 2011
cb08b97
Remove postresql count() override, now we can use same function in ba…
xadhoom Oct 4, 2011
7f3a4ca
Add cleanup after transaction test to avoid errors on pgsql.
xadhoom Oct 4, 2011
6e616bd
Merge remote branch 'upstream/master'
xadhoom Oct 10, 2011
863d090
add transactions for set in hasmany/habtm
Nov 2, 2011
f592c1a
Rename all txn attrs or params to transaction and use it consistently…
xadhoom Nov 28, 2011
2fc1fd9
Implemented transactions into find and get classmethods. Just pass tr…
xadhoom Nov 28, 2011
3aa7425
Remove TransactionAlreadyStartedError, multiple call to transaction()…
xadhoom Nov 28, 2011
f002ab9
fix if not Obj is None crazy syntax :)
xadhoom Nov 28, 2011
f2f40d3
add startTransaction method, move transaction method to read current …
xadhoom Nov 28, 2011
7855a90
Add test for calling transaction method and transaction is not starte…
xadhoom Nov 29, 2011
07c94a5
Add the possibility to inject a transaction, if not already started
xadhoom Nov 29, 2011
720fe0c
added test to expose bug in logging unicode strings
flaviogrossi Nov 29, 2011
6eef4e0
fixed logging with unicode strings
flaviogrossi Nov 29, 2011
60b81a7
Added more transaction support to relationships, with tests.
xadhoom Nov 30, 2011
2836544
Merge branch 'master' of https://github.com/xadhoom/twistar
xadhoom Nov 30, 2011
1597c38
Merge remote branch 'upstream/master'
xadhoom Jan 12, 2012
a81b325
Fix transactions in HABTM delete/clear
xadhoom Jan 17, 2012
bf553be
Merge remote-tracking branch 'upstream/master'
Apr 18, 2012
59e6598
Threaded transactions support.
xadhoom May 17, 2012
19321a5
Use connectionpool (really is adbapi threadpool) instead of connectin…
xadhoom May 17, 2012
af3460a
Move threadworker and new connectionpool outside twistar, so can be r…
xadhoom May 17, 2012
06bd80d
Fix modules inclusion
xadhoom May 17, 2012
1c9687b
Add missing import, remove not used ones.
xadhoom May 17, 2012
ce9dd08
Fix usage of threaded transactions on relationships
xadhoom May 18, 2012
ae953bb
deferred correctness. add copyright notice for threadworker.
xadhoom May 18, 2012
5b2e828
Fix transactions in HABTM get
xadhoom May 21, 2012
6daa933
small fixes
xadhoom May 21, 2012
8a59195
Fix transactions for polymorph relation
xadhoom May 21, 2012
811ef3b
Merge remote branch 'upstream/master'
xadhoom May 23, 2012
5d2b38f
Fix for python 2.6
xadhoom May 23, 2012
46ca70b
Remove new tables on tearDown
xadhoom May 23, 2012
6bab699
Transaction support to findBy and findOrCreate
xadhoom May 23, 2012
ecb481c
Merge remote branch 'upstream/master'
xadhoom Jun 8, 2012
92bd384
Add ci script
xadhoom Jun 27, 2012
8118bb7
Update readme with ci icon
xadhoom Jun 27, 2012
602429d
change README ext
xadhoom Jun 27, 2012
72a7511
trigger first ci
xadhoom Jun 27, 2012
89209bc
fix travis yaml
xadhoom Jun 27, 2012
6e21074
Fix travis image url
xadhoom Jun 27, 2012
f2991e5
correctly raise when given an invalid transaction
flaviogrossi Jul 31, 2012
2619090
added testcase for operation on an invalid transaction
flaviogrossi Jul 31, 2012
b661c91
Merge pull request #2 from flaviogrossi/master
xadhoom Jul 31, 2012
a6f77b4
add transactions support to habtm count()
xadhoom Oct 4, 2012
b9c3e62
added support for transaction to loadRelations
flaviogrossi Nov 30, 2012
2ca2211
added test for loadRelations outside a transaction
flaviogrossi Nov 30, 2012
94cd9e4
Merge pull request #3 from flaviogrossi/master
xadhoom Nov 30, 2012
59142ee
Fix for issue #32 - twistar.validation.presenceOf is broken
bmuller Dec 1, 2012
937de02
Fix for issue #33
bmuller Dec 1, 2012
023c271
updated docs around afterInit method in DBObject
bmuller Dec 1, 2012
0e5d96c
bumped version to 1.1 based on some bug fixes
bmuller Dec 1, 2012
4c13da9
honor log settings in delete() method
flaviogrossi Mar 7, 2013
8b914a4
Merge pull request #4 from flaviogrossi/master
xadhoom Mar 7, 2013
048fc4e
Add transaction support to Dbobject.count()
xadhoom Jun 11, 2013
7071f22
be sure to always release lock when exception occurs
xadhoom Aug 29, 2013
a76a351
log a warning message when the transaction pool is full
flaviogrossi Oct 25, 2013
197d301
Merge pull request #5 from flaviogrossi/master
xadhoom Oct 25, 2013
97bdac3
Added DBObject.__hash__; fixes #38
Dec 6, 2012
fba88c1
Fix #43 - clarified license type in setup.py
bmuller Mar 13, 2013
6702fb1
Clean up grammar and phrasing in examples
dehnert Apr 6, 2013
41b2b00
Minor formatting improvements to relationship docs
dehnert Apr 6, 2013
892419b
fixed issue w/ version being incorrect in init file, updated readme
bmuller May 29, 2013
4fe64e9
bumped version to 1.2
bmuller May 29, 2013
4afdf52
you can now add limit to update query - bumped version
bmuller Oct 12, 2013
f41b9d0
can how have joinwhere in habtm
bmuller Oct 18, 2013
4073850
Fix travis ci status link
xadhoom Oct 28, 2013
3507991
forgot one link
xadhoom Oct 28, 2013
07e5b91
Fix setup script
xadhoom Oct 28, 2013
bb68dad
Fix relationships when class name is a 'false' plural, like class, as…
xadhoom Apr 28, 2014
b96160b
Fix findOrCreate_rollback test and reenable sqlite backend as default…
xadhoom Apr 28, 2014
e01f81d
missing inlineCallbacks decorator
flaviogrossi May 27, 2014
b4d621d
add missing inlineCallbacks decorator to test
flaviogrossi May 27, 2014
b16790d
Merge pull request #6 from flaviogrossi/patch-1
xadhoom May 27, 2014
b98c8de
Merge pull request #7 from flaviogrossi/patch-2
xadhoom May 27, 2014
231461a
dump only valid threadpool data for twisted 17
davec82 Jun 8, 2021
0ace882
fix message in exception
davec82 Jun 8, 2021
0a7504c
remove --use-mirros option
davec82 Jun 8, 2021
78f3260
use trusty
davec82 Jun 8, 2021
2b9075e
use trusty with --use-mirros
davec82 Jun 8, 2021
34af700
use github actions
davec82 Jun 18, 2021
c01a241
run actions on push master branch
davec82 Jun 18, 2021
8003fd2
fix exception message when failing to commit
flaviogrossi Feb 18, 2022
809d10d
Merge pull request #8 from flaviogrossi/flaviogrossi-fix-commit-excep…
xadhoom Feb 18, 2022
0de46cf
fix comment and cleanup whitespace
flaviogrossi Feb 21, 2022
70a8e1e
always stop transaction thread worker, even if errors occurs
flaviogrossi Feb 21, 2022
c3935fb
Merge pull request #9 from flaviogrossi/fix_threadworker_not_always_s…
xadhoom Feb 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

on:
push:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [2.7]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: python -m pip install -q Twisted
- name: Run txconnectionpool tests
run: trial txconnectionpool
- name: Run test
run: trial twistar
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ doc/*.html
_trial_temp
build
dist
twistar.egg-info
24 changes: 0 additions & 24 deletions INSTALL

This file was deleted.

80 changes: 80 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# twistar: Asynchronous Python ORM
[![Build Status](https://secure.travis-ci.org/xadhoom/twistar.png?branch=master)](https://travis-ci.org/xadhoom/twistar)

The Twistar Project provides an ActiveRecord (ORM) pattern interface to the Twisted Project's RDBMS library. This file contains minimal documentation - see the project home page at http://findingscience.com/twistar for more information.

## Installation

```
easy_install twistar
```

## Usage
Your database must be one of: MySQL, PostgreSQL, or SQLite. The only DBAPI modules supported by Twistar are: MySQLdb, psycopg2, and sqlite3 - at least one of these must be installed.

Here's the obligatory TL;DR example of creating a User record, assuming that there is a table named "users" with varchar columns for first_name and last_name and an int age column:

```python
#!/usr/bin/env python
from twisted.enterprise import adbapi
from twistar.registry import Registry
from twistar.dbobject import DBObject
from twisted.internet import reactor

class User(DBObject):
pass

def done(user):
print "A user was just created with the name %s" % user.first_name
reactor.stop()

# Connect to the DB
Registry.DBPOOL = adbapi.ConnectionPool('MySQLdb', user="twistar", passwd="apass", db="twistar")

# make a user
u = User()
u.first_name = "John"
u.last_name = "Smith"
u.age = 25

# Or, use this shorter version:
u = User(first_name="John", last_name="Smith", age=25)

# save the user
u.save().addCallback(done)

reactor.run()
```

Then, finding this user is easy:

```python
def found(users):
print "I found %i users!" % len(users)
for user in users:
print "User: %s %s" % (user.first_name, user.last_name)

u = User.findBy(first_name="John", age=25).addCallback(found)
```

This is a very simple example - see http://findingscience.com/twistar for more complicated examples and additional uses.

## Testing
You will need to install the sqlite3 python package if you want to run the default tests. To run the tests:

```
trial twistar
```

See the README in the twistar/tests folder for more information on testing with different database types.

## Documenation
If you intent on generating API documentation, you will need pydoctor. If you want to generate the user documentation, you will need to install Twisted Lore.

To generate documentation:

```
make docs
```

Then open the docs/index.html file in a browser.
6 changes: 6 additions & 0 deletions README → README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Twistar
=======

.. image:: https://secure.travis-ci.org/xadhoom/twistar.png?branch=master

The Twistar Project provides an ActiveRecord (ORM) pattern interface to
the Twisted Project's RDBMS library.

Expand All @@ -6,3 +11,4 @@ those instructions are the steps to generating API, docs, and HOWTO examples.

For more information, see the project home page at:
http://findingscience.com/twistar

14 changes: 7 additions & 7 deletions doc/examples.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<body>
<h1>Simple Examples</h1>
<p>
Since Twistar uses Twisted, most methodand function calls willreturn a <code class="python">twisted.internet.defer.Deferred</code>
object. You must understand the propper use of these objects before most of this documentationwill make sense.
Since Twistar uses Twisted, most methods and function calls will return a <code class="python">twisted.internet.defer.Deferred</code>
object. You must understand the proper use of these objects before most of this documentation will make sense.
</p>

<h2>Initialization</h2>
<p>Before using Twistar a connection to the DB must first be made. The method of connecting to the database
is to use Twisted's <code class="python">twisted.enterprise.adapi</code> module and the <code class="python">ConnectionPool</code>
<p>Before using Twistar a connection to the DB must be made. To connect to the database
use Twisted's <code class="python">twisted.enterprise.adapi</code> module and the <code class="python">ConnectionPool</code>
object. The <code class="python">Registry</code> class is used to keep track of that pool. For instance, this is the
method to specify a connection to a MySQL database:
</p>
Expand Down Expand Up @@ -54,7 +54,7 @@ an auto-incrementing integer column named <q>id</q>.

<h2>Defining and Interacting With Objects</h2>
<p>
Object's representing rows in a database need only extend the
Objects representing rows in a database need only extend the
<code class="python">DBObject</code> class.
</p>
<pre class="python">
Expand Down Expand Up @@ -147,13 +147,13 @@ User.exists(['first_name = ?', "John"]).addCallback(printExists)

<h2>Validations</h2>
<p>
Twistar also supports validations. Validations describe constraints on an objects
Twistar also supports validations. Validations describe constraints on an object's
parameters. If those constraints are violated, then an object will not be saved (this
includes both creating and updating). In such a case a special parameter in the object
keeps track of the errors and the messages.
</p>
<p>
As an example, let's say that we want all users to always have a first name set and a last
As an example, let's say that we want all users to have a first name set and a last
name that has a length between 1 and 256 characters. First, we describe the class
<code class="python">User</code> as above and then add restrictions on it.
</p>
Expand Down
1 change: 1 addition & 0 deletions doc/index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object. You must understand the propper use of these objects before most of thi
<li><a href="examples.xhtml">Basic Examples</a></li>
<li><a href="relationship_examples.xhtml">Examples With Relationships</a></li>
<li><a href="lowlevel.xhtml">Lowlevel Database Interaction</a></li>
<li><a href="transactions.xhtml">Examples with Transactions</a></li>
</ul>

</body>
Expand Down
6 changes: 3 additions & 3 deletions doc/relationship_examples.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ Registry.register(User, Picture)
Assuming the DB structure is the same as in the "has many" example, you can now get and set the user that
a particular picture belongs to (using <code class="python">get()</code> and <code class="python">set()</code>
methods on <code class="python">picture.user</code>). Additionally, there is a <code>clear()</code> method that will clear all
objects in a given belongs to relationship.
objects in a given "belongs to" relationship.
</p>
<h2>Has and Belongs To Many</h2>
<p>
In a has and belongs to many relationship two objects have a many to many relationship. For instance, users and favorite colors.
A user can have many favorite colors and a favorite color could belong to many users. In this example, there should be three tables -
In a "has and belongs to many" relationship two objects have a many to many relationship. For instance, users and favorite colors.
A user can have many favorite colors and a favorite color could belong to many users. In this example, there should be three tables &mdash;
a <code>users</code> table, a <code>favorite_colors</code> table, and a <code>favorite_colors_users</code> table. The last on the list
is a special table that stores the relationships between the colors and users. It has no primary key, and two columns: one for
<code>user_id</code>s and one for <code>favorite_color_id</code>s. The table's name by convention should be the combination of the other
Expand Down
112 changes: 112 additions & 0 deletions doc/transactions.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Transaction Examples</title>
</head>

<body>
<h1>Transaction Examples</h1>
<p>From Active Record Transactions:
<q>Transactions are protective blocks where SQL statements are only permanent if they can all succeed as one atomic action.
The classic example is a transfer between two accounts where you can only have a deposit if the withdrawal succeeded and vice versa.
Transactions enforce the integrity of the database and guard the data against program errors or database break-downs.
So basically you should use transactions whenever you have a number of statements that must be executed together or not at all.</q>
</p>
<p>
More examples can be found in the <code class="python">RelationshipTest</code> class.
</p>
<h2>Initialization</h2>
<p>Given a <code class="python">DBObject</code> class instance, developer can call <code class="python">transaction()</code>
method on it, causing the start of the transaction. The method will return a transaction identifier.</p>
<pre class="python">
from twisted.internet.defer import inlineCallback

@inlineCallbacks
def do_some_pen_operations:
pen = Pen()
txn = pen.transaction()
</pre>

<h2>Commit / Rollback</h2>
<p>In this example, we will be using a <code class="python">Pen</code> object, which extends <code class="python">DBObject</code> class.</p>
<p>WARNING: pseudocode!</p>
<pre class="python">
from twisted.internet.defer import inlineCallback

@inlineCallbacks
def do_some_pen_operations:
pen = Pen()
pen.transaction()

pen.owner = "Luke"
yield pen.save()

pen.use() /* do something with the pen */

/* check if the owner is still Luke, after use */
if pen.owner == "Luke":
yield pen.commit()
else:
/* owner has changed, cannot apply ! */
yield pen.rollback()

</pre>
<h2>Different classes in a single transaction</h2>
<p>In this example, we use the same transaction across different objects, to bind all operations on them to same handler.</p>
<p>WARNING: pseudocode!</p>
<pre class="python">
from twisted.internet.defer import inlineCallback

@inlineCallbacks
def do_some_financial_operations:
money = Balance()
txn = money.transaction()

account = Account(transaction=txn)

money.total = 100
account.total = -100


yield money.save()
yield account.save()

try:
money.commit() /* or account.commit() */
except Exception, e:
money.rollback()
</pre>
<h2>Notes</h2>
<p>After a rollback or commit, the transaction is closed. You need to call <code class="python">transaction()</code> method again
to start a new transaction.</p>
<p>Depending on DB engine, you cannot call save on a <code class="python">DBObject</code> instance if same class type has an open transaction
(not committed yet), because the code will block waiting for the first transaction to finish. If the first open transaction will finish
before operation timeout, save will be done, otherwise will get executed after the transaction timeout of the DB engine. For example :</p>
<p>WARNING: pseudocode!</p>
<pre class="python">
from twisted.internet.defer import inlineCallback

@inlineCallbacks
def do_some_pen_operations:
pen = Pen(color="red")
pen.transaction() /* start transaction only on pen */

another_pen = Pen(color="blue") /* this is not in transaction */

yield pen.save()

/* code will block here utile DB engine timeout ... after that save() will throw an Exception */
/* after that, neither pen and another_pen are really save, the former because commit has not been called,
* the latter because the DB engine throwed an exception */
yield another_pen.save()

/* not executed at all */
yield pen.commit()
yield another_pen.commit()
</pre>

</body>
</html>

16 changes: 8 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env python
try:
from setuptools import setup, Extension
except ImportError:
from distutils.core import setup, Extension
from setuptools import setup, find_packages

from twistar import version

setup(
name="twistar",
version="1.0",
version=version,
description="An implementation of the Active Record pattern for Twisted",
author="Brian Muller",
author_email="bamuller@gmail.com",
license="GPLv3",
license="MIT",
url="http://findingscience.com/twistar",
packages=["twistar", "twistar.dbconfig", "twistar.tests", 'BermiInflector', 'BermiInflector.Rules'],
requires=["twisted.enterprise.adbapi"]
packages=find_packages(),
requires=["twisted.enterprise.adbapi"],
install_requires=['twisted >= 12.1']
)
5 changes: 2 additions & 3 deletions twistar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@

@author: Brian Muller U{bamuller@gmail.com}
"""

version = "0.1"
version_info = (0, 1)
version_info = (1, 3)
version = '.'.join(map(str, version_info))
Loading