-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dbm.sqlite proof of concept #48033
Comments
Based on recent discussions about ridding Python of bsddb I decided to No docs. No test cases. Caveat emptor. But I think it can serve as |
Attaching corrected module. |
Attaching test cases based on dumbdbm tests. |
Another slight revision to the module. |
Trivial doc diffs against 3.0b3 doc. |
Another tweak - add values() |
Updated test cases |
It would be more efficient to base keys() on iterkeys() than the |
Antoine> It would be more efficient to base keys() on iterkeys() than the True. I was just modifying the dumbdbm implementation.
Well, I only intended to create the initial proof of concept, but then last When I get a couple minutes free I'll try and condense it into a more Skip |
OK, I made a sandbox project out of it: svn+ssh://[email protected]/sandbox/trunk/dbm_sqlite Hack away! |
I would like to see something like this go into 3.0 so that shelves |
Here's an alternate version with most of bsddb's interface intact. |
sq_dict review: have sqlite quote/escape self._mtn before using it with a python %s raise a TypeError rather than a ValueError when you don't like the key also, to test the type, isinstance(val, str) is better than using type(val). |
I tried passing the db name as a parameter with '?', it doesn't always With regards to isinstance being better than type; it's only better if |
I like Skip's version better, because it's closer to the dbm I've made a few changes to the sandbox project which I will check in Perhaps we should do automatic commits every n (like 1000) changes, too? What's all this ORDER BY in both your implementations about? The dbm |
One question about Josiah's _check_value(). SQLite is less crippled than Shouldn't we make this accessible to users? Or is compatibility with |
Gerhard> What's all this ORDER BY in both your implementations about? I'd like to guarantee that zip(db.keys(), db.values() == db.items(). Skip |
Le jeudi 11 septembre 2008 à 12:46 +0000, Skip Montanaro a écrit :
It doesn't sound very useful, and it may hurt performance on big tables. |
Ok. If that isn't guaranteed elsewhere just drop it here? FWIW that will also work without the ORDER BY, because you're getting |
Actually, I think Python guarantees (for dicts at least - other mappings
Skip |
Gerhard> FWIW that will also work without the ORDER BY, because you're As long as SQLite guarantees that the ordering is identical, then sure, dump Skip |
Skip Montanaro wrote:
It doesn't guarantee it, but the implementation behaves like this. -- Gerhard |
Le jeudi 11 septembre 2008 à 13:48 +0000, Skip Montanaro a écrit :
Perhaps. I've never written any code that relies this, though, and it Also, the point is that Python dicts can make that guarantee without (also, IMO this discussion proves that the module shouldn't be included |
I might add that calling keys() then values() is suboptimal, because it |
dbm.sqlite is meant as a potential replacement of dbm.bsddb. Since Separating them out into a subclass (regular open doesn't have it, but Attached you will find an updated version. |
If the behavior isn't guaranteed, I think you need to retain ORDER BY. Skip |
Antoine> I might add that calling keys() then values() is suboptimal, Well, sure, but heaven only knows what an application programmer will do... S |
Here's an updated patch (it's also in the sandbox):
|
I think issuing 'SELECT MAX(ROWID)' to compute the length of the table |
That's a bummer. Changing this method to __bool__ and then setting |
FWIW, I put an alternative in the sandbox /dbm_sqlite/alt/dbdict.py and |
Unassigning. The code works but no one seems to be pushing for or If commits are delayed, then you might as well adopt the dbdict.py |
is there any chance for inclusion in 3.1? |
By utilizing triggers on inserts and deletes it is possible to SQL: CREATE TABLE IF NOT EXISTS info INSERT OR IGNORE INTO info (key,value) VALUES ('size',0); CREATE TABLE IF NOT EXISTS shelf CREATE TRIGGER IF NOT EXISTS insert_shelf CREATE TRIGGER IF NOT EXISTS delete_shelf On my laptop this increase the speed of 'len' about 10x I have a slightly modified version of dbsqlite.py for |
It would be nice to try to advance this at PyCon, or at another time. |
Multi threading: According to http://www.sqlite.org/cvstrac/wiki?p=MultiThreading I came across this when deploying an application in a multi threaded Also note that a memory database is not shared between threads and import threading
class SQLhash(collections.MutableMapping):
def __init__(self, filename=':memory:', flags='r', mode=None):
self.__filename = filename
self.__local = threading.local()
MAKE_SHELF = 'CREATE TABLE IF NOT EXISTS shelf (key TEXT PRIMARY KEY, value TEXT NOT NULL)'
self.conn.execute(MAKE_SHELF)
self.conn.commit()
@property
def conn(self):
try:
conn = self.__local.conn
except AttributeError:
conn = self.__local.conn = sqlite3.connect(self.__filename)
self.conn.text_factory = bytes
return conn |
This wiki page is out of date. It appears that SQlite is now threadsafe by default: http://www.sqlite.org/threadsafe.html |
I would like to try and resurrect this issue using @rhettinger's last submitted code (on bpo). @ambv almost mentioned shelve and sqlite3 in the same sentence in one of his developer-in-residence blog posts last year, so it may be worth it to try and get this up and running. (If not, it will at least be a fun exercise.) |
@erlend-aasland do you have any knews about this? |
Nope, and I've been busy with $work. Raymond has created a duplicate issue, though: see #100414 |
Just a heads-up; the gh-100414 now has a PR based on a recent patch Raymond posted. Feel free to review it: |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: