Skip to main content

cognee_database/
lib.rs

1//! Relational metadata persistence (SeaORM/SQLite) for ingestion, search history, and deletion.
2
3mod connection;
4mod conversions;
5pub mod entities;
6pub mod migrator;
7pub mod ops;
8pub mod pipelines;
9pub mod sync;
10mod traits;
11mod types;
12pub mod uuid_hex;
13
14// Re-export tutorial seeder for use by cognee-http-server (which can't depend on cognee).
15pub use ops::tutorial_seeder::{
16    TUTORIAL_BASICS_ID, TUTORIAL_PYTHON_DEV_ID, seed_tutorials_if_first_call,
17};
18
19pub use connection::{connect, initialize, sqlite_url_is_in_memory};
20
21/// Generic backend-label helper shared by the concrete public fn below and the
22/// transaction-scoped internals in `ops::graph_storage` (a `DatabaseTransaction`
23/// also implements `ConnectionTrait`). Kept crate-private so the published API
24/// keeps its pre-0.1.4 `&DatabaseConnection` signature.
25pub(crate) fn connection_system_label<C: sea_orm::ConnectionTrait>(db: &C) -> &'static str {
26    use sea_orm::DatabaseBackend;
27    match db.get_database_backend() {
28        DatabaseBackend::Sqlite => "sqlite",
29        DatabaseBackend::Postgres => "postgres",
30        DatabaseBackend::MySql => "mysql",
31    }
32}
33
34/// Map the active SeaORM backend to a `cognee.db.system` string
35/// matching the values used by the vector / graph adapters.
36///
37/// The tag values mirror Python's observability layer
38/// (`cognee/modules/observability/tracing.py`) and the
39/// `cognee.db.system` attribute exposed by every relational op span.
40pub fn database_system_label(db: &DatabaseConnection) -> &'static str {
41    connection_system_label(db)
42}
43pub use ops::checkpoint::{CheckpointStore, SeaOrmCheckpointStore};
44pub use pipelines::sea_orm_impl::SeaOrmPipelineRunRepository;
45pub use pipelines::{
46    NoopPipelineRunRepository, PipelineRunRepository, PipelineRunWithAttributionRow,
47};
48pub use sea_orm::DatabaseConnection;
49pub use sync::{
50    SeaOrmSyncOperationRepository, SyncOperationRepository, SyncOperationRow, SyncOperationStatus,
51};
52pub use traits::{
53    AclDb, CostByModelRow, DatasetConfigDb, DatasetConfiguration, DatasetConfigurationPatch,
54    DeleteDb, IngestDb, Notebook, NotebookDb, NotebookUpdatePatch, SearchHistoryDb,
55    SessionLifecycleDb, SessionListFilters, SessionListPage, SessionRowWithStatus, SessionStats,
56};
57pub use types::{
58    DatabaseError, GraphEdge, GraphMetrics, GraphNode, PipelineRun, PipelineRunStatus,
59    SearchHistoryEntry, SearchHistoryEntryType, TaskRun,
60};
61
62// The `auth`, `permissions`, `UserDb`/`RoleDb`/`TenantDb`,
63// `SeaOrmUserAuthRepository`, `SeaOrmApiKeyRepository`, `ApiKey`, `AuthUser`,
64// `CreateUserPayload`, `UpdateUserPayload`, `ActiveUserWithApiKeyCount` items
65// moved to the closed `cognee-access-control` crate
66//. The `types` module deliberately remains private —
67// closed callers reach `DatabaseError` via the top-level re-export above.