A OO-based Git Database
Project description
Because doing stupid things with git is surprisingly fun.
OGitM is an ORM, but where the relational database that underlies the entire mapping has been replaced by an awful attempt at replicating a stupidly basic key-value document store in git. This software should never be used by anyone ever. Please, for the good of humanity.
Um… What?
Git is useful, because it stores both data, and the history of that data. This might be a useful property for a database to have. Writing a whole database based on git is boring, I should try writing an ORM to wrap around it. Well, it wouldn’t so much be an ORM, more an O… git M?
How do I use this?
Import the module, declare your model, and go!
>>> import tempfile; db_directory = tempfile.TemporaryDirectory()
>>>
>>> import ogitm
>>> class MyModel(ogitm.Model, db=db_directory.name):
... name = ogitm.fields.String()
... age = ogitm.fields.Integer(min=0)
>>>
>>> instance = MyModel(name="Bob", age=172)
>>> instance_id = instance.save()
>>> MyModel.find(name="Bob", age=172).first() == instance
True
>>> instance.age = -5
Traceback (most recent call last):
...
ValueError: Disallowed value -5 ...
Can I get at the underlying database?
Yes. Meet the gitdb module, which provides direct access to a document-based database. Initialise it with a directory that it can use as a git bare repository, and start inserting and getting.
>>> import tempfile; db_directory = tempfile.TemporaryDirectory()
>>>
>>> from ogitm import gitdb
>>> db = gitdb.GitDB(db_directory.name)
>>> doc_id = db.insert({'name': 'Jimmy', 'age': 45, 'car': False})
>>> db.get(doc_id) == {'name': 'Jimmy', 'age': 45, 'car': False}
True
More than that, you can also search for documents previously inserted. These queries accept simple scalar arguments, which return all documents which have the same values as the query, and more complex dictionary arguments which can test for existence, compare etc.
>>> doc_id = db.insert({'name': 'Bobbie', 'car': True})
>>> doc_id = db.insert({'name': 'Bertie', 'age': 26, 'car': False})
>>> {'name': 'Bobbie', 'car': True} in db.find_items({'car': True})
True
>>> doc_id = db.insert({'name': 'Jimmy'})
>>> db.find_items({'car': {'exists': False}}) == [{'name': 'Jimmy'}]
True
Todo
Documentation. (docstrings & manual)
PyPI
Relationships? (U f*cking wot m8?)
Python 2
Better way of accessing git (May be needed for Py2, is needed for pypy, will make it easier for anyone to install it from PyPI) (See Dulwich)
Begin versioning sometime fairly soon
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ogitm-0.1.0.tar.gz
.
File metadata
- Download URL: ogitm-0.1.0.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b99563d9baae442cd2177de80b7a671d1459d28f815c26e355b71e21288cab3 |
|
MD5 | ea4681ac488e8e24a1ada2b50fbb0655 |
|
BLAKE2b-256 | 29dfa8fd98734ef48cc3806132e6173b381fa887668a2f76d770025290944ddc |
File details
Details for the file ogitm-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: ogitm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c31fa4ceb506f1b40172113ca40f2dd28113b1e478de4fd1535742cc0ef8c9c |
|
MD5 | 88abd92fd63efd2ea6f210f05763766f |
|
BLAKE2b-256 | 995005db3d7c5484e49dec98b87377e9293dde49b602f29fd498ce8d148a20c9 |