Skip to content

Commit bc0e856

Browse files
committed
Add backend support for PostgreSQL
1 parent 44ac2c5 commit bc0e856

File tree

18 files changed

+195
-48
lines changed

18 files changed

+195
-48
lines changed

.github/workflows/main.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
name: Run CI
1+
name: Tests
22

33
on:
4+
pull_request: ~
45
push:
5-
pull_request:
6+
branches: [ main ]
7+
8+
# Allow job to be triggered manually.
69
workflow_dispatch:
710

11+
# Run job each night.
12+
schedule:
13+
- cron: '0 3 * * *'
14+
815
# Cancel in-progress jobs when pushing to the same branch.
916
concurrency:
1017
cancel-in-progress: true
@@ -30,6 +37,13 @@ jobs:
3037
max-parallel: 4
3138
matrix:
3239
python-version: [3.7, 3.8, 3.9, '3.10', '3.11']
40+
services:
41+
postgresql:
42+
image: postgres:16
43+
ports:
44+
- 5432:5432
45+
env:
46+
POSTGRES_HOST_AUTH_METHOD: trust
3347
steps:
3448
- uses: actions/checkout@v3
3549
- name: Set up Python ${{ matrix.python-version }}
@@ -59,6 +73,13 @@ jobs:
5973
ls -l dist
6074
documentation:
6175
runs-on: ubuntu-latest
76+
services:
77+
postgresql:
78+
image: postgres:16
79+
ports:
80+
- 5432:5432
81+
env:
82+
POSTGRES_HOST_AUTH_METHOD: trust
6283
steps:
6384
- uses: actions/checkout@v3
6485
- name: Setup python

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Release new version
1+
name: Release
22

33
on:
44
push:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ ENV/
113113
env.bak/
114114
venv.bak/
115115

116+
# PyCharm project settings
117+
.idea
118+
116119
# Spyder project settings
117120
.spyderproject
118121
.spyproject

README.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,23 @@ Usage
7979
Please access http://localhost:8000/search.html
8080
8181
82+
Development
83+
===========
84+
85+
Install package in development mode::
86+
87+
pip install --editable='.[cli,docs,test]' --prefer-binary
88+
89+
Start PostgreSQL server::
90+
91+
docker run --rm -it --publish=5432:5432 --env "POSTGRES_HOST_AUTH_METHOD=trust" postgres:16 postgres -c log_statement=all
92+
93+
Invoke software tests::
94+
95+
export POSTGRES_LOG_STATEMENT=all
96+
pytest -vvv
97+
98+
8299
.. _atsphinx-sqlite3fts: https://pypi.org/project/atsphinx-sqlite3fts/
83100
.. _Kazuya Takei: https://github.com/attakei
84101
.. _readthedocs-sphinx-search: https://github.com/readthedocs/readthedocs-sphinx-search

docs/_static/.gitkeep

Whitespace-only changes.

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
}
3333
# atsphinx-sqlite3fts
3434
sqlite3fts_use_search_html = True
35+
sqlite3fts_database_url = "postgresql://postgres@localhost:5432"
3536

3637

3738
def setup(app): # noqa: D103

docs/getting-started.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ You can build database by ``sqlite`` builder.
4747

4848
.. code-block:: console
4949
50-
make sqlite
51-
sqlite3 _build/sqlite/db.sqlite
50+
make fts-index
51+
52+
.. code-block:: console
53+
54+
psql postgresql://postgres@localhost:5432/ --command 'SELECT * FROM document;'
5255
5356
.. code-block:: sqlite3
5457

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dynamic = ["version", "description"]
3535
dependencies = [
3636
"docutils",
3737
"peewee",
38+
"psycopg2[binary]",
3839
"Sphinx",
3940
]
4041

src/atsphinx/sqlite3fts/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Sphinx document searcher using SQLite3."""
1+
"""Sphinx document searcher using SQL database."""
22
from sphinx.application import Sphinx
33

44
from . import builders, events
@@ -10,9 +10,10 @@ def setup(app: Sphinx):
1010
"""Entrypoint as Sphinx extension."""
1111
app.add_config_value("sqlite3fts_exclude_pages", [], "env")
1212
app.add_config_value("sqlite3fts_use_search_html", False, "env")
13-
app.add_builder(builders.SqliteBuilder)
13+
app.add_config_value("sqlite3fts_database_url", None, "env")
14+
app.add_builder(builders.FtsIndexer)
1415
app.connect("config-inited", events.setup_search_html)
15-
app.connect("builder-inited", events.configure_database)
16+
app.connect("config-inited", events.configure_database)
1617
app.connect("html-page-context", events.register_document)
1718
app.connect("build-finished", events.save_database)
1819
return {

src/atsphinx/sqlite3fts/builders.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from . import models, services
88

99

10-
class SqliteBuilder(Builder):
10+
class FtsIndexer(Builder):
1111
"""Single database generation builder.
1212
1313
This is custom builder to generate only SQLite database file
1414
"""
1515

16-
name = "sqlite"
16+
name = "fts-index"
1717
allow_parallel = True
1818

1919
def get_target_uri(self, docname: str, typ: str = None) -> str: # noqa: D102
@@ -23,7 +23,11 @@ def get_outdated_docs(self) -> str: # noqa: D102
2323
return "db.sqlite"
2424

2525
def prepare_writing(self, docnames: Set[str]) -> None: # noqa: D102
26-
pass
26+
from atsphinx.sqlite3fts.models import Content, Document, Section
27+
28+
Document.truncate_table(cascade=True)
29+
Section.truncate_table(cascade=True)
30+
Content.truncate_table(cascade=True)
2731

2832
def write_doc(self, docname: str, doctree: nodes.document) -> None:
2933
"""Register content of document into database.

0 commit comments

Comments
 (0)