Skip to content

Commit e7b1290

Browse files
chrisemkeKrisque
authored andcommitted
sqlmodel (#1)
add sqlmodel orm; create all address query based on types and inputs created from sqlmodel models; fix dockerfiles and compose; drop edgedb (technical unfeasibility) see changelog file Reviewed-on: https://codeberg.org/Krisque/jacobson/pulls/1 Co-authored-by: Christian G. Semke <[email protected]> Co-committed-by: Christian G. Semke <[email protected]>
1 parent fd47651 commit e7b1290

33 files changed

+3587
-1618
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ end_of_line = lf
1010
charset = utf-8
1111
trim_trailing_whitespace = true
1212
insert_final_newline = true
13+
14+
[*.{py,pyi}]
15+
max_line_length = 80

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,6 @@ dmypy.json
133133

134134
# vscode
135135
.vscode
136+
137+
# database data
138+
docker/database/data/

.pre-commit-config.yaml

Lines changed: 74 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,75 @@
11
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.4.0
4-
hooks:
5-
- id: trailing-whitespace
6-
- id: end-of-file-fixer
7-
- id: check-yaml
8-
- id: check-added-large-files
9-
- id: check-toml
10-
- repo: https://github.com/psf/black
11-
rev: 23.3.0
12-
hooks:
13-
- id: black
14-
- repo: https://github.com/astral-sh/ruff-pre-commit
15-
rev: v0.0.270
16-
hooks:
17-
- id: ruff
18-
args: [--fix, --exit-non-zero-on-fix]
19-
- repo: https://github.com/pre-commit/mirrors-mypy
20-
rev: v1.3.0
21-
hooks:
22-
- id: mypy
23-
- repo: https://github.com/python-poetry/poetry
24-
rev: "1.5.0"
25-
hooks:
26-
- id: poetry-check
27-
- id: poetry-lock
28-
- id: poetry-export
29-
args: ["-f", "requirements.txt", "-o", "requirements.txt"]
30-
- repo: https://github.com/compilerla/conventional-pre-commit
31-
rev: v2.3.0
32-
hooks:
33-
- id: conventional-pre-commit
34-
stages: [commit-msg]
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.6.0
4+
hooks:
5+
- id: end-of-file-fixer
6+
- id: trailing-whitespace
7+
- id: mixed-line-ending
8+
- id: check-byte-order-marker
9+
- id: check-executables-have-shebangs
10+
- id: check-merge-conflict
11+
- id: check-symlinks
12+
- id: check-vcs-permalinks
13+
- id: debug-statements
14+
- id: check-yaml
15+
files: .*\.(yaml|yml)$
16+
- id: check-added-large-files
17+
- id: check-toml
18+
- repo: https://github.com/Lucas-C/pre-commit-hooks
19+
rev: v1.5.5
20+
hooks:
21+
- id: insert-license
22+
name: Add license for all python files
23+
files: \.py$|\.pyi$
24+
args:
25+
[
26+
--comment-style,
27+
'"""||"""',
28+
--license-filepath,
29+
license-templates/LICENSE.txt,
30+
--fuzzy-match-generates-todo,
31+
--use-current-year,
32+
--no-space,
33+
]
34+
- id: insert-license
35+
name: Add license for all Markdown files
36+
files: \.md$
37+
args:
38+
[
39+
--comment-style,
40+
'<!--||-->',
41+
--license-filepath,
42+
license-templates/LICENSE.txt,
43+
--fuzzy-match-generates-todo,
44+
--no-space,
45+
]
46+
- repo: https://github.com/astral-sh/ruff-pre-commit
47+
rev: v0.3.5
48+
hooks:
49+
- id: ruff
50+
name: Run Ruff Linter & Formater
51+
args: [--fix, --exit-non-zero-on-fix]
52+
- id: ruff-format
53+
name: Run Ruff Formater
54+
- repo: https://github.com/pre-commit/mirrors-mypy
55+
rev: v1.9.0
56+
hooks:
57+
- id: mypy
58+
name: Run Mypy (Static type checker)
59+
exclude: "jacobson"
60+
additional_dependencies: [strawberry-graphql, pydantic, pydantic-settings, sqlmodel]
61+
- repo: https://github.com/python-poetry/poetry
62+
rev: "1.8.0"
63+
hooks:
64+
- id: poetry-check
65+
- id: poetry-lock
66+
- id: poetry-export
67+
args: [-f, requirements.txt, -o, requirements.txt]
68+
- repo: https://github.com/commitizen-tools/commitizen
69+
rev: v3.21.3
70+
hooks:
71+
- id: commitizen
72+
- id: commitizen-branch
73+
stages:
74+
- post-commit
75+
- push

CHANGELOG.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--
2+
Jacobson is a self hosted zipcode API
3+
Copyright (C) 2023-2024 Christian G. Semke.
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as
7+
published by the Free Software Foundation, either version 3 of the
8+
License, or (at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
-->
18+
19+
## Unreleased
20+
21+
### BREAKING CHANGE
22+
23+
- The query has completely changed IO
24+
25+
### Feat
26+
27+
- **sqlmodel-mariadb**: add sqlmodel models, create async session, create tables on startup and add query function with beta filters
28+
- Initial commit
29+
30+
### Fix
31+
32+
- some docker files
33+
- continued fixing some wrong features
34+
- **Hooks**: Validate merge branches
35+
36+
### Refactor
37+
38+
- **pydantic**: move pydantic models to sqlmodel models
39+
- **edgedb-jacobson**: remove edgedb and legacy jacobson
40+
- **graphql-query**: add pydantic and strawberry types to query
41+
- start edgedb support
42+
- create docker folders and minor fixes

LICENSE renamed to LICENSE.txt

File renamed without changes.

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,49 @@
1+
<!--
2+
Jacobson is a self hosted zipcode API
3+
Copyright (C) 2023-2024 Christian G. Semke.
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as
7+
published by the Free Software Foundation, either version 3 of the
8+
License, or (at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
-->
18+
119
# jacobson
220
self-hosted zipcode API
21+
22+
23+
### The initial structure I imagined would be:
24+
```
25+
*api query/get* -> search in database -> if there is any result return;
26+
else async call to all plugins that are configured, return and insert on database
27+
```
28+
```
29+
*api mutation/post* -> manually update or insert zipcodes
30+
```
31+
```
32+
call to tell the api to update some register from plugins that are configured
33+
```
34+
35+
# TODO
36+
- [x] git hooks (pre-commit)
37+
- [x] SqlModel
38+
- [ ] Api's support plugin-like (cepaberto, brazilapi...)
39+
- [ ] Tests (pytest)
40+
- [ ] Docs (mkdocs)
41+
- [ ] fix podman pod for all devs (see jacobson-dev.yaml)
42+
- [ ] Alembic migrations
43+
44+
45+
# DEV
46+
The idea is to just run this command and podman will run the entire dev environment
47+
```bash
48+
podman compose up -d --build
49+
```

api/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Jacobson is a self hosted zipcode API
3+
Copyright (C) 2023-2024 Christian G. Semke.
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as
7+
published by the Free Software Foundation, either version 3 of the
8+
License, or (at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
"""

api/address/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Jacobson is a self hosted zipcode API
3+
Copyright (C) 2023-2024 Christian G. Semke.
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as
7+
published by the Free Software Foundation, either version 3 of the
8+
License, or (at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
"""

api/address/inputs.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
Jacobson is a self hosted zipcode API
3+
Copyright (C) 2023-2024 Christian G. Semke.
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as
7+
published by the Free Software Foundation, either version 3 of the
8+
License, or (at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
"""
18+
19+
from strawberry import auto, input
20+
from strawberry.experimental.pydantic import input as pydantic_input
21+
22+
from database.models.brazil import AddressBase, City, State
23+
24+
25+
@pydantic_input(model=State)
26+
class StateInput:
27+
name: auto
28+
acronym: auto
29+
30+
31+
@pydantic_input(model=City)
32+
class CityInput:
33+
ibge: auto
34+
name: auto
35+
ddd: auto
36+
37+
38+
@input
39+
class CoordinatesInput:
40+
latitude: float
41+
longitude: float
42+
altitude: float | None = None
43+
44+
45+
@pydantic_input(model=AddressBase)
46+
class AddressInput:
47+
zipcode: auto
48+
city: CityInput | None = None
49+
state: StateInput | None = None
50+
neighborhood: auto
51+
complement: auto
52+
# coordinates: CoordinatesInput | None = None

api/address/types.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
Jacobson is a self hosted zipcode API
3+
Copyright (C) 2023-2024 Christian G. Semke.
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as
7+
published by the Free Software Foundation, either version 3 of the
8+
License, or (at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
"""
18+
19+
from strawberry import auto, type
20+
from strawberry.experimental.pydantic import type as pydantic_type
21+
22+
from database.models.brazil import Address, City, State
23+
24+
DATABASE_USER = "teste"
25+
DATABASE_PASSWORD = "teste"
26+
DATABASE_HOST = "db"
27+
DATABASE_PORT = 3306
28+
DATABASE_NAME = "test"
29+
30+
@pydantic_type(name='State', model=State)
31+
class StateType:
32+
name: auto
33+
acronym: auto
34+
35+
36+
@pydantic_type(name='City', model=City)
37+
class CityType:
38+
ibge: auto
39+
name: auto
40+
ddd: auto
41+
42+
43+
@type(name='Coordinates')
44+
class CoordinatesType:
45+
latitude: float
46+
longitude: float
47+
altitude: float
48+
49+
50+
@pydantic_type(name='Address', model=Address)
51+
class AddressType:
52+
zipcode: auto
53+
city: CityType
54+
state: StateType
55+
neighborhood: auto
56+
complement: auto
57+
coordinates: CoordinatesType | None = None

0 commit comments

Comments
 (0)