Skip to content

Commit

Permalink
feat(experimental): postgres support
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeldking committed Apr 6, 2024
1 parent 30b2ab0 commit a2657d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/phoenix/db/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ def set_sqlite_pragma(connection: Connection, _: Any) -> None:
cursor.close()


def get_db_url(driver: str = "sqlite+aiosqlite", database: Union[str, Path] = ":memory:") -> URL:
return URL.create(driver, database=str(database))


def aiosqlite_engine(
database: Union[str, Path] = ":memory:",
echo: bool = False,
) -> AsyncEngine:
driver_name = "sqlite+aiosqlite"
url = URL.create(driver_name, database=str(database))
url = get_db_url(driver="sqlite+aiosqlite", database=database)
engine = create_async_engine(url=url, echo=echo, json_serializer=_dumps)
event.listen(engine.sync_engine, "connect", set_sqlite_pragma)
if str(database) == ":memory:":
Expand Down
7 changes: 4 additions & 3 deletions src/phoenix/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from phoenix.core.traces import Traces
from phoenix.datasets.dataset import EMPTY_DATASET, Dataset
from phoenix.datasets.fixtures import FIXTURES, get_datasets
from phoenix.db.engines import aiosqlite_engine
from phoenix.db.engines import aiosqlite_engine, get_db_url
from phoenix.pointcloud.umap_parameters import (
DEFAULT_MIN_DIST,
DEFAULT_N_NEIGHBORS,
Expand Down Expand Up @@ -70,7 +70,7 @@
| 🚀 Phoenix Server 🚀
| Phoenix UI: http://{host}:{port}
| Log traces: /v1/traces over HTTP
| Storage location: {working_dir}
| Storage: {storage}
"""


Expand Down Expand Up @@ -268,6 +268,7 @@ def _send_spans(spans: Iterable[Span], url: str) -> None:
start_prometheus()

working_dir = get_working_dir().resolve()
sql_url = get_db_url(database=working_dir / "phoenix.db")
engine = aiosqlite_engine(working_dir / "phoenix.db")
app = create_app(
engine=engine,
Expand All @@ -290,7 +291,7 @@ def _send_spans(spans: Iterable[Span], url: str) -> None:
"version": phoenix_version,
"host": host,
"port": port,
"working_dir": working_dir,
"storage": sql_url,
}
print(_WELCOME_MESSAGE.format(**config))

Expand Down

0 comments on commit a2657d4

Please sign in to comment.