Skip to content

Commit

Permalink
Merge branch 'main' into async
Browse files Browse the repository at this point in the history
  • Loading branch information
PookieBuns authored Nov 5, 2023
2 parents af84d75 + e05eae6 commit fb60073
Show file tree
Hide file tree
Showing 28 changed files with 663 additions and 214 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: python -m poetry install
- name: Install Material for MkDocs Insiders
if: ( github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false ) && steps.cache.outputs.cache-hit != 'true'
if: ( github.event_name != 'pull_request' || github.secret_source == 'Actions' ) && steps.cache.outputs.cache-hit != 'true'
run: python -m poetry run pip install git+https://${{ secrets.SQLMODEL_MKDOCS_MATERIAL_INSIDERS }}@github.com/squidfunk/mkdocs-material-insiders.git
- uses: actions/cache@v3
with:
key: mkdocs-cards-${{ github.ref }}
path: .cache
- name: Build Docs
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true
if: github.event_name == 'pull_request' && github.secret_source != 'Actions'
run: python -m poetry run mkdocs build
- name: Build Docs with Insiders
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false
if: github.event_name != 'pull_request' || github.secret_source == 'Actions'
run: python -m poetry run mkdocs build --config-file mkdocs.insiders.yml
- uses: actions/upload-artifact@v3
with:
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/latest-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ jobs:
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true' }}
with:
limit-access-to-actor: true
- uses: docker://tiangolo/latest-changes:0.0.3
- uses: docker://tiangolo/latest-changes:0.2.0
# - uses: tiangolo/latest-changes@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
latest_changes_file: docs/release-notes.md
latest_changes_header: '## Latest Changes\n\n'
latest_changes_header: '## Latest Changes'
end_regex: '^## '
debug_logs: true
label_header_prefix: '### '
16 changes: 3 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,13 @@ repos:
- --unsafe
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args:
- --py3-plus
- --keep-runtime-typing
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.1
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.2
hooks:
- id: ruff
args:
- --fix
- repo: https://github.com/psf/black
rev: 23.10.0
hooks:
- id: black
- id: ruff-format
ci:
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate
34 changes: 34 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@

## Latest Changes

### Internal

* 👷 Upgrade latest-changes GitHub Action. PR [#693](https://github.com/tiangolo/sqlmodel/pull/693) by [@tiangolo](https://github.com/tiangolo).

## 0.0.11

### Features

* ✨ Add support for passing a custom SQLAlchemy type to `Field()` with `sa_type`. PR [#505](https://github.com/tiangolo/sqlmodel/pull/505) by [@maru0123-2004](https://github.com/maru0123-2004).
* You might consider this a breaking change if you were using an incompatible combination of arguments, those arguments were not taking effect and now you will have a type error and runtime error telling you that.
* ✨ Do not allow invalid combinations of field parameters for columns and relationships, `sa_column` excludes `sa_column_args`, `primary_key`, `nullable`, etc. PR [#681](https://github.com/tiangolo/sqlmodel/pull/681) by [@tiangolo](https://github.com/tiangolo).

### Docs

* 🎨 Update inline source examples, hide `#` in annotations (from MkDocs Material). PR [#677](https://github.com/tiangolo/sqlmodel/pull/677) by [@Matthieu-LAURENT39](https://github.com/Matthieu-LAURENT39).

### Internal

* ⬆ Update coverage requirement from ^6.2 to >=6.2,<8.0. PR [#663](https://github.com/tiangolo/sqlmodel/pull/663) by [@dependabot[bot]](https://github.com/apps/dependabot).
* ⬆ Update mkdocs-material requirement from 9.1.21 to 9.2.7. PR [#675](https://github.com/tiangolo/sqlmodel/pull/675) by [@dependabot[bot]](https://github.com/apps/dependabot).
* ⬆️ Upgrade mypy manually. PR [#684](https://github.com/tiangolo/sqlmodel/pull/684) by [@tiangolo](https://github.com/tiangolo).
* ⬆ Update black requirement from ^22.10.0 to >=22.10,<24.0. PR [#664](https://github.com/tiangolo/sqlmodel/pull/664) by [@dependabot[bot]](https://github.com/apps/dependabot).
* 👷 Update CI to build MkDocs Insiders only when the secrets are available, for Dependabot. PR [#683](https://github.com/tiangolo/sqlmodel/pull/683) by [@tiangolo](https://github.com/tiangolo).

## 0.0.10

### Features

* ✨ Add support for all `Field` parameters from Pydantic `1.9.0` and above, make Pydantic `1.9.0` the minimum required version. PR [#440](https://github.com/tiangolo/sqlmodel/pull/440) by [@daniil-berg](https://github.com/daniil-berg).

### Internal

* 🔧 Adopt Ruff for formatting. PR [#679](https://github.com/tiangolo/sqlmodel/pull/679) by [@tiangolo](https://github.com/tiangolo).

## 0.0.9

### Breaking Changes
Expand Down
100 changes: 50 additions & 50 deletions docs_src/tutorial/automatic_id_none_refresh/tutorial002.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,56 +21,56 @@ def create_db_and_tables():


def create_heroes():
hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson") # (1)
hero_2 = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") # (2)
hero_3 = Hero(name="Rusty-Man", secret_name="Tommy Sharp", age=48) # (3)

print("Before interacting with the database") # (4)
print("Hero 1:", hero_1) # (5)
print("Hero 2:", hero_2) # (6)
print("Hero 3:", hero_3) # (7)

with Session(engine) as session: # (8)
session.add(hero_1) # (9)
session.add(hero_2) # (10)
session.add(hero_3) # (11)

print("After adding to the session") # (12)
print("Hero 1:", hero_1) # (13)
print("Hero 2:", hero_2) # (14)
print("Hero 3:", hero_3) # (15)

session.commit() # (16)

print("After committing the session") # (17)
print("Hero 1:", hero_1) # (18)
print("Hero 2:", hero_2) # (19)
print("Hero 3:", hero_3) # (20)

print("After committing the session, show IDs") # (21)
print("Hero 1 ID:", hero_1.id) # (22)
print("Hero 2 ID:", hero_2.id) # (23)
print("Hero 3 ID:", hero_3.id) # (24)

print("After committing the session, show names") # (25)
print("Hero 1 name:", hero_1.name) # (26)
print("Hero 2 name:", hero_2.name) # (27)
print("Hero 3 name:", hero_3.name) # (28)

session.refresh(hero_1) # (29)
session.refresh(hero_2) # (30)
session.refresh(hero_3) # (31)

print("After refreshing the heroes") # (32)
print("Hero 1:", hero_1) # (33)
print("Hero 2:", hero_2) # (34)
print("Hero 3:", hero_3) # (35)
# (36)

print("After the session closes") # (37)
print("Hero 1:", hero_1) # (38)
print("Hero 2:", hero_2) # (39)
print("Hero 3:", hero_3) # (40)
hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson") # (1)!
hero_2 = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") # (2)!
hero_3 = Hero(name="Rusty-Man", secret_name="Tommy Sharp", age=48) # (3)!

print("Before interacting with the database") # (4)!
print("Hero 1:", hero_1) # (5)!
print("Hero 2:", hero_2) # (6)!
print("Hero 3:", hero_3) # (7)!

with Session(engine) as session: # (8)!
session.add(hero_1) # (9)!
session.add(hero_2) # (10)!
session.add(hero_3) # (11)!

print("After adding to the session") # (12)!
print("Hero 1:", hero_1) # (13)!
print("Hero 2:", hero_2) # (14)!
print("Hero 3:", hero_3) # (15)!

session.commit() # (16)!

print("After committing the session") # (17)!
print("Hero 1:", hero_1) # (18)!
print("Hero 2:", hero_2) # (19)!
print("Hero 3:", hero_3) # (20)!

print("After committing the session, show IDs") # (21)!
print("Hero 1 ID:", hero_1.id) # (22)!
print("Hero 2 ID:", hero_2.id) # (23)!
print("Hero 3 ID:", hero_3.id) # (24)!

print("After committing the session, show names") # (25)!
print("Hero 1 name:", hero_1.name) # (26)!
print("Hero 2 name:", hero_2.name) # (27)!
print("Hero 3 name:", hero_3.name) # (28)!

session.refresh(hero_1) # (29)!
session.refresh(hero_2) # (30)!
session.refresh(hero_3) # (31)!

print("After refreshing the heroes") # (32)!
print("Hero 1:", hero_1) # (33)!
print("Hero 2:", hero_2) # (34)!
print("Hero 3:", hero_3) # (35)!
# (36)!

print("After the session closes") # (37)!
print("Hero 1:", hero_1) # (38)!
print("Hero 2:", hero_2) # (39)!
print("Hero 3:", hero_3) # (40)!


def main():
Expand Down
28 changes: 14 additions & 14 deletions docs_src/tutorial/create_db_and_table/tutorial003.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
from typing import Optional # (1)
from typing import Optional # (1)!

from sqlmodel import Field, SQLModel, create_engine # (2)
from sqlmodel import Field, SQLModel, create_engine # (2)!


class Hero(SQLModel, table=True): # (3)
id: Optional[int] = Field(default=None, primary_key=True) # (4)
name: str # (5)
secret_name: str # (6)
age: Optional[int] = None # (7)
class Hero(SQLModel, table=True): # (3)!
id: Optional[int] = Field(default=None, primary_key=True) # (4)!
name: str # (5)!
secret_name: str # (6)!
age: Optional[int] = None # (7)!


sqlite_file_name = "database.db" # (8)
sqlite_url = f"sqlite:///{sqlite_file_name}" # (9)
sqlite_file_name = "database.db" # (8)!
sqlite_url = f"sqlite:///{sqlite_file_name}" # (9)!

engine = create_engine(sqlite_url, echo=True) # (10)
engine = create_engine(sqlite_url, echo=True) # (10)!


def create_db_and_tables(): # (11)
SQLModel.metadata.create_all(engine) # (12)
def create_db_and_tables(): # (11)!
SQLModel.metadata.create_all(engine) # (12)!


if __name__ == "__main__": # (13)
create_db_and_tables() # (14)
if __name__ == "__main__": # (13)!
create_db_and_tables() # (14)!
26 changes: 13 additions & 13 deletions docs_src/tutorial/delete/tutorial002.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,23 @@ def update_heroes():

def delete_heroes():
with Session(engine) as session:
statement = select(Hero).where(Hero.name == "Spider-Youngster") # (1)
results = session.exec(statement) # (2)
hero = results.one() # (3)
print("Hero: ", hero) # (4)
statement = select(Hero).where(Hero.name == "Spider-Youngster") # (1)!
results = session.exec(statement) # (2)!
hero = results.one() # (3)!
print("Hero: ", hero) # (4)!

session.delete(hero) # (5)
session.commit() # (6)
session.delete(hero) # (5)!
session.commit() # (6)!

print("Deleted hero:", hero) # (7)
print("Deleted hero:", hero) # (7)!

statement = select(Hero).where(Hero.name == "Spider-Youngster") # (8)
results = session.exec(statement) # (9)
hero = results.first() # (10)
statement = select(Hero).where(Hero.name == "Spider-Youngster") # (8)!
results = session.exec(statement) # (9)!
hero = results.first() # (10)!

if hero is None: # (11)
print("There's no hero named Spider-Youngster") # (12)
# (13)
if hero is None: # (11)!
print("There's no hero named Spider-Youngster") # (12)!
# (13)!


def main():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastapi.testclient import TestClient
from sqlmodel import Session, SQLModel, create_engine

from .main import app, get_session # (1)
from .main import app, get_session # (1)!


def test_create_hero():
Expand All @@ -17,16 +17,16 @@ def get_session_override():

app.dependency_overrides[get_session] = get_session_override

client = TestClient(app) # (2)
client = TestClient(app) # (2)!

response = client.post( # (3)
response = client.post( # (3)!
"/heroes/", json={"name": "Deadpond", "secret_name": "Dive Wilson"}
)
app.dependency_overrides.clear()
data = response.json() # (4)
data = response.json() # (4)!

assert response.status_code == 200 # (5)
assert data["name"] == "Deadpond" # (6)
assert data["secret_name"] == "Dive Wilson" # (7)
assert data["age"] is None # (8)
assert data["id"] is not None # (9)
assert response.status_code == 200 # (5)!
assert data["name"] == "Deadpond" # (6)!
assert data["secret_name"] == "Dive Wilson" # (7)!
assert data["age"] is None # (8)!
assert data["id"] is not None # (9)!
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastapi.testclient import TestClient
from sqlmodel import Session, SQLModel, create_engine

from .main import app, get_session # (1)
from .main import app, get_session # (1)!


def test_create_hero():
Expand All @@ -12,17 +12,17 @@ def test_create_hero():

with Session(engine) as session:

def get_session_override(): # (2)
return session # (3)
def get_session_override(): # (2)!
return session # (3)!

app.dependency_overrides[get_session] = get_session_override # (4)
app.dependency_overrides[get_session] = get_session_override # (4)!

client = TestClient(app)

response = client.post(
"/heroes/", json={"name": "Deadpond", "secret_name": "Dive Wilson"}
)
app.dependency_overrides.clear() # (5)
app.dependency_overrides.clear() # (5)!
data = response.json()

assert response.status_code == 200
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from fastapi.testclient import TestClient
from sqlmodel import Session, SQLModel, create_engine

from .main import app, get_session # (1)
from .main import app, get_session # (1)!


def test_create_hero():
engine = create_engine( # (2)
engine = create_engine( # (2)!
"sqlite:///testing.db", connect_args={"check_same_thread": False}
)
SQLModel.metadata.create_all(engine) # (3)
SQLModel.metadata.create_all(engine) # (3)!

with Session(engine) as session: # (4)
with Session(engine) as session: # (4)!

def get_session_override():
return session # (5)
return session # (5)!

app.dependency_overrides[get_session] = get_session_override # (4)
app.dependency_overrides[get_session] = get_session_override # (4)!

client = TestClient(app)

Expand All @@ -30,4 +30,4 @@ def get_session_override():
assert data["secret_name"] == "Dive Wilson"
assert data["age"] is None
assert data["id"] is not None
# (6)
# (6)!
Loading

0 comments on commit fb60073

Please sign in to comment.