Skip to content

Add support for spatialite database backend #439

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

Merged
merged 1 commit into from
Oct 1, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-22.04]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-24.04]
runs-on: ${{ matrix.os }}
name: "${{ matrix.os }} Python: ${{ matrix.python-version }}"
services:
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Install OS Packages
run: |
sudo apt-get update
sudo apt-get install binutils libproj-dev gdal-bin libmemcached-dev
sudo apt-get install binutils libproj-dev gdal-bin libmemcached-dev libsqlite3-mod-spatialite
- uses: actions/checkout@v3
with:
fetch-depth: 0
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions django_prometheus/db/backends/spatialite/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.contrib.gis.db.backends.spatialite import base, features
from django.db.backends.sqlite3 import base as sqlite_base

from django_prometheus.db.common import DatabaseWrapperMixin


class DatabaseFeatures(features.DatabaseFeatures):
"""Our database has the exact same features as the base one."""

pass


class DatabaseWrapper(DatabaseWrapperMixin, base.DatabaseWrapper):
CURSOR_CLASS = sqlite_base.SQLiteCursorWrapper
4 changes: 4 additions & 0 deletions django_prometheus/tests/end2end/testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
"HOST": "127.0.0.1",
"PORT": "3306",
},
"spatialite": {
"ENGINE": "django_prometheus.db.backends.spatialite",
"NAME": "db_spatialite.sqlite3",
},
# The following databases are used by test_db.py only
"test_db_1": {
"ENGINE": "django_prometheus.db.backends.sqlite3",
Expand Down
32 changes: 32 additions & 0 deletions django_prometheus/tests/end2end/testapp/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,35 @@ def test_counters(self):
alias="postgis",
vendor="postgresql",
)


@pytest.mark.skipif("spatialite" not in connections, reason="Skipped unless spatialite database is enabled")
class TestSpatialiteDbMetrics(BaseDBTest):
"""Test django_prometheus.db metrics for spatialite backend.

Note regarding the values of metrics: many tests interact with the
database, and the test runner itself does. As such, tests that
require that a metric has a specific value are at best very
fragile. Consider asserting that the value exceeds a certain
threshold, or check by how much it increased during the test.
"""

def test_counters(self):
r = save_registry()
connection = connections["spatialite"]

# Make sure the extension is loaded and geospatial tables are created
connection.prepare_database()

cursor = connection.cursor()

for _ in range(20):
cursor.execute("SELECT 1")

assert_metric_compare(
r,
lambda a, b: a + 20 <= b < a + 25,
"django_db_execute_total",
alias="spatialite",
vendor="sqlite",
)
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ legacy_tox_ini = """
[tox]
min_version = 4.4
envlist =
{py37,py38,py39,py310,py311}-django{320}-{end2end,unittests}
{py38,py39,py310,py311}-django{320}-{end2end,unittests}
{py38,py39,py310,py311,py312}-django{400,410,420}-{end2end,unittests}
{py310,py311,py312}-django{500,510}-{end2end,unittests}
py39-lint

[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39, py39-lint
3.10: py310
Expand Down
Loading