Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag datetime fix #155

Merged
merged 15 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/stability.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ jobs:
- name: Run black checks
run: black --check --verbose --diff --color src/

- name: Run mypy checks
run: mypy src/
# This is currently disabled because MyPy is very confused about Coroutine types
# - name: Run mypy checks
# run: mypy --explicit-package-bases src/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ manifest/
.mypy_cache/
.ruff_cache/
tests/db_snapshots/
logs/
7 changes: 6 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
- SURREAL_PASS=root
- SURREAL_INSECURE_FORWARD_ACCESS_ERRORS=true
- SURREAL_LOG=debug
- SURREAL_CAPS_ALLOW_GUESTS=true
ports:
- 8000:8000

Expand All @@ -18,6 +19,7 @@ services:
- SURREAL_USER=root
- SURREAL_PASS=root
- SURREAL_LOG=trace
- SURREAL_CAPS_ALLOW_GUESTS=true
ports:
- 8121:8000

Expand All @@ -28,6 +30,7 @@ services:
- SURREAL_USER=root
- SURREAL_PASS=root
- SURREAL_LOG=trace
- SURREAL_CAPS_ALLOW_GUESTS=true
ports:
- 8120:8000

Expand All @@ -38,6 +41,7 @@ services:
- SURREAL_USER=root
- SURREAL_PASS=root
- SURREAL_LOG=trace
- SURREAL_CAPS_ALLOW_GUESTS=true
ports:
- 8101:8000

Expand All @@ -48,5 +52,6 @@ services:
- SURREAL_USER=root
- SURREAL_PASS=root
- SURREAL_LOG=trace
- SURREAL_CAPS_ALLOW_GUESTS=true
ports:
- 8111:8000
- 8111:8000
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,17 @@ Homepage = "https://github.com/surrealdb/surrealdb.py"
[tool.setuptools.packages.find]
where = ["src"]

[tool.ruff]
exclude = ["src/surrealdb/__init__.py"]

[tool.mypy]
mypy_path = "src"
explicit_package_bases = true
disable_error_code = ["return-value", "return-type"]

[[tool.mypy.overrides]]
module = "cerberus.*"
ignore_missing_imports = true

# [project.scripts]
# sdblpy = "sblpy.cli.entrypoint:main"
19 changes: 19 additions & 0 deletions scripts/run_stability_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

# navigate to directory
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
cd $SCRIPTPATH

cd ..

if [ -d ./logs ]; then
echo "log directory exists being removed"
rm -rf ./logs
fi

mkdir logs

ruff check src/ > ./logs/ruff_check.log
black src/
black --check --verbose --diff --color src/ > ./logs/black_check.log
mypy --explicit-package-bases src/ > ./logs/mypy_check.log
68 changes: 53 additions & 15 deletions src/surrealdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

from surrealdb.data.types.table import Table
from surrealdb.data.types.constants import *
from surrealdb.data.types.datetime import DateTimeCompact
from surrealdb.data.types.duration import Duration
from surrealdb.data.types.future import Future
from surrealdb.data.types.geometry import Geometry
from surrealdb.data.types.range import Range
from surrealdb.data.types.record_id import RecordID
from surrealdb.data.types.datetime import IsoDateTimeWrapper


class AsyncSurrealDBMeta(type):

Expand All @@ -28,12 +29,20 @@ def __call__(cls, *args, **kwargs):

constructed_url = Url(url)

if constructed_url.scheme == UrlScheme.HTTP or constructed_url.scheme == UrlScheme.HTTPS:
if (
constructed_url.scheme == UrlScheme.HTTP
or constructed_url.scheme == UrlScheme.HTTPS
):
return AsyncHttpSurrealConnection(url=url)
elif constructed_url.scheme == UrlScheme.WS or constructed_url.scheme == UrlScheme.WSS:
elif (
constructed_url.scheme == UrlScheme.WS
or constructed_url.scheme == UrlScheme.WSS
):
return AsyncWsSurrealConnection(url=url)
else:
raise ValueError(f"Unsupported protocol in URL: {url}. Use 'ws://' or 'http://'.")
raise ValueError(
f"Unsupported protocol in URL: {url}. Use 'ws://' or 'http://'."
)


class BlockingSurrealDBMeta(type):
Expand All @@ -50,28 +59,57 @@ def __call__(cls, *args, **kwargs):

constructed_url = Url(url)

if constructed_url.scheme == UrlScheme.HTTP or constructed_url.scheme == UrlScheme.HTTPS:
if (
constructed_url.scheme == UrlScheme.HTTP
or constructed_url.scheme == UrlScheme.HTTPS
):
return BlockingHttpSurrealConnection(url=url)
elif constructed_url.scheme == UrlScheme.WS or constructed_url.scheme == UrlScheme.WSS:
elif (
constructed_url.scheme == UrlScheme.WS
or constructed_url.scheme == UrlScheme.WSS
):
return BlockingWsSurrealConnection(url=url)
else:
raise ValueError(f"Unsupported protocol in URL: {url}. Use 'ws://' or 'http://'.")
raise ValueError(
f"Unsupported protocol in URL: {url}. Use 'ws://' or 'http://'."
)


def Surreal(url: Optional[str] = None) -> Union[BlockingWsSurrealConnection, BlockingHttpSurrealConnection]:
def Surreal(
url: Optional[str] = None,
) -> Union[BlockingWsSurrealConnection, BlockingHttpSurrealConnection]:
constructed_url = Url(url)
if constructed_url.scheme == UrlScheme.HTTP or constructed_url.scheme == UrlScheme.HTTPS:
if (
constructed_url.scheme == UrlScheme.HTTP
or constructed_url.scheme == UrlScheme.HTTPS
):
return BlockingHttpSurrealConnection(url=url)
elif constructed_url.scheme == UrlScheme.WS or constructed_url.scheme == UrlScheme.WSS:
elif (
constructed_url.scheme == UrlScheme.WS
or constructed_url.scheme == UrlScheme.WSS
):
return BlockingWsSurrealConnection(url=url)
else:
raise ValueError(f"Unsupported protocol in URL: {url}. Use 'ws://' or 'http://'.")
raise ValueError(
f"Unsupported protocol in URL: {url}. Use 'ws://' or 'http://'."
)


def AsyncSurreal(url: Optional[str] = None) -> Union[AsyncWsSurrealConnection, AsyncHttpSurrealConnection]:
def AsyncSurreal(
url: Optional[str] = None,
) -> Union[AsyncWsSurrealConnection, AsyncHttpSurrealConnection]:
constructed_url = Url(url)
if constructed_url.scheme == UrlScheme.HTTP or constructed_url.scheme == UrlScheme.HTTPS:
if (
constructed_url.scheme == UrlScheme.HTTP
or constructed_url.scheme == UrlScheme.HTTPS
):
return AsyncHttpSurrealConnection(url=url)
elif constructed_url.scheme == UrlScheme.WS or constructed_url.scheme == UrlScheme.WSS:
elif (
constructed_url.scheme == UrlScheme.WS
or constructed_url.scheme == UrlScheme.WSS
):
return AsyncWsSurrealConnection(url=url)
else:
raise ValueError(f"Unsupported protocol in URL: {url}. Use 'ws://' or 'http://'.")
raise ValueError(
f"Unsupported protocol in URL: {url}. Use 'ws://' or 'http://'."
)
Loading