Merge pull request #28 from grillazz/json-field-example

readme update
This commit is contained in:
Jakub Miazek 2022-04-23 20:21:45 +02:00 committed by GitHub
commit f6e5088d3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 93 deletions

1
.gitignore vendored
View File

@ -127,3 +127,4 @@ dmypy.json
# Pyre type checker
.pyre/
/requirements-dev.txt

View File

@ -14,13 +14,9 @@ up: ## Run project with compose
clean: ## Clean Reset project containers with compose
docker-compose down -v --remove-orphans
.PHONY: lock
lock: ## Refresh pipfile.lock
pipenv lock --pre
.PHONY: requirements
requirements: ## Refresh requirements.txt from pipfile.lock
pipenv lock -r > requirements.txt
pipenv lock -r -d > requirements.txt
.PHONY: test
test: ## Run project tests

View File

@ -22,7 +22,6 @@ pytest-asyncio = "*"
isort = "*"
mypy = "*"
flake8 = "*"
flake8-fastapi = "*"
black = "*"
safety = "*"
autoflake = "*"

85
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "33514b9ec2791fea6a15aa302c07b6e4dace6ae566468715cfcf333c9d8c3f5c"
"sha256": "a079fa81edd5f9fffa5d9c991b96d227b19bf14c6692d83d99601f43c553586b"
},
"pipfile-spec": 6,
"requires": {
@ -241,7 +241,7 @@
"sha256:f27f0875e0873f6bf5df09a456bfcac0667824cabac4cad30b43f36e0382ffe7",
"sha256:fcd4a6d04995f1d66bc78b503e4e59ae72fd32aaec4f661657fe5ae5c1aa4ce3"
],
"markers": "python_version >= '3' and platform_machine == 'aarch64' or (platform_machine == 'ppc64le' or (platform_machine == 'x86_64' or (platform_machine == 'amd64' or (platform_machine == 'AMD64' or (platform_machine == 'win32' or platform_machine == 'WIN32')))))",
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
"version": "==2.0.0a2"
},
"h11": {
@ -460,11 +460,11 @@
},
"pytest": {
"hashes": [
"sha256:841132caef6b1ad17a9afde46dc4f6cfa59a05f9555aae5151f73bdf2820ca63",
"sha256:92f723789a8fdd7180b6b06483874feca4c48a5c76968e03bb3e7f806a1869ea"
"sha256:13d0e3ccfc2b6e26be000cb6568c832ba67ba32e719443bfe725814d3c42433c",
"sha256:a06a0425453864a270bc45e71f783330a7428defb4230fb5e6a731fde06ecd45"
],
"markers": "python_version >= '3.7'",
"version": "==7.1.1"
"version": "==7.1.2"
},
"pytest-asyncio": {
"hashes": [
@ -738,14 +738,6 @@
],
"version": "==0.8.3"
},
"fastapi": {
"hashes": [
"sha256:a70d31f4249b6b42dbe267667d22f83af645b2d857876c97f83ca9573215784f",
"sha256:b5dac161ee19d33346040d3f44d8b7a9ac09b37df9efff95891f5e7641fa482f"
],
"index": "pypi",
"version": "==0.75.2"
},
"flake8": {
"hashes": [
"sha256:479b1304f72536a55948cb40a32dce8bb0ffe3501e26eaf292c7e60eb5e0428d",
@ -754,22 +746,6 @@
"index": "pypi",
"version": "==4.0.1"
},
"flake8-fastapi": {
"hashes": [
"sha256:aa004b3813bf97088dc0dc273f63cd04972251eb4a6964f7ec9d2c264c922a84",
"sha256:c3bce2c282bf6565011cc0c08618a155f9afe52ba2847185d636a8eb7f67bc5a"
],
"index": "pypi",
"version": "==0.6.1"
},
"flake8-plugin-utils": {
"hashes": [
"sha256:1fe43e3e9acf3a7c0f6b88f5338cad37044d2f156c43cb6b080b5f9da8a76f06",
"sha256:20fa2a8ca2decac50116edb42e6af0a1253ef639ad79941249b840531889c65a"
],
"markers": "python_version >= '3.6' and python_version < '4.0'",
"version": "==1.3.2"
},
"icecream": {
"hashes": [
"sha256:04b9cea4d9931cf6960db0430ebf11fa34464ce7152e384ddf50f96d25b201b4",
@ -980,47 +956,6 @@
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
"version": "==2.8.0"
},
"pydantic": {
"hashes": [
"sha256:085ca1de245782e9b46cefcf99deecc67d418737a1fd3f6a4f511344b613a5b3",
"sha256:086254884d10d3ba16da0588604ffdc5aab3f7f09557b998373e885c690dd398",
"sha256:0b6037175234850ffd094ca77bf60fb54b08b5b22bc85865331dd3bda7a02fa1",
"sha256:0fe476769acaa7fcddd17cadd172b156b53546ec3614a4d880e5d29ea5fbce65",
"sha256:1d5278bd9f0eee04a44c712982343103bba63507480bfd2fc2790fa70cd64cf4",
"sha256:2cc6a4cb8a118ffec2ca5fcb47afbacb4f16d0ab8b7350ddea5e8ef7bcc53a16",
"sha256:2ee7e3209db1e468341ef41fe263eb655f67f5c5a76c924044314e139a1103a2",
"sha256:3011b975c973819883842c5ab925a4e4298dffccf7782c55ec3580ed17dc464c",
"sha256:3c3b035103bd4e2e4a28da9da7ef2fa47b00ee4a9cf4f1a735214c1bcd05e0f6",
"sha256:4c68c3bc88dbda2a6805e9a142ce84782d3930f8fdd9655430d8576315ad97ce",
"sha256:574936363cd4b9eed8acdd6b80d0143162f2eb654d96cb3a8ee91d3e64bf4cf9",
"sha256:5a79330f8571faf71bf93667d3ee054609816f10a259a109a0738dac983b23c3",
"sha256:5e48ef4a8b8c066c4a31409d91d7ca372a774d0212da2787c0d32f8045b1e034",
"sha256:6c5b77947b9e85a54848343928b597b4f74fc364b70926b3c4441ff52620640c",
"sha256:742645059757a56ecd886faf4ed2441b9c0cd406079c2b4bee51bcc3fbcd510a",
"sha256:7bdfdadb5994b44bd5579cfa7c9b0e1b0e540c952d56f627eb227851cda9db77",
"sha256:815ddebb2792efd4bba5488bc8fde09c29e8ca3227d27cf1c6990fc830fd292b",
"sha256:8b5ac0f1c83d31b324e57a273da59197c83d1bb18171e512908fe5dc7278a1d6",
"sha256:96f240bce182ca7fe045c76bcebfa0b0534a1bf402ed05914a6f1dadff91877f",
"sha256:a733965f1a2b4090a5238d40d983dcd78f3ecea221c7af1497b845a9709c1721",
"sha256:ab624700dc145aa809e6f3ec93fb8e7d0f99d9023b713f6a953637429b437d37",
"sha256:b2571db88c636d862b35090ccf92bf24004393f85c8870a37f42d9f23d13e032",
"sha256:bbbc94d0c94dd80b3340fc4f04fd4d701f4b038ebad72c39693c794fd3bc2d9d",
"sha256:c0727bda6e38144d464daec31dff936a82917f431d9c39c39c60a26567eae3ed",
"sha256:c556695b699f648c58373b542534308922c46a1cda06ea47bc9ca45ef5b39ae6",
"sha256:c86229333cabaaa8c51cf971496f10318c4734cf7b641f08af0a6fbf17ca3054",
"sha256:c8d7da6f1c1049eefb718d43d99ad73100c958a5367d30b9321b092771e96c25",
"sha256:c8e9dcf1ac499679aceedac7e7ca6d8641f0193c591a2d090282aaf8e9445a46",
"sha256:cb23bcc093697cdea2708baae4f9ba0e972960a835af22560f6ae4e7e47d33f5",
"sha256:d1e4c28f30e767fd07f2ddc6f74f41f034d1dd6bc526cd59e63a82fe8bb9ef4c",
"sha256:d9c9bdb3af48e242838f9f6e6127de9be7063aad17b32215ccc36a09c5cf1070",
"sha256:dee5ef83a76ac31ab0c78c10bd7d5437bfdb6358c95b91f1ba7ff7b76f9996a1",
"sha256:e0896200b6a40197405af18828da49f067c2fa1f821491bc8f5bde241ef3f7d7",
"sha256:f5a64b64ddf4c99fe201ac2724daada8595ada0d102ab96d019c1555c2d6441d",
"sha256:f947352c3434e8b937e3aa8f96f47bdfe6d92779e44bb3f41e4c213ba6a32145"
],
"index": "pypi",
"version": "==1.9.0"
},
"pyflakes": {
"hashes": [
"sha256:05a85c2872edf37a4ed30b0cce2f6093e1d0581f8c19d7393122da7e25b2b24c",
@ -1139,14 +1074,6 @@
],
"version": "==0.2.0"
},
"starlette": {
"hashes": [
"sha256:26a18cbda5e6b651c964c12c88b36d9898481cd428ed6e063f5f29c418f73050",
"sha256:57eab3cc975a28af62f6faec94d355a410634940f10b30d68d31cb5ec1b44ae8"
],
"markers": "python_version >= '3.6'",
"version": "==0.17.1"
},
"tokenize-rt": {
"hashes": [
"sha256:08a27fa032a81cf45e8858d0ac706004fcd523e8463415ddf1442be38e204ea8",
@ -1192,7 +1119,7 @@
"sha256:44ece4d53fb1706f667c9bd1c648f5469a2ec925fcf3a776667042d645472c14",
"sha256:aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4.0'",
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'",
"version": "==1.26.9"
},
"wcwidth": {

View File

@ -9,7 +9,7 @@ Example for [FastAPI](https://fastapi.tiangolo.com/) integration with [SQLAlchem
Beside of using latest and greatest version of [SQLAlchemy](https://www.sqlalchemy.org/) with it robustness, powerfulness and speed
of [asyncpg](https://github.com/MagicStack/asyncpg) there is [FastAPI](https://fastapi.tiangolo.com/) (modern, fast (high-performance),
web framework for building APIs with Python 3.10+ based on standard Python type hints.) already reviewed
web framework for building APIs with Python 3.7+ based on standard Python type hints.) already reviewed
on [thoughtworks](https://www.thoughtworks.com/radar/languages-and-frameworks?blipid=202104087).
@ -33,10 +33,13 @@ test Run project tests
up Run project with compose
```
Hope you enjoy it.
It tooks me a while to find nice data set. Hope shkezz as example will be able to cover
first part with read only declarative base and all type of selects :)
I took data set form https://github.com/catherinedevlin/opensourceshakespeare
Next generated declarative base with https://github.com/agronholm/sqlacodegen
And after soem twiking i get desired result
### How to feed database
It took me a while to find nice data set. Hope works of Shakespeare as example will be able to cover
first part with read only declarative base configuration and all type of funny selects :)
Data set is coming form https://github.com/catherinedevlin/opensourceshakespeare
Next models were generated with https://github.com/agronholm/sqlacodegen
And after some tweaking I got desired result
Hope you enjoy it.

View File

@ -1,4 +1,6 @@
from sqlalchemy import Column, ForeignKeyConstraint, Integer, PrimaryKeyConstraint, String, Table, Text, UniqueConstraint
from sqlalchemy import (Column, ForeignKeyConstraint, Integer,
PrimaryKeyConstraint, String, Table, Text,
UniqueConstraint)
from sqlalchemy.orm import declarative_base, relationship
Base = declarative_base()