//! Use DQL [`Query`]s to [subscribe to], [observe], and [edit] documents.
//!
//! # Example: Write and Read with DQL
//!
//! Let's look at how to execute an immediate query on the data in the `Store`
//! using [`ditto.store().execute(...)`]:
//!
//! ```
//! use dittolive_ditto::prelude::*;
//! use dittolive_ditto::dql::QueryResult;
//! # async fn example(ditto: &Ditto) -> anyhow::Result<()> {
//!
//! // Insert a document into a collection
//! let insert_result: QueryResult = ditto
//!     .store()
//!     .execute_v2((
//!          "INSERT INTO cars DOCUMENTS (:newCar)",
//!          serde_json::json!({
//!              "newCar": {
//!                  "make": "ford",
//!                  "color": "blue"
//!              }
//!          })
//!     ))
//!     .await?;
//!
//! // Select all documents from a collection
//! let select_result: QueryResult = ditto.store().execute("SELECT * FROM cars", None).await?;
//!
//! // Extract documents as `serde_json::Value`s
//! let documents: Vec<serde_json::Value> = select_result
//!     .iter()
//!     .flat_map(|item| item.deserialize_value().ok())
//!     .collect();
//!
//! # Ok(())
//! # }
//! ```
//!
//! # Example: Observe document updates with DQL
//!
//! If instead we want to be notified when documents are changed, we can use
//! [`ditto.store().register_observer(...)`] to receive callbacks for documents
//! matching a given DQL query.
//!
//! ```
//! use dittolive_ditto::{
//!     dql::{QueryResult, QueryResultItem},
//!     prelude::*,
//! };
//! # fn example(ditto: &Ditto) -> anyhow::Result<()> {
//!
//! let _observer = ditto.store().register_observer(
//!     "SELECT * FROM cars",
//!     None, // No query arguments
//!     |query_result: QueryResult| {
//!         let changed_documents = query_result
//!             .iter()
//!             .flat_map(|item: QueryResultItem| {
//!                 item.deserialize_value::<serde_json::Value>().ok()
//!             })
//!             .collect::<Vec<_>>();
//!
//!         for doc in &changed_documents {
//!             println!("Observed change to document: {doc}");
//!         }
//!     },
//! )?;
//! # Ok(())
//! # }
//! ```
//!
//! [subscribe to]: crate::sync::Sync::register_subscription
//! [observe]: crate::store::Store::register_observer
//! [edit]: crate::store::Store::execute
//! [`ditto.store().execute(...)`]: crate::store::Store::execute
//! [`ditto.store().register_observer(...)`]: crate::store::Store::register_observer

/// Query
pub(crate) mod query;
#[allow(deprecated)]
pub use query::{Query, QueryArguments};

pub(crate) mod query_v2;
pub use query_v2::{IntoQuery, QueryV2};

/// Dql Result
pub(crate) mod query_result;
pub use query_result::{QueryResult, QueryResultItem};

/// Differ
pub(crate) mod differ;
pub use differ::{Diff, DiffMove, Differ};

// TODO(v5): Remove re-exports from deprecated location
#[doc(hidden)]
#[deprecated(note = "Use `dittolive_ditto::store::ChangeHandler` instead")]
pub use crate::store::ChangeHandler;
#[doc(hidden)]
#[deprecated(note = "Use `dittolive_ditto::store::ChangeHandlerWithSignalNext` instead")]
pub use crate::store::ChangeHandlerWithSignalNext;
#[doc(hidden)]
#[deprecated(note = "Use `dittolive_ditto::store::SignalNext` instead")]
pub use crate::store::SignalNext;
#[doc(hidden)]
#[deprecated(note = "Use `dittolive_ditto::store::StoreObserver` instead")]
pub use crate::store::StoreObserver;
// NOTE(nimo): Ensure that even though this is deprecated, it's available
/// ```
/// use dittolive_ditto::{dql::SyncSubscription as _, store::dql::SyncSubscription as _};
/// ```
#[doc(hidden)]
#[deprecated(note = "Use `sync::SyncSubscription` instead")]
pub use crate::sync::SyncSubscription;
