mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 15:37:55 +08:00
core/cli: keep database url :memory:; default url None
Unset/empty url still maps to durable user-data chat.db. Explicit :memory: is not rewritten; CLI warns when not quiet. DatabaseConfig.url default is None; engine treats None as memory.
This commit is contained in:
+11
-2
@@ -82,12 +82,21 @@ def _warn_recoverable_providers(recoverable: Mapping[str, object]) -> None:
|
||||
|
||||
def _database_config(store: ConfigStore, *, quiet: bool = False) -> DatabaseConfig:
|
||||
raw = dict(store.database)
|
||||
# Prefer a durable file DB so sessions survive CLI restarts.
|
||||
if raw.get("url") in {None, "", ":memory:"} and raw.get("implementation", "sqlite") == "sqlite":
|
||||
url = raw.get("url")
|
||||
impl = raw.get("implementation", "sqlite")
|
||||
# Unset/empty → durable user-data chat.db so interactive sessions persist.
|
||||
# Explicit ``:memory:`` is kept as-is (ephemeral; warn so it is not accidental).
|
||||
if impl == "sqlite" and url in {None, ""}:
|
||||
db_path = user_data_path("plyngent", ensure_exists=True) / _DEFAULT_DB_FILENAME
|
||||
raw = {**raw, "implementation": "sqlite", "url": str(db_path)}
|
||||
if not quiet:
|
||||
click.secho(f"using database: {db_path}", fg="bright_black", err=True)
|
||||
elif not quiet and impl == "sqlite" and url == ":memory:":
|
||||
click.secho(
|
||||
"warning: database url is :memory: — sessions are not persisted to disk",
|
||||
fg="yellow",
|
||||
err=True,
|
||||
)
|
||||
return msgspec.convert(raw, DatabaseConfig)
|
||||
|
||||
|
||||
|
||||
@@ -18,10 +18,12 @@ _MINIMAL_CONFIG = """\
|
||||
# plyngent configuration
|
||||
# edit providers below
|
||||
|
||||
# Optional: omit [database] to use ~/.local/share/plyngent/chat.db (Linux).
|
||||
# Optional: omit [database] (or leave url unset) → ~/.local/share/plyngent/chat.db.
|
||||
# url = ":memory:" keeps a true in-memory SQLite (CLI warns; nothing on disk).
|
||||
# [database]
|
||||
# implementation = "sqlite"
|
||||
# url = "/path/to/chat.db"
|
||||
# # url = ":memory:"
|
||||
|
||||
# [agent]
|
||||
# system_prompt = "You are a careful coding assistant."
|
||||
|
||||
@@ -4,10 +4,15 @@ from msgspec import Struct, field
|
||||
|
||||
|
||||
class DatabaseConfig(Struct, omit_defaults=True):
|
||||
"""Database connection configuration."""
|
||||
"""Database connection configuration.
|
||||
|
||||
``url`` is ``None`` when unset. The CLI fills a durable user-data
|
||||
``chat.db`` only for unset/empty url. Explicit ``":memory:"`` is a true
|
||||
in-memory SQLite (no rewrite).
|
||||
"""
|
||||
|
||||
implementation: str = "sqlite"
|
||||
url: str = ":memory:"
|
||||
url: str | None = None
|
||||
username: str | None = None
|
||||
password: str | None = None
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ def build_async_url(config: DatabaseConfig) -> str:
|
||||
raise UnsupportedDatabaseError(msg)
|
||||
|
||||
url = config.url
|
||||
if url in {":memory:", ""}:
|
||||
if url is None or url in {":memory:", ""}:
|
||||
return "sqlite+aiosqlite:///:memory:"
|
||||
if url.startswith("sqlite+aiosqlite://"):
|
||||
return url
|
||||
|
||||
Reference in New Issue
Block a user