Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/metal3d/rethinkmodel
Rethink:Model - use Python annotation to describe RethinkDB Models - ORM
https://github.com/metal3d/rethinkmodel
orm python rethinkdb
Last synced: 6 days ago
JSON representation
Rethink:Model - use Python annotation to describe RethinkDB Models - ORM
- Host: GitHub
- URL: https://github.com/metal3d/rethinkmodel
- Owner: metal3d
- License: mit
- Created: 2021-02-13T13:56:07.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-07T14:05:01.000Z (almost 4 years ago)
- Last Synced: 2024-12-25T03:45:21.430Z (about 1 month ago)
- Topics: orm, python, rethinkdb
- Language: Python
- Homepage: https://metal3d.github.io/rethinkmodel/
- Size: 3.24 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rethink:Model
[![PyPI version](https://badge.fury.io/py/rethinkmodel.svg)](https://badge.fury.io/py/rethinkmodel)
[![Build
Status](https://www.travis-ci.org/metal3d/rethinkmodel.svg?branch=master)](https://www.travis-ci.org/metal3d/rethinkmodel)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=rethinkmodel&metric=alert_status)](https://sonarcloud.io/dashboard?id=rethinkmodel)
[![Documentation](https://badgen.net/badge/doc/official/green)](https://metal3d.github.io/rethinkmodel)Simple and easy to use ORM for [RethinkDB](https://www.rethinkdb.com).
Use Python `typing` package and annotations to describe data
representation.RethinkModel aims to help you to describe your data as classes to be
easilly created, updated and get from
[RethinkDB](https://www.rethinkdb.com).Rethink:Model make uses of [typing
support](https://docs.python.org/3/library/typing.html) annotations -
Python annotations describe the model fields. That’s easy, you only have
to import the standard `typing` module, and use any of `Optionnal`,
`Type`, `List`, `Union`… types.## It’s simple as a pie
``` python
from typing import Optional, List
from rethinkdb.model import Modelclass Post(Model):
author: User # One to One relation to User
content: str
tags: Optional[List[str]] # use typing, tags can be Noneclass User(Model):
login: str
email: str# save
user = User(login="John", email="[email protected]").save()
post = Post(author=user, content="This is the post").save()# get user
user = User.get(user.id)# get Post
post = Post.get(post.id)
# post.author is an User, but in DB it's the ID# get post from User ?
user = User.get(user.id).join(Project)
# user.projects is now filled
```There are **other methods** like `join()`, `get_all()` and so on. Please
check documentation.## The goals
- Describe the models in the simplest possible way, but also in the
most meaningful way
- Make use of powerful typing package from Python \> 3.7
- Avoid type checking at runtime (What ?) but let your IDE punish youPython is not a staticly typed langage. But Python developers want it
(or not 😜) - So there are many Python tools that are designed to use
typing package which is integrated with Python SDK: Pyright (use by
PyLance), MyPy, PyType…Your IDE can make type checking.
- Vim can use
[coc-pyright](https://github.com/fannheyward/coc-pyright)
- VsCode can use
[PyLance](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance)
- PyCharm knows how to manage typing
- etc…So, let’s use typing \! Rethink:Model is designed to use the typing
package.