Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed Jan 10, 2022
2 parents a241f32 + e0eb098 commit fa5f50e
Show file tree
Hide file tree
Showing 51 changed files with 5,964 additions and 963 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install and set up Poetry
run: |
curl -fsS -o get-poetry.py https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py
python get-poetry.py -y
source $HOME/.poetry/env
poetry config virtualenvs.in-project true
python-version: 3.9
- name: Install and configure Poetry
uses: gi0baro/setup-poetry-bin@v1
with:
virtualenvs-in-project: true
- name: Publish
run: |
source $HOME/.poetry/env
poetry config pypi-token.pypi $PUBLISH_TOKEN
poetry build
poetry publish
env:
PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
61 changes: 31 additions & 30 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,79 +13,80 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9, '3.10']

services:
postgres:
image: postgis/postgis:12-3.2
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
ports:
- 5432:5432

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install and set up Poetry
run: |
curl -fsS -o get-poetry.py https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py
python get-poetry.py -y
source $HOME/.poetry/env
poetry config virtualenvs.in-project true
- name: Install and configure Poetry
uses: gi0baro/setup-poetry-bin@v1
with:
virtualenvs-in-project: true
- name: Install dependencies
run: |
source $HOME/.poetry/env
poetry install -v
poetry install -v --extras crypto
- name: Test
env:
POSTGRES_URI: postgres:postgres@localhost:5432/test
run: |
source $HOME/.poetry/env
poetry run pytest -v tests
MacOS:
runs-on: macos-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9, '3.10']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install and set up Poetry
run: |
curl -fsS -o get-poetry.py https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py
python get-poetry.py -y
source $HOME/.poetry/env
poetry config virtualenvs.in-project true
- name: Install and configure Poetry
uses: gi0baro/setup-poetry-bin@v1
with:
virtualenvs-in-project: true
- name: Install dependencies
run: |
source $HOME/.poetry/env
poetry install -v
poetry install -v --extras crypto
- name: Test
run: |
source $HOME/.poetry/env
poetry run pytest -v tests
Windows:
runs-on: windows-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9, '3.10']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install and setup Poetry
run: |
curl -fsS -o get-poetry.py https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py
python get-poetry.py -y
$env:Path += ";$env:Userprofile\.poetry\bin"
poetry config virtualenvs.in-project true
- name: Install and configure Poetry
uses: gi0baro/setup-poetry-bin@v1
with:
virtualenvs-in-project: true
- name: Install dependencies
shell: bash
run: |
$env:Path += ";$env:Userprofile\.poetry\bin"
poetry install -v
poetry install -v --extras crypto
- name: Test
shell: bash
run: |
$env:Path += ";$env:Userprofile\.poetry\bin"
poetry run pytest -v tests
26 changes: 24 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
Emmett changelog
================

Version 2.4
-----------

Released on January 10th 2022, codename Edison

- Added official Python 3.10 support
- Added relative path support in templates
- Added support for spatial columns in ORM
- Added support for custom/multiple primary keys in ORM
- Added support for custom/multiple foreign keys in ORM
- Added support for custom and multiple primary keys relations in ORM
- Added `watch` parameter to ORM's `compute` decorator
- Added `save` method to ORM's rows and relevant callbacks
- Added `destroy` method to ORM's rows and relevant callbacks
- Added `refresh` method to ORM's rows
- Added `before_commit` and `after_commit` ORM callbacks
- Added changes tracking to ORM's rows
- Added support to call super `rowmethod` decorated methods in ORM models
- Added `migrations set` command to CLI
- Added `skip_callbacks` parameter to relevant methods in ORM
- ORM now automatically adds appropriate indexes for `unique` fields

Version 2.3
-----------

Expand All @@ -12,8 +34,8 @@ Released on August 12th 2021, codename Da Vinci
- Added `dict` values support for `in` validations
- Use optional `emmett-crypto` package for cryptographic functions
- Deprecated `security.secure_dumps` and `security.secure_loads` in favour of new crypto package
- Add `on_delete` option to `belongs_to` and `refers_to`
- Add `--dry-run` option to migrations `up` and `down` commands
- Added `on_delete` option to `belongs_to` and `refers_to`
- Added `--dry-run` option to migrations `up` and `down` commands

Version 2.2
-----------
Expand Down
40 changes: 40 additions & 0 deletions docs/orm/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,43 @@ class Post(Model):
```

The `where` option accepts a lambda function that should accept the model as first parameter and should return any valid query using the Emmett query language.

Custom primary keys
-------------------

*New in version 2.4*

### Customise primary key type

Under default behaviour, all models in Emmett have an integer `id` primary key. In case you need to change the type of this field, just define your own `id` field.

For example, we might want to have a model with UUID strings as primary key:

```python
from uuid import uuid4

class Ticket(Model):
id = Field.string(default=lambda: uuid4().hex)
```

### Using custom primary keys

Sometimes you need to have models without an `id` field, as a specific field can be used as primary key. Other times, you need to have compound primary keys, where you have multiple fields producing your records identifier.

Under these circumstances, using the `primary_keys` attribute of the `Model` class will be enough:

```python
class Ticket(Model):
primary_keys = ["code"]

code = Field.string(default=lambda: uuid4().hex)


class MultiPK(Model):
primary_keys = ["key1", "key2"]

key1 = Field.int()
key2 = Field.int()
```

> **Note:** Emmett [relations](./relations) system is fully-compatible with custom and multiple primary keys.
Loading

0 comments on commit fa5f50e

Please sign in to comment.