forked from ponyorm/pony
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQLite memory database can be shared between connections
- Loading branch information
Showing
5 changed files
with
70 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from __future__ import absolute_import, print_function, division | ||
|
||
import threading | ||
import unittest | ||
|
||
from pony.orm.core import * | ||
|
||
|
||
db = Database('sqlite', ':sharedmemory:') | ||
|
||
|
||
class Person(db.Entity): | ||
name = Required(str) | ||
|
||
db.generate_mapping(create_tables=True) | ||
|
||
with db_session: | ||
Person(name='John') | ||
Person(name='Mike') | ||
|
||
|
||
class TestThread(threading.Thread): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, *kwargs) | ||
self.result = [] | ||
def run(self): | ||
with db_session: | ||
persons = Person.select().fetch() | ||
self.result.extend(p.name for p in persons) | ||
|
||
|
||
class TestFlush(unittest.TestCase): | ||
def test1(self): | ||
thread1 = TestThread() | ||
thread1.start() | ||
thread1.join() | ||
self.assertEqual(set(thread1.result), {'John', 'Mike'}) |