You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To create a memory-mapped DB per the docs I can do
from montydb import set_storage, MontyClient
MontyClient(":memory:")
which results in nothing being written to disk. In the above, ":memory:" is a special repository name.
However if I first use set_storage with ":memory:" as the repository name
set_storage(":memory:")
MontyClient(":memory:")
Then a directory called :memory: is written to the current directory with a monty.storage.cfg file in it, which actually has nothing to do with the created MontyClient.
Similarly, if I pass "memory" as the repository name to MontyClient, a directory called memory is created and the actual underlying storage type is flatfile
>>> mc=MontyClient("memory")
>>> mc
MontyClient(repository='memory', document_class=builtins.dict, storage_engine=MontyStorage(engine: 'FlatFileStorage'))
Finally, if I specify storage="memory" (note the absence of :), with or without a repository,
then all works as expected and nothing is written to disk.
Strictly speaking none of these are "bugs", but personally I think this behavior is quite confusing and has a risk of unintended behavior. I suggest a few ways to address:
Recognize ":memory:" as a special repo name in set_storage and prevent it from being created as a directory
Warn the user if they pass "memory" as a repository name in MontyClient.__init__(). It is conceivable that someone might want their database to live in a folder called "memory", but I think it's also feasible that a user might pass that argument thinking they were getting a memory database
Expose all the set_storage kwargs in MontyClient.__init__() so that one could say, for example MontyClient(storage='sqlite', use_bson=True) rather than having to understand the nuances of set_storage and invoke it separately.
I'm willing to work on implementing the above, but wanted to hear your feedback first to make sure I'm not misunderstanding some of the intended behavior.
The text was updated successfully, but these errors were encountered:
To create a memory-mapped DB per the docs I can do
which results in nothing being written to disk. In the above, ":memory:" is a special repository name.
However if I first use
set_storage
with ":memory:" as the repository nameThen a directory called
:memory:
is written to the current directory with amonty.storage.cfg
file in it, which actually has nothing to do with the createdMontyClient
.Similarly, if I pass
"memory"
as the repository name toMontyClient
, a directory calledmemory
is created and the actual underlying storage type is flatfileFinally, if I specify
storage="memory"
(note the absence of :), with or without a repository,or
then all works as expected and nothing is written to disk.
Strictly speaking none of these are "bugs", but personally I think this behavior is quite confusing and has a risk of unintended behavior. I suggest a few ways to address:
set_storage
and prevent it from being created as a directoryMontyClient.__init__()
. It is conceivable that someone might want their database to live in a folder called "memory", but I think it's also feasible that a user might pass that argument thinking they were getting a memory databaseset_storage
kwargs inMontyClient.__init__()
so that one could say, for exampleMontyClient(storage='sqlite', use_bson=True)
rather than having to understand the nuances ofset_storage
and invoke it separately.I'm willing to work on implementing the above, but wanted to hear your feedback first to make sure I'm not misunderstanding some of the intended behavior.
The text was updated successfully, but these errors were encountered: